$(document).ready(function() {
	
	//preloader di contatti
	$("#states").ajaxStop(function(){
		$("#ajax-loader").hide();
	});
	$("#ajax-loader").hide();
	
	
	//Liste contatti
	  $('#states').hide();
	  $('#continents a').click(function() 
	  {	var nomeCard='';
		var idCard=$(this).attr('idvalue');
		var nomeCard=$(this).attr('title');
		loadContatti(idCard,nomeCard,'states');
		$('#states').fadeOut('fast');
		$('#continents a').removeClass('contact-active');
		$(this).addClass('contact-active');
		
		return false;
	  });
	  
	  $('#bredpaese').click(function() 
	   {
		$(".dett-contact").hide();
		$(".contact").show("slow");
		document.getElementById('breadstato').style.display='none';
		$("#paeselink").hide();
		$("#paesenonlink").show("slow");
	  });
	 
	//fine liste contatti che sparicono quando clicco sopra
	$("#home1select").change(function () {
		var url='';
		
		url = $(this).attr("value");		
        if(url != ''){
			location.href=url;
		}
	     
    });
	$("#home2select").change(function () {
		var url='';
		url = $(this).attr("value");		
        if(url != ''){
			location.href=url;
		}
	     
    });
	
	$("#r1").change(function () {
		var idCat='';
		idCat = $(this).attr("value");		
        if(idCat != ''){
			location.href='/on-line/cardCategory.jsp?instance=11&channel=28&size=10&from=1&idXsl=1&node=1531&idCardLevel='+idCat;
		}
	     
    });
	$("#r2").change(function () {
		var idCat='';
		idCat = $(this).attr("value");		
        if(idCat != ''){
			location.href='/on-line/cardCategory.jsp?instance=11&channel=28&size=10&from=1&idXsl=1&node=1531&idCardLevel='+idCat;
		}
	     
    });
	$("#r3").change(function () {
		var idCat='';
		idCat = $(this).attr("value");		
        if(idCat != ''){
			location.href='/on-line/cardCategory.jsp?instance=11&channel=28&size=10&from=1&idXsl=1&node=1531&idCardLevel='+idCat;
		}
	     
    });
				
});	

/********************************************************************/
/* FLASH 															*/
/********************************************************************/

/* carica flash interno */
function caricaMovie(movie,div,larg,alt){
	var params = {
		allowScriptAccess: 'sameDomain',
		allowFullScreen: 'true',
		scale: 'exactfit',
		wmode: 'transparent'
	};
	swfobject.embedSWF(movie, div, larg, alt, '9.0.0', false,false, params, false);				
}
/* carica video */
function videoPlayer(linkurl,w,h,auto_play,img) {
	var flashvars = {
		videoUrl: linkurl,
		autoPlay: auto_play,
		videoImg: img
	};
	var params = {
		allowScriptAccess: 'sameDomain',
		allowFullScreen: 'true',
		scale: 'exactfit',
		wmode: 'transparent'
	};
	var attributes = {
		id: 'video-player',
		name: 'video-player'
	};
	
	swfobject.embedSWF(movie_dir+'/video-player.swf', 'video-player', w, h, '9.0.0', false, flashvars, params, attributes);
}

function loadContatti(idCardLevel,nomeCard,nomeDiv) {
	
	$("#ajax-loader").show();
	$.ajax({
		type: "GET",
		url:"/on-line/cardCategory.jsp?node=1511&instance=11&channel=28&size=100&ext=template/empty&int=node/schedeContatti&idCardLevel="+idCardLevel,
		 //EVENTUALI PARAMETRI
		dataType: "html",

		success: function(htmlData){
			$("#"+nomeDiv).html(htmlData);
			$("#bredpaese").html('<span id="paesenonlink">&#160;&#160;&gt;&#160;&#160;'+nomeCard+'</span><a id="paeselink" style="display:none" idvalue="'+idCardLevel+'" href="#">&#160;&#160;&gt;&#160;&#160;'+nomeCard+'</a>');
			$("#bredpaese").show("slow");
			$('#states').fadeIn('slow');
		},				
		error: function(){
		alert('Errore nel caricamento del file ');
	   }
	});
}
function loadDettaglioContatto(idCard,nomeCard,nomeDiv) {
	$.ajax({
		type: "GET",
		url:"/on-line/Home/Contatti/scheda"+idCard+".html?ext=template/empty&int=node/dettaglioContatto",
		 //EVENTUALI PARAMETRI
		dataType: "html",
		
		success: function(htmlData){
			$("#"+nomeDiv).html(htmlData);
			$("#paeselink").show("slow");
			$("#paesenonlink").hide();
			$("#breadstato").html('&#160;&#160;&gt;&#160;&#160;'+nomeCard);
			$("#breadstato").show("slow");
			$(".contact").hide();
			$(".dett-contact").show("slow");
			
		},				
		error: function(){
		alert('Errore nel caricamento del file ');
	   }
	});
}

function loadExposeIniziale(){
	 var viewportwidth;
	 var viewportheight;
	 
	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	 
	 if (typeof window.innerWidth != 'undefined')
	 {
		  viewportwidth = window.innerWidth,
		  viewportheight = window.innerHeight
	 }
	 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

	 else if (typeof document.documentElement != 'undefined'
		 && typeof document.documentElement.clientWidth !=
		 'undefined' && document.documentElement.clientWidth != 0)
	 {
		   viewportwidth = document.documentElement.clientWidth,
		   viewportheight = document.documentElement.clientHeight
	 }
	 
	 // older versions of IE
	 
	 else
	 {
		   viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
		   viewportheight = document.getElementsByTagName('body')[0].clientHeight
	 }
	var perWidth= (159.4*100)/(viewportheight-19);
 
	$('#imghome').overlay({ effect: 'apple',top: 162, absolute: true});
	/* $('#imghome').overlay({ effect: 'apple',top: '160px', absolute: 'true'});  */
	$("#imghome").overlay().load(); 
	var demos = $("div.demos");
	$(".uncontrolled-interval p", demos).oneTime(12000, "soon", function() {
		$("#imghome").overlay().close(); 
	});
}

//setta i cookie in acm di modifica categoria box 1
	function createCookie(name,value,expired){
		
		if(expired == 'no'){
		
			today=new Date();
			var expires=0.2;
			expires = expires*100*60*60*24;
			var expires_date= new Date(today.getTime() + (expires));
			document.cookie= name+"="+value+";expires="+expires_date.toGMTString()+";path=/";
		}
		else{
			today=new Date();
			var expires=30;
			expires = expires*100*60*60*24;
			var expires_date= new Date(today.getTime() - (expires));
			document.cookie= name+"="+value+";expires="+expires_date.toGMTString()+";path=/";
		}
	}
	
	function leggiCookie(nomeCookie)
	{
	  if (document.cookie.length > 0)
	  {
		var inizio = document.cookie.indexOf(nomeCookie + "=");
		if (inizio != -1)
		{
		  inizio = inizio + nomeCookie.length + 1;
		  var fine = document.cookie.indexOf(";",inizio);
		  if (fine == -1) fine = document.cookie.length;
		  
		  
		  return unescape(document.cookie.substring(inizio,fine));
		  
		}else{
		   return "";
		}
	  }
	  return "";
	}