function cufon()
{
	
	Cufon.replace('li.navigation a', {hover: true});
	Cufon.replace('h1');
	Cufon.replace('h2');
	Cufon.replace('h2.detail');
	Cufon.replace('h6');
	Cufon.replace('div.fiche-detail-titel');
	Cufon.replace('div.paragraph a', {hover : true});
	Cufon.replace('.tickets', {hover : true});
	Cufon.replace('li.sidebar');
	Cufon.replace('.subtitle');
	Cufon.replace('div#top span', {hover: true});
	Cufon.replace('span.date-large');
}

var currentIndex = 0;
var numOfImages = 0;
var holderX = 0;
function moveThumbs(direction) {
	var currentImage = $('div.thumbsholder').children()[currentIndex].id;
	currentImage = $("#" + currentImage);
	
	var imgX = currentImage.position().left;
	var xTo = -imgX;
	$('div.thumbsholder').animate({'left': xTo + "px"}, 500);
}

function checkButtons() 
{
	if (currentIndex < 1) {
		$('#thumbswidget a.prev').hide();
	} else {
		$('#thumbswidget a.prev').show();
	}
	if (currentIndex == numOfImages -1) {
		$('#thumbswidget a.next').hide();
	} else {
		$('#thumbswidget a.next').show();
	}
}

$(document).ready( function() {
	//slideshow in fiche
	if ($('div.thumbsholder').attr('class')) {
		holderX = $('div.thumbsholder').offset().left;
		numOfImages = $('div.thumbsholder').children('img.gallerythumb').length;
		checkButtons();
	}
	$('#thumbswidget a.prev').click(function(event) {
		event.preventDefault();
		currentIndex = currentIndex - 1;
		moveThumbs();
		checkButtons();
	});
	
	$('#thumbswidget a.next').click(function(event) {
		event.preventDefault();
		currentIndex = currentIndex + 1;
		moveThumbs();
		checkButtons();
	});
	
	$('div.tickets').hover(
			function(){
				if ($(this).hasClass('click')) {
					$(this).addClass('hover');
					cufon();
				}
			}, function() {
				if ($(this).hasClass('click')) {
					$(this).removeClass('hover');
					cufon();
				}
			}
	);
	
	$('table#relations tr:last').addClass('last');
	$('table#relations-others tr:last').addClass('last');
	$('a.jsbutton').click(function(event){
		event.preventDefault();
	});
	

	$("img.gallerythumb").click(function(){
		curImage = $(this).attr('src').split("thumb_").join("");
		curAlt = $(this).attr('alt');
		$('#mainimage').fadeOut(500, replaceImage);
	});
	
	$('#mainimage').hover(
			function(){
				var altText = $(this).attr('alt');
				if (altText != "") {
					showTooltip(altText);
				}
			},
			function(){
				hideTooltip();
			}
		);
	cufon();
	$("#print").click(function(event){
		event.preventDefault();
		print();
	});
	
	$("#cart").click(function(event){
		event.preventDefault();
		openWin();
	});
	
	$("#videoHolder, #imageHolder").hover(
		function(){
			showTooltip($(this).attr("rel"));
		},function(){
			hideTooltip();
		}
	);
	
	
	$("div#title").click(function(){
		window.location = "/home";
	});
	
	$("div#all-events, div#more-news, div#more-pers").click(function(){
		window.location = $(this).attr("rel");
	});
	
	$("div#news ul li, div#pers ul li").click(function(){
		window.location = this.id;
	});
	
	$("tr.row, div#news ul li, div#pers ul li, li.sidebar").hover(
		function(){
			$(this).addClass("hover");
		},
		function(){
			$(this).removeClass("hover");
		}
	);
	
	$("div.search table tr, div#binnenkort table tr, div#detail-relations table tr").hover(
			function(){
				showTooltipThumb(this);
			}, 
			function(){
				hideTooltipThumb();
			}
	);
	$("div#binnenkort table tr").click(
		function(){
			window.location = this.id;
		}
	);
	
	$("div#blikvanger table tr").click(
		function(){
			window.location = this.id;
		}
	);
	
	$("div.tickets").click(function(){
		if ($(this).hasClass('click')) {
			window.open($(this).attr("rel"));	
		}
	});
	
	$("div.fiches table tr, div#detail-relations table tr").click(
		function(){
			var location = this.id;
			
			if (location.indexOf("http://") == -1) {
				window.location = location;
			} else {
				window.open(location);				
			}
		}
	);
});
