function bind_reglement()
{
	$('a[href$="reglement"]').bind("click",function(){
		$("#reglement_wrapper").fadeIn(350);
		return false;
	});
}

// Multiview
function multiView(id,next,prev)
{
	$(id + " .multiview_window").css({opacity:'0.50'});
	$(id + " .multiview_window:first").addClass("active_multiview").css({opacity:'1.00'});

	$(next).bind('click',
	function()
	{
		if($(id +" .active_multiview").next().length != 0)
		{
			pos_left = $(id + " .active_multiview").find(".pos_left").val();
			
			if(pos_left=="0px")
			{
				$(id + " .active_multiview").animate({opacity:'0.00'}).addClass("active_multiview2").removeClass("active_multiview");
			}
			else
			{
				$(id + " .active_multiview").animate({'left': pos_left,opacity:'0.50'}).addClass("active_multiview2").removeClass("active_multiview");
			}
						
			$(id + " .active_multiview2").next().addClass("active_multiview").animate({'left':'0px',opacity:'1.00'});
			$(id + " .active_multiview2").removeClass("active_multiview2");
		}
		else
		{
			pos_left = $(id + " .active_multiview").find(".pos_left").val();
			
			if(pos_left=="0px")
			{
				$(id + " .active_multiview").animate({opacity:'0.00'}).addClass("active_multiview2").removeClass("active_multiview");
			}
			else
			{
				$(id + " .active_multiview").animate({'left': pos_left,opacity:'0.50'}).addClass("active_multiview2").removeClass("active_multiview");
			}
			
			$(id + " .active_multiview").animate({'left': pos_left,opacity:'0.50'});
			$(id + " .active_multiview").removeClass("active_multiview");
			$(id + " .multiview_window:first").addClass("active_multiview").animate({'left':'0px',opacity:'1.00'});
		}
	});
	
	$(prev).bind('click',
	function()
	{
		if($(id +" .active_multiview").prev().length != 0)
		{
			pos_left = $(id + " .active_multiview").find(".pos_left").val();
			
			if(pos_left=="0px")
			{
				$(id + " .active_multiview").animate({opacity:'0.00'}).addClass("active_multiview2").removeClass("active_multiview");
			}
			else
			{
				$(id + " .active_multiview").animate({'left': pos_left,opacity:'0.50'}).addClass("active_multiview2").removeClass("active_multiview");
			}
			
			$(id + " .active_multiview2").prev().addClass("active_multiview").animate({'left':'0px',opacity:'1.00'});
			$(id + " .active_multiview2").removeClass("active_multiview2");
		}
		else
		{
			pos_left = $(id + " .active_multiview").find(".pos_left").val();
			
			if(pos_left=="0px")
			{
				$(id + " .active_multiview").animate({opacity:'0.00'}).addClass("active_multiview2").removeClass("active_multiview");
			}
			else
			{
				$(id + " .active_multiview").animate({'left': pos_left,opacity:'0.50'}).addClass("active_multiview2").removeClass("active_multiview");
			}
			
			$(id + " .active_multiview").removeClass("active_multiview");
			$(id + " .multiview_window:last").addClass("active_multiview").animate({'left':'0px',opacity:'1.00'});
		}
	});
};

function scrolltodiv(selector) 
{
	selector =  "#" + selector;
	
	var targetOffset = $(selector).offset().top;
	$('html,body').animate({scrollTop: targetOffset}, 300);
}

countimg = 0;

function loadGallery(totalimg)
{
	$(".gallery_img").load(function(){
		countimg++;
	});
	
	if(countimg==totalimg)
	{
		alert("klaar");
	}
	else
	{
		loadGallery(totalimg)
	}
}

function getContent(id)
{	
	if($.trim($("#page_" + id + " .content_wrapper").text()) == "") 
	{ 
		$("#page_" + id + " .content_wrapper").addClass("load");
		
		$.ajax({
		type: "GET",
		async: false,
		url: "inc/build_content.php",
		data: "id=" + id,
		success: 	function (data) 
					{
						$("#page_" + id + " .content_wrapper").removeClass("load");
						$("#page_" + id + " .content_wrapper").html(data);
						
						$(".gallery_img").load(function(){
							$(this).fadeIn('slow');
						});
						
						bind_reglement();
					},
		dataType: "html"
		});
	}
}

$(function() 
{	
	$("#signin").bind('click',function(){scrolltodiv('page_24');})

	// Home achtergrond stretch
	$.fn.fullBg = function(){
    var bgImg = $(this);
    function resizeImg() 
	{
		  var imgwidth = bgImg.width();
		  var imgheight = bgImg.height();
	 
		  var winwidth = $(window).width();
		  var winheight = $(window).height();
	 
		  var widthratio = winwidth / imgwidth;
		  var heightratio = winheight / imgheight;
	 
		  var widthdiff = heightratio * imgwidth;
		  var heightdiff = widthratio * imgheight;
	 
		  if(heightdiff>winheight) {
			bgImg.css({
			  width: winwidth+'px',
			  height: heightdiff+'px'
			});
		  } else {
			bgImg.css({
			  width: widthdiff+'px',
			  height: winheight+'px'
			});		
		  }
		} 
		resizeImg();
		$(window).resize(function() {
		  resizeImg();
		}); 
	 };
	 
	 $('img#background').load( function() {
	jQuery(function($) {
		$('img#background').fullBg();
	});
	});
	 
	function center_elements()
	{
		newmargin = parseFloat($("#menu").width())/2;
		
		newmargin2 = parseFloat($("#menu ul").width())/2;
		newmargin2 = newmargin-newmargin2;
		newmargin2 = newmargin2;
		
		newmargin3 = parseFloat($("#logo").width())/2;
		newmargin3 = newmargin-newmargin3;
		
		newmargin4 = parseFloat($(".content_wrapper").width())/2;
		newmargin4 = newmargin-newmargin4;
		
		newmargin5 = parseFloat($("#reglement").width())/2;
		newmargin5 = newmargin-newmargin5;
		
		newmargin6 = parseFloat($("#reglement").height())/2;
		window_height = parseFloat($(window).height())/2;
		newmargin6 = window_height-newmargin6;

		$('#menu ul').css('marginLeft',newmargin2);
		$('#logo').css('left',newmargin3);
		$(".content_wrapper").css('marginLeft',newmargin4);
		
		$("#reglement").css('left',newmargin5);
		$("#reglement").css('top',newmargin6);
	}
	
	$("#menu ul li:first-child").addClass("active");
	
	$('img.bg_img').load( function() {
	$(function($) {
		$('img.bg_img').fullBg();
	});
	});
	
	$("input,textarea").live('focus',function(){$(this).css('border', "1px solid #CCC");});
	
	$(window).scroll(function() 					  
	{
		if($(window).scrollTop()<450)
		{
			$("#menu").stop().animate({ height: "540px" }, {duration:300, easing: 'easeOutBack'});
			$("#menu ul").stop().animate({ marginTop: "514px" }, {duration:300, easing: 'easeOutBack'});
			$("#signin").stop().animate({ left: "-215px",top: "-55px" }, {duration:300, easing: 'easeOutBack'});
			$("#date").stop().animate({ marginTop: "395px",marginLeft: "355px" }, {duration:300, easing: 'easeOutBack'});
			$("#logo").stop().animate({ top: "235px" }, {duration:300, easing: 'easeOutBack'});
			$("#logo").css("background-image", "url(img/logo.png)"); 
			$("#menu_bg").hide();
			//$("#campaign_button").stop().animate({ opacity: "1.00" }, {duration:300});
		}
		else if($(window).scrollTop()>=450)
		{
			$("#menu").stop().animate({ height: "195px" }, {duration:300, easing: 'easeOutBack'});
			$("#menu ul").stop().animate({ marginTop: "169px" }, {duration:300, easing: 'easeOutBack'});
			$("#signin").stop().animate({ left: "-377px", top: "70px" }, {duration:300, easing: 'easeOutBack'});
			$("#date").stop().animate({ marginTop: "177px",marginLeft: "438px" }, {duration:300, easing: 'easeOutBack'});
			$("#logo").stop().animate({ top: "-90px" }, {duration:300, easing: 'easeOutBack'});
			$("#logo").css("background-image", "url(img/logo2.png)"); 
			$("#menu_bg").show();
			//$("#campaign_button").stop().animate({ opacity: "0.00" }, {duration:100});
		}
		
		if($(window).scrollTop()<850)
		{
			$("#menu_bg").hide();
		}
		else if($(window).scrollTop()>=850)
		{
			$("#menu_bg").show();
		}
	});
	
	$("#signin").hover(function() 
	{
		if($(window).scrollTop()<850)
		{
			$(this).stop().animate({ top: "-65px" }, {duration:300, easing: 'easeOutBack'});
		}
		else
		{
			$(this).stop().animate({ top: "80px" }, {duration:300, easing: 'easeOutBack'});
		}
	}
	,function()
	{
		if($(window).scrollTop()<850)
		{
			$(this).stop().animate({ top: "-55px" }, {duration:300, easing: 'easeOutBack'});
		}
		else
		{
			$(this).stop().animate({ top: "70px" }, {duration:300, easing: 'easeOutBack'});
		}
	});
	
	$("#footer #social .social_button").hover(function() 
	{
		$(this).stop().animate({ top: "-5px" }, {duration:300, easing: 'easeOutBack'});
	}
	,function()
	{
		$(this).stop().animate({ top: "0" }, {duration:300, easing: 'easeOutBack'});
	});
	
	$(window).load(function(){
		center_elements();
	});
	
	$(window).resize(function(){
		center_elements();
	});
	
	$("#reglement_wrapper").bind("click",function(){
		$("#reglement_wrapper").fadeOut(350);
	});
	
	bind_reglement();
});
