$(document).ready(function() {

	$("#subcontent ul#slideshow").cycle({fx: 'fade', timeout: 6000});
	
	//$("#content").slideDown(300,function(){
	CSBfleXcroll('content');
	var screen = $(window).height();
	var cheight = $("#content").height();
	var avail = screen - 290;
	if (cheight > avail) {
		$("#content").height(avail);
	}
	//});
	
	if ($.browser.msie && $.browser.version <= 6 ) {
		$("#footer").css({position: 'absolute',bottom: '0px'});
	}
	
	if ($("#intro").size()) {
		$("#subcontent").hide();
	}
	
	/*
	$("a:not(.nofx)").click(function(){
		var url = $(this).attr("href");
		var height = $("#content").height();
		
		$("#content").css({height: height+"px"});
		$("#subcontent").animate({opacity: 0},200);
		$("#navcontent").animate({opacity: 0},200);	
		$("#content").animate({height: "0px"},300,"",function(){
			$(this).hide();
			if (url.indexOf("http") != -1) 	{ window.location = url; }
			else 							{ window.location = domain+""+url; }
		});
		return false;
	});
	*/
	
	if ($("#navcontent #submenu ul li.active").size()) 	{ var menuopen = true; var someactive = true; }
	else 												{ var menuopen = false; var someactive = false; }
	
	var menuopen = false;
	$("#navcontent #submenu ul li").hover(
		function(){
			if (menuopen == false) {
				$(this).find("ul").stop(true,true).slideDown('slow');
				menuopen = true;
			}
		}, function(){
			if (!$(this).hasClass('active')) {
				$(this).find("ul").stop(true,true).slideUp('slow',function(){
					menuopen = false;
				});
			}
		}
	);
	
	$("#fotoalbum ul li img").hover(
		function(){ $(this).stop(true,true).animate({opacity: 1}); },
		function(){ $(this).animate({opacity: 0.4}); }
	);
	$("#videoalbum ul li img").hover(
		function(){ $(this).stop(true,true).animate({opacity: 1}); },
		function(){ $(this).animate({opacity: 0.4}); }
	);
	
	/*var disablestaffhover = false;
	$("#staff ul li img.opacity").hover(
		function(){ if (!disablestaffhover) { $(this).stop(true,true).animate({opacity: 1}); } },
		function(){ if (!disablestaffhover) { $(this).animate({opacity: 0.4}); } }
	); 
	*/
	/*
	$("#staff ul li a").click(function(){
		var id = $(this).parent().find("div").find("span").attr("id");
		//$("img.opacity").animate({opacity: 0.4});
		$(this).parent().find(".popup").css({display: 'block', opacity: 0}).animate({opacity: 1},'','',function(){ CSBfleXcroll(id); });
		$('#stafful').find('a.hidertje').hide();
		//disablestaffhover = true;
		return false;
	});
	$("#staff ul li a.close").click(function(){
		$(this).closest(".popup").hide();
		$('#stafful').find('a.hidertje').show();
		//disablestaffhover = false;
		return false;
	});
	*/

	$("#videoalbum a,#video a").click(function(){
		$("#hoverpreventer").css("display","block");
		$("#videoplayerclose").css("display","block");
		$("#videoplayer").css("display","block");
		var href = $(this).attr("href");
		initflow(href);
		return false;
	});
	
	$("#news .text").click(function(){
		document.location.href = $(this).attr("href");
	});
	$("#news .title").click(function(){
		document.location.href = $(this).attr("href");
	});
	
	$("#fotoalbum a").fancybox();
	$("#slideshow a").fancybox();

	if ($("#googlemap").size()) { go_go_google_maps(); }
	$("#startcalculate").click(function(){
		var url = 'http://maps.google.nl/maps?f=d&source=s_d&saddr='+$("#gmaprstreet").val()+',+'+$("#gmaprcity").val()+'&daddr=Caeciliastraat+18,+2312+XB+Leiden+(Leidse+Ballet+%26+Theaterschool)&hl=nl&ie=UTF8&z=8&layer=c&pw=2&geocode=;FXTuGwMdqXJEACECVWXKjQct0A&mra=pe&mrcr=0&sll=51.553425,5.221651&sspn=2.780446,7.13562';
		window.open(url);
		return false;
	});

});

Cufon.replace('h1');
Cufon.replace('#menu',{hover: true});
Cufon.replace('#news .title');
Cufon.replace('#navcontent #submenu',{hover: true});
Cufon.replace('#navcontent #newslist',{hover: true});


function closevideo(){
	$f().stop();
	$("#hoverpreventer").css("display","none");
	$("#videoplayerclose").css("display","none");
	$("#videoplayer").css("display","none");
	return false;
}

function initflow(href) {
	flowplayer("videoplayer","flash/flowplayer-3.1.2.swf", {
		clip: { autoPlay: true, autoBuffering: true,scaling: 'orig' },
		playlist: [href]
		
	});
	return false;
}

function go_go_google_maps() {
	var office = new google.maps.LatLng(52.163304,4.483902);
	var myOptions = {
		zoom: 16,
		center: office,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	var map = new google.maps.Map(document.getElementById("googlemap"), myOptions);
	
	var infowindow = new google.maps.InfoWindow({
		position: office,
		content: '<strong>Leidse Ballet & Theaterschool</strong><br />Caeciliastraat 18<br />2312 XB Leiden'
		});
	infowindow.open(map);
}

