jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


/* 
 *  Related content boxen
 */


function relatedContent(b,w,e,v)
{
	if (w == "tr")
	{
		var p = "related_cases";	
	}
	else
	{
		var p = "related_publications";	
	}
	
	
	$.ajax({
	  url: 'http://zanders.eu/'+ lang +'/embeds/'+ p +'/'+ w +'/'+ e +'/'+v,
	  success: function(data) {
		$(b).html(data);
	  }
	});
}
function relatedServices(b,e)
{
	$.ajax({
	  url: 'http://zanders.eu/'+ lang +'/embeds/related_services/'+ e,
	  success: function(data) {
		$(b).html(data);
	  }
	});
}

/* 
 *  Toolbar loader
 */
function loadToolbar(b,e)
{
	if (!/msie|MSIE 6/.test(navigator.userAgent)) 
	{
		$.ajax({
		  url: 'http://zanders.eu/'+ lang +'/embeds/toolbar/'+e,
		  success: function(data) {
			$(b).html(data);
		  }
		});
	}		
}




$(function(){
	
	/* 
	 *  Contact
	 */
	
		$('.a_bussum').click(function(event){
			event.preventDefault();
			$('#map_bussum').show();
		}); 
		$('.a_londen').click(function(event){
			event.preventDefault();
			$('#map_londen').show();
		}); 
		$('.a_brussel').click(function(event){
			event.preventDefault();
			$('#map_brussel').show();
		}); 
		$('.a_zurich').click(function(event){
			event.preventDefault();
			$('#map_zurich').show();
		}); 


	/* END */


	/* 
	 *  Search functionality
	 */
	
		$('#cse-search-box .english').click(function(event){

			$("#cx").attr("value","017561242828991908653:mnacwnyxbyg");
			$("#cse-search-box").attr("action","http://zanders.eu/search");
		}); 


		$('#cse-search-box .dutch').click(function(event){
			
			$("#cx").attr("value","017561242828991908653:gesqvv9m-ja");
			$("#cse-search-box").attr("action","http://zanders.eu/search");
		}); 
	/* END */


	/* 
	 *  Dialog functionality
	 */

		// dialog
		$('.dialog').dialog({
			autoOpen: false,
			width: 500,
			height: 400,
			bgiframe: true,
			resizable: false,
			modal: true,
			overlay: {
				backgroundColor: '#000',
				opacity: 0.4
			}
		}); 
		
		$('.showDialog').click(function(event){

			event.preventDefault();
			var params = returnParams(this.href);
			$('#' + params.id).dialog("open");
			
		}); 
		
	/* END */


	/* 
	 *  Webfamily tabmenu
	 */
		// Show first element
		$("#site_family ul div:first").show();
		
		// Mouseover functionality
		$("#site_family li").mouseover(function () { 
			
			// reset elements
			$("#site_family li div").hide();
			$("#site_family li").attr("class","");
			
			$("div", this).show();
			$(this).attr("class","selected");
		});
	
	/* END */
		
		
	/*
	 * Login dialog
	 */
	$('.login').click(function(event){
		
		event.preventDefault();
		$('#login').show(250);
		
	}); 
	$('.login_close').click(function(event){
		
		event.preventDefault();
		$('#login').hide(250);
		
	}); 

	/* END */
		

	/*
	 * Economic view dialog
	 */
	$('.economic_view').click(function(event){
		
		event.preventDefault();
		$('#economic_view').show(250);
		
	}); 
	$('.economic_view_close').click(function(event){
		
		event.preventDefault();
		$('#economic_view').hide(250);
		
	}); 

	/* END */



	/*
	 * Additional publications box
	 */
	
	// Show first element
	$("#ap_box_lists div:first").show();
	
	// Mouseover functionality
	$("#ap_box a").click(function(event) { 

		event.preventDefault();

		var year = $(this).attr("class");
		
		$("#ap_box_lists div").hide();
		$("#ap_box_"+ year).show();
	});
	
	/* END */



	/* 
	 *  Change language and - site bar
	 */
		
		$('#change_language').click(function(event){
			event.preventDefault();
			$('#language').show(250);
		});
		$("#language").mouseleave(function(){
			$('#language').hide(250);
		});
		
		$('#change_site').click(function(event){
			event.preventDefault();
			$('#site_family').show(250);
		});
		$('#site_family').mouseleave(function(){
			$('#site_family').hide(250);
		});
		
	/* END */


	/* 
	 * Class corrections
	 * If page class is general we have to do some corrections
	 */
	
		var style = ($("#pi_a").attr("class") != undefined) ? $("#pi_a").attr("class") : $("#pi_b").attr("class");
		
		if (style == undefined) {
			style = $("#pi_c").attr("class");
		}
		
		if (style == "general") 
		{
			$(".cb_a").css("width", "268px");
			$(".cb_b").css("width", "303px");
			$(".cb_c").css("width", "268px");
		}

	/* END */
	
	/* 
	 * Content width corrections
	 * If page no bg image is defined, widen the content
	 */
	
	if ($("#pi_a").attr("class") != undefined)
	{
		if ($("img", "#pi_a .bg").attr("src") == undefined)
		{
			$("#pi_a .content").css("width","580px");	
		}
	}
	if ($("#pi_b").attr("class") != undefined)
	{
		if ($("img", "#pi_b .bg").attr("src") == undefined)
		{
			$("#pi_b .content").css("width","650px");	
		}
	}
	
	

	/* 
	 *  Contentbox style fix
	 */
		
		var pageColors = new Array();
		pageColors['competences'] = "#cbdce6";
		pageColors['services'] = "#ebf4d9";
		pageColors['clients'] = "#ead3b2";
		pageColors['about_us'] = "#ebf4d9";
		pageColors['general'] = "#f6fbff";
		
		$("#ct_a1 .cb_a:odd").css("margin", "0 0 0 0");
		$("#ct_b1 .cb_b:odd").css("margin", "0 0 20px 0"); 
		$(".cb_c:odd").css("margin", "0 20px");
		$("#ct_d1 .cb_a:odd").css("margin", "0 0 0 0");

		$("#pi_a").css("background", ""+ pageColors[style] +" url("+ $("img", "#pi_a .bg").attr("src") +") top right no-repeat");
		$("#pi_b").css("background", ""+ pageColors[style] +" url("+ $("img", "#pi_b .bg").attr("src") +") top right no-repeat");
		$("#pi_c").css("background", ""+ pageColors[style] +" url("+ $("img", "#pi_c .bg").attr("src") +") top right no-repeat");
		$("#additionals").css("background", pageColors[style]);
		
		$('#menu_a1 li').click(function(event){
			location.href = $("a", this).attr('href');
		});
		
		
	/* END */

	/* 
	 *  Accordion
	 */

		$(".accordion").accordion({
			header: "h2",
			autoHeight: false
		});
	
	/* END */

	/* 
	 *  Set current tab style
	 */

		var x;
		var topics=new Array();
		topics[0] = new Array("competences", "0");
		topics[1] = new Array("services", "-125px");
		topics[2] = new Array("clients", "-250px");	
		topics[3] = new Array("about_us", "-375px");	
		var uri = location.href.split('/');
		
		for (x in topics)
		{
			if (topics[x][0] == uri[4] || topics[x][0] == uri[3]) 
			{
				$("#menu ." + lang + "_" + topics[x][0] + "").css("background", "url(http://zanders.eu/img/menu_" + lang + ".gif) no-repeat " + topics[x][1] + " -60px");
			}
		}

	/* END */





}); //close $(function()


	/*
	 * Carosel
	 */
	
	function carosel() 
	{
	
		// Show first element
		$("#carosel div:first").show();
		showTab("tab_1");
		
		// Mouseover functionality
		$("#carosel li").mouseover(function () { 
			
			showTab(this.id)
			clearInterval(tabInterval);
			
		});
	
		// Interval
		var i=1;
		var tabInterval = setInterval(function()
		{
			i++;
			if (i == 5) i =1;
			
			showTab("tab_"+ i);
			
		}, (10*1000));
	
	}
	/* END */


	function showTab(tab)
	{
		tab = $("#"+ tab); 	

		// reset elements
		$("#carosel li div").hide();
		$("#carosel li").attr("class","");
		$("#tab_1").css("margin","10px 0 0 0"); //ie fix

		$("div", tab).show();
		$(tab).attr("class","selected");
		var img = $("img", tab).attr("src");


		$("#pageintro_y").css("background", "url("+ img +") no-repeat");
	}


	function returnParams(query) 
	{
		var query = query.replace(/^[^\?]+\??/,'');
		var Params = {};
		
		if (!query) { return Params; }// return empty object
		var Pairs = query.split(/[;&]/);
		
		for (var i = 0; i < Pairs.length; i++ ) 
		{
			var KeyVal = Pairs[i].split('=');
			if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
			var key = unescape( KeyVal[0] );
			var val = unescape( KeyVal[1] );
			val = val.replace(/\+/g, ' ');
			Params[key] = val;
		}
		return Params;
	}

	//URL switcher
	function switchURL(value,segment) {
		u = location.href.split('/');
		
		
		if (u[3] == "en" || u[3] == "nl")
		{
			u[3] = value;	
		}
		else {
			u[3] = value + "/" + u[3];
		}
		
		location.href = u.join('/');
	}




