$.ajaxSetup({
	type: 'POST'
});

$(document).ready(function()
{
	var windowHeight = $(window).height();
	var footerHeight = $('#footer').height();
	var ContentHeight = $('#content').outerHeight();
	var MiniNavheight = $('#miniNav').outerHeight();

	// Rechtermuis knop uitschakelen (ook image protection)
	$(document)[0].oncontextmenu = function() {return false;}

	if( MiniNavheight == null )
	{
		MiniNavheight = 0;
	}

	// Global var maken voor het onthouden van de gekozen serie
	$.g_sMiniId = $( 'ul#miniSites li:first-child' ).attr('id');

	$('.minisite_imglink').mouseenter(function()
	{
		$(this).next().css('color', '#BE3100');
	}).
	mouseleave(function()
	{
		$(this).next().css('color', '#808080');
	});

	$('.minisite_textlink').mouseenter(function()
	{
		$(this).css('color', '#BE3100');
	}).
	mouseleave(function()
	{
		$(this).css('color', '#808080');
	});

	//Mini site slider
	$('#mini-site-button img').click( function() {
		gotoNextMiniSite();
	});

	//Font bepalen
	Cufon.replace('.ponto');

	//Menu functie weer aanroepen zodat het gebruikt kan blijven worden.
	$('.menu > li').bind('mouseover', jsddm_open);
	//$('.menubutton').bind('click', jsddm_open);
	$('.menu > li').bind('mouseout',  jsddm_timer);

	$('.welcomeNav').fadeIn( 10000 );

	// Het minisite thumb menu goed plaatsen als je een minisite bekijkt
	if( $('.miniTitle').attr('name') != undefined && $('.miniTitle').attr('name') != '' )
	{
		// id van de serie ophalen
		$.g_sMiniId = $('.miniTitle').parent().attr('id');
		animateMini();
	}

	// Venster in het midden plaatsen
	relocate();
	relocateVideo();
});

//Op resize functie relocate uitvoeren
$(window).bind('resize', function() {
	relocate();
	relocateVideo();
});

//Functie voor centreren van content vlak en tonen van scrollbar
function relocate()
{
	var windowHeight = $(window).height();				// Browser viewport hoogte
	var windowWidth = $(window).width();				// Browser viewport hoogte
	var footerHeight = $('#footer').height();			// Hoogte van element #footer
	var ContentHeight = $('#content').outerHeight();	// Hoogte van content container
	var ContentWidth = $('#content').outerWidth();		// Hoogte van content container
	var MiniNavheight = $('#mininav').outerHeight();

	//Wordt css toegevoegd naar aanleiding van berekening
	$('#content').css( "top", ( ( windowHeight - footerHeight ) / 2 ) - ( ContentHeight / 2 ) );
	$('#content').css( "left", ( ( windowWidth ) / 2 ) - ( ContentWidth / 2 ) );


	// Pas de content tonen als het goed geladen is
	if( $('#content').attr( 'class') != '' && $('#content').attr( 'class') != 'home' && $('#content').attr( 'class') != 'mini-sites' && $('#content').attr( 'class') != 'studio' && $('#content').attr( 'class') != 'headquarters' )
	{
		$('#content').css( "display", "block" );
	}
}

// Video minisite centreren
function relocateVideo()
{
	var windowHeight = $(window).height();				// Browser viewport hoogte
	var windowWidth = $(window).width();				// Browser viewport hoogte
	var footerHeight = $('#footer').height();			// Hoogte van element #footer
	var ContentHeight = 450;							// Hoogte van video
	var ContentWidth = 800;								// Breedte van video
	var MiniNavheight = $('#mininav').outerHeight();

	//Wordt css toegevoegd naar aanleiding van berekening
	$('#fullscreenflash').css( "top", ( ( windowHeight - footerHeight - MiniNavheight ) / 2 ) - ( ContentHeight / 2 ) );
	$('#fullscreenflash').css( "left", ( ( windowWidth ) / 2 ) - ( ContentWidth / 2 ) );
}

//Functie voor centreren van content vlak
function resizeContent( p_bHeight, p_bWidth, p_bInnerContent, p_bProducts )
{
	var margin = 20;									// Margin om de content container in pixels
	var windowHeight = $(window).height();				// Browser viewport hoogte
	var windowWidth = $(window).width();				// Browser viewport hoogte
	var footerHeight = $('#footer').height();			// Hoogte van element #footer

	// Hoogte berekenen
	if( p_bHeight )
		$('#content').css( "height", ( windowHeight - footerHeight - ( margin * 2 ) ) );

	// Breedte berekenen
	if( p_bWidth )
		$('#content').css( "width", ( windowWidth - ( margin * 2 ) ) );

	// Breedte producten berekenen
	if( p_bProducts )
	{
		// -20 marge die je verliest, omdat er geen ruimte tussen de foto en info container zit
		// -50 voor de navigatie knoppen
		l_iAantalProducten = Math.floor( ( windowWidth - ( margin * 2 ) + 20 - 50 ) / 300 );
		l_iBreedte = l_iAantalProducten * 300 - 20;
		$('#content').css( "width", ( l_iBreedte + 50 ) );
		$('#screen').css( "width", l_iBreedte );
	}

	// InnerContent hoogte en breedte aanpassen
	if( p_bInnerContent )
		resizeInnerContent();

	relocate();
}

//Functie voor centreren van InnerContent vlak en tonen van scrollbar
function resizeInnerContent()
{
	var header = 160;									// Hoogte van de header in de content
	var contentHeight = $('#content').height();				// Content container hoogte
	var contentWidth = $('#content').width();				// Content container breedte

	$('#innerContent').css( "height", contentHeight - header );
	$('#innerContent').css( "width", contentWidth );
}

//Submenu


var timeout         = 2500;
var closetimer		= 500;
var ddmenuitem      = 0;

function jsddm_open()
{
	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');

	return false;
}

function jsddm_close()
{
	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
}

function jsddm_timer()
{
	closetimer = window.setTimeout(jsddm_close, timeout);
}

function jsddm_canceltimer()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

//document.onclick = jsddm_close;


//Filter menu

var down = false;

function filter_menu()
{
	$('.filterYear').click( function()
	{
		$('#yearMenu').toggle(200, function()
		{
			// Scrollbar toevoegen
			$('.scroll-year').jScrollPane();
		});
	});

	$('.filterCountry').click( function()
	{
		$('#countryMenu').toggle(200);
	});

	$('.filterPress').click( function()
	{
		$('#pressMenu').toggle( 200, function()
		{
			// Scrollbar toevoegen
			$('.scroll-publication').jScrollPane();
		});
	});
}

// Menu sluiten
function closeMenu()
{
	$('#yearMenu').hide(200);
	$('#countryMenu').hide(200);
	$('#pressMenu').hide(200);
}

//Animeer de juiste mini sites naar de juiste positie
function animateMini()
{
	// Top en left bepalen
	var l_iPositionTop = $( 'li#' + $.g_sMiniId ).position().top;
	var l_iPositionLeft = $( 'li#' + $.g_sMiniId ).position().left;
	var l_iTotalWidth = 190 * $('ul#miniSites li').length;


	//Animeer de gekozen mini site naar de juiste plaats
	$( 'ul#miniSites' ).animate(
	{
		top: '-' + l_iPositionTop,
		left: '-' + l_iPositionLeft
	}, 500 );

	return false;
}

//Naar de volgende mini sites gaan
function gotoNextMiniSite()
{
	// id van de volgende serie ophalen
	$.g_sMiniId = $( 'li#' + $.g_sMiniId ).next().attr('id');

	// Controleren of je bij de eerste serie bent, dan weer achteraan beginnen
	if( $.g_sMiniId == undefined ) $.g_sMiniId = $( 'ul#miniSites li:first-child' ).attr('id');

	animateMini();

	return false;
}