/* Predefined variables */
$(document).ready(function() {
	AdjustCalenderSize();
	ActivateAjaxCall();
	ActivateAjaxCallPodium();
	ActivateAjaxCallAgenda();
	ChangeName();
	bindRichInteraction();
 DraggableHomepage();

	$("a[rel=PrettyPhoto]").prettyPhoto({animationSpeed:'slow',theme:'dark_square'});

 $("a[rel=popupAT]").fancybox({
 		'width'				      : 800,
 		'height'			      : 600,
 		'titleShow'		    : false,
   'autoScale'      : true,
   'transitionIn'   : 'none',
 		'transitionOut'  : 'none',
 		'type'				       : 'iframe',
 		'scrolling'      : 'yes',
 		'showNavArrows'  : false,
 		'centerOnScroll' : true
	});

	$("div.open").click(function() { 
		$(this).parent().parent().parent().find("#credits").animate({left:'0'});
		$(this).parent().parent().parent().find("#credits").css({'z-index' : '99999'});
		$(this).fadeOut();
		$(this).parent().find(".close").fadeIn();
	});

	$("div.close").click(function() { 
		$(this).parent().parent().parent().find("#credits").animate({left:'-132'});
		$(this).parent().parent().parent().find("#credits").css({'z-index' : '1'});
		$(this).parent().find(".open").fadeIn();
		$(this).fadeOut();
	});

	$("#play").click(function(){
		api.playToggle();
		$(this).toggleClass("active")
	});

		$("ul#podium_home").mouseenter(function() { 
					$(this).parent().addClass("current2");
		});

		$("ul#podium_home").mouseleave(function() { 
					$(this).parent().removeClass("current2");
		});
		$("ul#film_home").mouseenter(function() { 
					$(this).parent().addClass("current2");
		});

		$("ul#film_home").mouseleave(function() { 
					$(this).parent().removeClass("current2");
		});
		$("ul#tweetert").mouseenter(function() { 
					$(this).parent().addClass("current2");
		});

		$("ul#tweetert").mouseleave(function() { 
					$(this).parent().removeClass("current2");
		});


  var index = 999999;
		$("#tweetert").click(function() { //When trigger is clicked...
					$(this).parent().css("z-index", index++);
		});

		$("ul#podium_home").click(function() { //When trigger is clicked...
		//Following events are applied to the subnav itself (moving subnav up and down)
					var items = $(this);
					var currentItem = items.find(".current");
					var nextItem = currentItem.next();
					if (!nextItem.length) nextItem = items.find(".film_1");
					currentItem.removeClass("current");
					nextItem.addClass("current");
					$(this).parent().css("z-index", index++);
		});

		$("ul#film_home").click(function() { //When trigger is clicked...
		//Following events are applied to the subnav itself (moving subnav up and down)
					var items = $(this);
					var currentItem = items.find(".current");
					var nextItem = currentItem.next();
					if (!nextItem.length) nextItem = items.find(".film_1");
					currentItem.removeClass("current");
					nextItem.addClass("current");
					$(this).parent().css("z-index", index++);
		});

});


function DraggableHomepage(){
 	var draggableCount = 0;
		index: 103;
 	$(".draggable").each(function(){

   	var windowWidth = $(window).width();
   	var windowHeight = $(window).height();
   	
   	var horizontal = Math.round(((windowWidth * .9) - 320) / 3);
   	var vertical = Math.round(((windowHeight * .9) - 310) / 3);
 			horizontal = [0, horizontal * 2, horizontal];
 			vertical = [0, vertical, vertical * 2];
 			var leftOffset = windowWidth * .05 - (Math.random() * (windowWidth * .1));
 			var topOffset = windowHeight * .025 - (Math.random() * (windowHeight * .05));
 			var left = (windowWidth * .1) + horizontal[draggableCount] + leftOffset;
 			var top = 100 + vertical[draggableCount] + topOffset;
    left = Math.floor(left);
    top = Math.floor(top);
 			$(this).css("left", left).css("top", top);
 			draggableCount++;
 	});	

}

function AdjustCalenderSize(){
	$("a[rel^='blokvergroting']").each(function(){
			$(this).bind({
				click: 	    function(){ beweegblokrechts($(this).attr('id'),this.href);return false },
				mouseenter: function(){ beweegblokrechts($(this).attr('id'),'');$(this).addClass("active");return false },
				mouseleave: function(){ beweegblokrechtslinks($(this).attr('id'),'');$(this).removeClass("active");return false }
			});
	});	
}
function ActivateAjaxCallPodium(){
	$("a[rel^='bloknormalpodium']").each(function(){
			$(this).bind({
				click: 	    function(){ laadcontent(this.href);return false }
			});
	});	
}

function ActivateAjaxCall(){
	$("a[rel^='bloknormal']").each(function(){
			$(this).bind({
				click: 	    function(){ laadcontent(this.href);return false },
				mouseenter: function(){ $(this).addClass("active");return false },
				mouseleave: function(){ $(this).removeClass("active");return false }				
			});
	});	
}


function ActivateAjaxCallAgenda(){
	$("a[rel^='blokbig']").each(function(){
			$(this).bind({
				click: 	    function(){ laadcontentagenda(this.href);return false }
			});
	});	
}


function beweegblokrechts(id,value){
  $('#'+id).animate({
    // voor pc - 
	width: '188',
	// voor ipad liggend - width: '205',
	// voor ipad staan - width: '149',
	zIndex: '60'
  }, 0, function() {


  	$('#'+id).addClass("active");
  	if (value != '') {
  		laadcontent(value);
  	}
  });
}
function beweegblokrechtslinks(id){
  $('#'+id).animate({
    width: '70',
	   zIndex: '50'
  }, 0, function() {
  //nothing
  });
}

function laadcontentagenda(value){
  $('#agendapopup').empty();
  $('#fullscreenmask').show().animate({
	   zIndex: '9998'
  });
  var positie = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    positie = window.pageYOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    positie = document.body.scrollTop;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    positie = document.documentElement.scrollTop;
  }

  $('#agendapopup').show().animate({
    height: '600',
	   zIndex: '9999',
    top: positie
  }, 100, function() {
		   $('#agendapopup').load(value+'ajaxcall/');
  });
}

function laadcontent(value){
  var positie = document.documentElement.scrollTop;
  $('#kalenderpopup').show().animate({
    height: '90',
	   zIndex: '9999',
    top: positie
  }, 100, function() {
		  $('#kalenderpopup').load(value+'ajaxcall/');
  });
}

function jsAlert(title,content)
{
	var boxHeight = 300;
	var box = '';
	    box += '<strong>'+title+'</strong><br/><br/>'
	    box += '<p>'+content+'</p>'
			  $.fn.prettyPhoto({social_tools:false,theme:'facebook'});
			  $.prettyPhoto.open('/images/logo.png', '','<h3 class="center">'+title+'</h3><br/><br/><p class="black font11 center">'+content+'</p><br/>');
}

function ChangeName(value){
	$(".draggable_podium_data li").click(function () {movetime(this);});

	$(".draggable_film_data li").click(function () {movetime(this);});

	$(".fixed_podium_data li").click(function () {movetime(this);});

	$(".fixed_film_data li").click(function () {movetime(this);});

	$(".fixed_podium_xl_data li").click(function () {movetime(this);});

	$(".fixed_film_xl_data li").click(function () {movetime(this);});
}

function movetime(triggert){
 	 $(triggert).find("span.time_container").animate({"left": "-54px"}, "fast", function() {
     $(triggert).find("span.time_container").animate({"left": "0px"}, "slow");
   });
}

function bindRichInteraction(){

		/* Clear & Restore input */
	$('input[type=text]').bind({
		focus: function(){ if ($(this).val() == $(this)[0].defaultValue) $(this).val(''); },
		blur:  function(){ if ($(this).val() == "") $(this).val($(this)[0].defaultValue); }
	});
	
	/* In uitschakelen formulier elementen */
	$('.toggleFormParts').each(function(){ toggleFormPart($(this)) } );
	
	$('.toggleFormParts').bind({ click: function(){ toggleFormPart($(this)) } });
	
	function toggleFormPart(e){
		var targetE = '#part'+ e.attr('rel') +'Adres';
		var targetSpry = e.attr('rel');
		var eVisible = e.is(':checked');
		if (eVisible){
			$(targetE).removeClass("jsHide");
			// Spryregels toevoegen op basis van variabele targetSpry
		}else{
			$(targetE).addClass("jsHide");
			// Spryregels verwijderen op basis van variabele targetSpry
		}
	}
}


