$(document).ready(function() {
	jQuery(function($){
		$.supersized({
			//Functionality
			slideshow: 1,
			start_slide: 1,
			slide_interval: 3000,
			transition: 1,
			navigation: 0,
			transition_speed: 1500, 
			performance: 2,
			random: 1,
			pause_hover: 0,
			keyboard_nav: 0,
			image_protect: 1,
			//size & position

			min_width: 0,
			min_height: 0,
			vertical_center: 1,
			horizontal_center: 1,
			fit_always: 0,
			fit_portrait:0,
			fit_landscape: 0,

			//components
			slides:  [ //slideshow images
				//{image : 'img/splash/bg/img1.jpg'},
				{image : 'img/splash/bg/beeld_01.jpg'},
				{image : 'img/splash/bg/beeld_02.jpg'},
				{image : 'img/splash/bg/beeld_03.jpg'}
			]
		});
    });
	
	// Stuff to do as soon as the DOM is ready;
	var languagesbe = "<li><a href='#' rel='nl'>Nederlands</a></li><li><a href='#' rel='fr'>Fran&ccedil;ais</a></li><li><a href='#' rel='en'>English</a></li><li class='last'></li>";
	var languagesfr = "<li><a href='#' rel='fr'>Fran&ccedil;ais</a></li><li><a href='#' rel='en'>English</a></li><li class='last'></li>";
	var languagesnl = "<li><a href='#' rel='nl'>Nederlands</a></li><li><a href='#' rel='en'>English</a></li><li class='last'></li>";
	var languagesit = "<li><a href='#' rel='it'>Italiano</a></li><li><a href='#' rel='en'>English</a></li><li class='last'></li>";
	
	//slide menu up & down
	/*
	$('.filterhead a').click(function(e){
		e.preventDefault();
		
		
		var target = '.'+$(this).attr('rel');
		
		if(target == '.language'){
			if($('#langLink').hasClass('disabled')){
				//do nothing
			}else{
				if($(target).hasClass('open')){
			        $(target).slideUp('fast');
			        $(target).removeClass('open');
				}else{
			        $(target).slideDown('fast');
			        $(target).addClass('open');
				}
			}
		}
		else{
			if($(target).hasClass('open')){
		        $(target).slideUp('fast');
		        $(target).removeClass('open');
			}else{
		        $(target).slideDown('fast');
		        $(target).addClass('open');
			}
		}
	});
	*/
	
	$('.countrySelect').mouseenter(function(e){
		var toFade = '#introPaneTrans'+$(this).attr('rel');
		var filterC = '#filter'+$(this).attr('rel');
		var chooseC = '#choose'+$(this).attr('rel');
		$(toFade).stop(true,true).fadeTo(400, 0.90);
		//$(filterC).stop(true,true).fadeTo(400,1);
		//$(chooseC).stop(true,true).fadeTo(400,1);
		$(chooseC).show();
		$(filterC).show();
		expander();
	});
	$('.countrySelect').mouseleave(function(e){
		var toFade = '#introPaneTrans'+$(this).attr('rel');
		var filterC = '#filter'+$(this).attr('rel');
		var chooseC = '#choose'+$(this).attr('rel');
		$(toFade).stop(true,true).fadeTo(400, 0.5);
		//$(filterC).stop(true,true).fadeTo(400,0);
		//$('.filter').hide().removeClass('open');
		//$(chooseC).stop(true,true).fadeTo(400,0);
		$(chooseC).hide();
		$(filterC).hide();
	});
	
	//set language dropdown + animaties
	$('.country a').click(function(e){
		e.preventDefault();
		var content = $(this).html();
		$('.selCountry').empty();
		$('.selCountry').html(content);
		
		var delayFade = 0;
		
		if($('#languagePane').hasClass('hidden')){
			$('#languagePaneTrans').fadeTo(400, 0.55);
			$('#languagePane').delay(400).fadeIn(400);
			$('#languagePane').removeClass('hidden');
			var delayFade = 1000;
		}
		
		country = ($(this).attr('rel'));
		/*
		if($('.language').hasClass('open')){	
			$('.language').slideUp('fast');
			$('.language').removeClass('open');
		}
		*/
		/*
		$('.language').delay(400).empty();
		
		if(country == 'be'){
			$('.language').append(languagesbe);
			$('.language').attr('rel', 'be');
		}else if(country == 'fr'){
			$('.language').append(languagesfr);
			$('.language').attr('rel', 'fr');
		}else if(country == 'nl'){
			$('.language').append(languagesnl);
			$('.language').attr('rel', 'nl');
		}else{
			$('.language').append(languagesit);
			$('.language').attr('rel', 'it');
		}

		$('.country').slideUp('fast');
		$('.country').removeClass('open');
		$('.language').delay(delayFade).slideDown('fast', function() {
			// Animation complete.
			$('#langLink').removeClass('disabled');
		});
		*/
		$('.language').addClass('open');
	});
	
	
	$('.country a').live('click', function(e){
		e.preventDefault();
		
		var countryLang = $(this).attr('rel');
		//alert(countryLang);
		$.ajax({
			type: "POST",
			url: countryLang+"/splash/setLangCookie/",
			data: ( {
						'countryLang'	: countryLang,
						'postback'		: true
					}),
			success: function(response) {
				if(response!="false"){
					//alert(response);
					window.location = response;
				}
				else{
					return false;
				}
			}
		});
	});
	
	
	//set heights initial
	viewportHeight = $(window).height(); 
	introHeight = $(document).height();
	
	if(introHeight > viewportHeight){
		$('#introPaneTransEN').height(introHeight);
		$('#introPaneTransFR').height(introHeight);
		$('#introPaneTransIT').height(introHeight);
		$('#introPaneTransNL').height(introHeight);
		$('#countryPaneTrans').height(introHeight);
		$('#languagePaneTrans').height(introHeight);
	};
	
	$(window).resize(function() {
		viewportHeight = $(window).height(); 
		introHeight = $(document).height();

		if(introHeight > viewportHeight){
			$('#introPaneTransEN').height(introHeight);
			$('#introPaneTransFR').height(introHeight);
			$('#introPaneTransIT').height(introHeight);
			$('#introPaneTransNL').height(introHeight);
			$('#countryPaneTrans').height(introHeight);
			$('#languagePaneTrans').height(introHeight);
		}else{
			$('#introPaneTransEN').height(viewportHeight);
			$('#introPaneTransFR').height(viewportHeight);
			$('#introPaneTransIT').height(viewportHeight);
			$('#introPaneTransNL').height(viewportHeight);
			$('#countryPaneTrans').height(viewportHeight);
			$('#languagePaneTrans').height(viewportHeight);
		}
	});
	
/*
	//set heights on resize
	$(window).resize(function() {
	  	viewportHeight = $(window).height(); 
		introHeight = $(document).height()-5;
		var innerHeight = introHeight - 250;
		
		
		//set min to start
		var minStart = 600;
		
		if(minStart >= viewportHeight)
		{
			console.log(minStart);
			$('#introPaneTransEN').height(minStart);
			$('#introPaneTransFR').height(minStart);
			$('#introPaneTransIT').height(minStart);
			$('#introPaneTransNL').height(minStart);
			$('#countryPaneTrans').height(minStart);
			$('#languagePaneTrans').height(minStart);
			$('#introPaneEN').height(minStart);
			$('#introPaneFR').height(minStart);
			$('#introPaneIT').height(minStart);
			$('#introPaneNL').height(minStart);
		}
		else
		{
			viewportHeight = viewportHeight-5;
			$('#introPaneTransEN').height(viewportHeight);
			$('#introPaneTransFR').height(viewportHeight);
			$('#introPaneTransIT').height(viewportHeight);
			$('#introPaneTransNL').height(viewportHeight);
			$('#countryPaneTrans').height(viewportHeight);
			$('#languagePaneTrans').height(viewportHeight);
			$('#introPaneEN').height(innerHeight);
			$('#introPaneFR').height(innerHeight);
			$('#introPaneIT').height(innerHeight);
			$('#introPaneNL').height(innerHeight);
		}
	});
*/

	function expander(){
		viewportHeight = $(window).height(); 
		introHeight = $(document).height()-5;
		
		var innerHeight = introHeight - 250;

			$('#introPaneTransEN').height(introHeight);
			$('#introPaneTransFR').height(introHeight);
			$('#introPaneTransIT').height(introHeight);
			$('#introPaneTransNL').height(introHeight);
			$('#introPaneEN').height(innerHeight);
			$('#introPaneFR').height(innerHeight);
			$('#introPaneIT').height(innerHeight);
			$('#introPaneNL').height(innerHeight);
			$('#countryPaneTrans').height(introHeight);
			$('#languagePaneTrans').height(introHeight);
	}
	
	/*
	function shrinker(){
		viewportHeight = $(window).height(); 
		introHeight = $('#introPaneIT').height();
		docHeight = $(document).height();
		
		if(viewportHeight < introHeight){
			introHeight = viewportHeight;
		}
		
		var innerHeight = introHeight - 260;
			console.log('viewport= '+viewportHeight + ' intro:' +introHeight + 'document: '+docHeight);
			$('#introPaneTransEN').height(viewportHeight);
			$('#introPaneTransFR').height(viewportHeight);
			$('#introPaneTransIT').height(viewportHeight);
			$('#introPaneTransNL').height(viewportHeight);
			$('#introPaneEN').height(viewportHeight);
			$('#introPaneFR').height(viewportHeight);
			$('#introPaneIT').height(viewportHeight);
			$('#introPaneNL').height(viewportHeight);

	}
	*/
	
});

