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('div#top ul li', {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();
	}
}

function fixColumns() 
{
	if (controller == "index") {
		var h1 = $("#binnenkort").height();
		var h2 = $("#news").height();
		
		if (h1 < h2) {
			h1 = h2;
		} else {
			h2 = h1;
		}
		
		$("#news").height(h1);
		$("#binnenkort").height(h2);
	}
	//************************************************************
	//content and sidebar height hack for making columns equal size
	var sidebarHeight = $('#left').outerHeight(true);
	var contentHeight = $('#right').outerHeight(true);
	if (sidebarHeight > contentHeight) {
		var diffY = $('div.content-spacer').offset().top - $('div#main').offset().top;
		$('div.content-spacer').height(sidebarHeight - diffY);
		$('div.stroke, div.small-stroke').height(sidebarHeight);
	} else if (contentHeight > sidebarHeight) {
		var diffY = $("div.sidebar-spacer").offset().top - $("div#main").offset().top;
		$('div.sidebar-spacer').height(contentHeight - diffY);
		$('div.stroke, div.small-stroke').height(contentHeight);
	} else if (contentHeight == sidebarHeight){
		$('div.stroke, div.small-stroke').height(contentHeight);
	}
	

	//**************************************************************/	
}
$(window).load(function(){
	fixColumns();
});
$(document).ready( function() {	
	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();
		}
	);
	
	$("#largetext").fontscale("body", "up", {cookie:true,unit:"em"});
	$("#smalltext").fontscale("body", "down", {cookie:true,unit:"em"});
	$("#largetext").click(function(event){
		event.preventDefault();
		cufon();
		fixColumns()
	});
	$("#smalltext").click(function(event){
		event.preventDefault();
		cufon();
		fixColumns()
	});
	$("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, div.row").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);				
			}
		}
	);	
});