$(document).ready(function() {
	$(document).pngFix();
		var ftime=leggiCookie('primavolta');
	/*volte successive */
	if(ftime=='si'){
		others();
	}
	/* prima volta allora setta un immagine di base */
	else{
		createCookie('primavolta','si','no');
		firstime();
	}
});
/* genera un numero casuale tra lowVal e HighVal*/
function randRange(lowVal,highVal) {
   return Math.floor(Math.random()*(highVal-lowVal+1))+lowVal;
}
	
//setta i cookie in acm di modifica categoria box 1
function createCookie(name,value,expired){
	
	if(expired == 'no'){
	
		today=new Date();
		var expires=10;
		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 firstime(){
	jQuery("#cont-head").attr("style" , "background-Image:url(/contents/instance2/images/tophead3.jpg)"); 
}
function others(){
	imgHeader=new Array(
		"tophead1.jpg",
		"tophead2.jpg",
		"tophead3.jpg",
		"tophead4.jpg"
	);		

	var numrand=randRange(1,imgHeader.length)-1;
	/* se non ho un flash ma ho solo l'immagine*/
		
	jQuery("#cont-head").attr("style" , "background-Image:url(/contents/instance2/images/"+imgHeader[numrand]+")"); 
}
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 "";
}

