function setCookie(c_name,value,exdays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}
function getCookie(c_name){
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++){
		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		x=x.replace(/^\s+|\s+$/g,"");
		if (x==c_name){
			return unescape(y);
		}
	}
}
function checkCookie(){
	var regionURL=getCookie("IFFregion");
	if (regionURL!=null && regionURL!="") {
		window.location = regionURL;
	}
}
function selectRegion(regionURL,source){
	if(source == "dropdown"){
		_gaq.push(['_trackEvent', 'Dropdown URL clicked on EU splash page', regionURL]);
	}
	else{
		_gaq.push(['_trackEvent', 'Text link URL clicked on EU splash page', regionURL]);
	}
	jConfirm('<b>Would you like us to remember your country selection for future visits?</b><br><br>This will record your choice on your computer for future reference.<br>We will not store any personal information.', 'Remember my selection?', function(r) {
		if(r){
			setCookie("IFFregion",regionURL,365);
		}
		window.location = regionURL;
	});
}

function resizeBG(){
	var windowHeight = $(window).height() - $('#header').height() - $('#footer').height();
	var windowWidth = $(window).width();
	if(windowWidth >= windowHeight){
		var windowRatio = windowWidth/windowHeight;
		$('#background-image').width(windowWidth);
		$('#background-image').height(windowHeight * windowRatio);
	}
	else{
		var windowRatio = windowHeight/windowWidth;
		$('#background-image').height(windowHeight);
		$('#background-image').width(windowWidth * windowRatio);
	}	
}
function initDropDown(){
	$("#drop-down-menu").mouseenter(function(){
		clearTimeout($("#drop-down-menu").data('timeoutId'));
		$("#drop-down-list").fadeIn("fast");
	}).mouseleave(function(){
		var timeoutId = setTimeout(function(){ $("#drop-down-list").fadeOut("fast");}, 100);
		$("#drop-down-menu").data('timeoutId', timeoutId);
	});
	$("#drop-down-list").mouseenter(function(){
		clearTimeout($("#drop-down-menu").data('timeoutId'));
		 $("#drop-down-list").fadeIn("fast");
	}).mouseleave(function(){
		clearTimeout($("#drop-down-menu").data('timeoutId'));
		var timeoutId = setTimeout(function(){ $("#drop-down-list").fadeOut("fast");}, 100);
		$("#drop-down-menu").data('timeoutId', timeoutId);
	});
}
