var tasti;
var contenuto;
var intervalMenu = null; 
var intervalLampadine = null;
var numeroTastoAttuale = 2;
var numeroTastoPrecedente = 0;
/////////////////////////////////////////////////////
function initGioco(sender,args){
	contenuto = sender.findName("tasti");
	var control = sender.getHost();
	var xamlItem = sender.getResponseText("");	
	tasti = control.content.createFromXaml(xamlItem,true);	
	contenuto.children.add(tasti);	
}
function startAnimazioneTasti(sender, args){
	tml_sfondo = tasti.findName("tasti_in");
	tml_sfondo.begin();	
	initTimerMenu();
}
function startAnimazioneAlbero(sender, args){
	tml_albero = tasti.findName("albero_in");
	tml_albero.begin();	
}
function startAnimazioneRegali(sender, args){
	tml_regali = tasti.findName("regali_in");
	tml_regali.begin();	
}
////////////////////////////////////////
//LAMPADINE
////////////////////////////////////////
function initTimerLampadine(sender, args){
	intervalLampadine = setInterval(startAnimazioneLampadine, 7000); 		
}
function startAnimazioneLampadine(sender, args){
	//alert("startAnimazioneLampadine")
	clearInterval(intervalLampadine);
	tml_lampadine = tasti.findName("loop_lampadine");
	tml_lampadine.begin();	
}
function loopAnimazionLampadine(sender, args){
    sender.findName("loop_lampadine").begin();
}
////////////////////////////////////////
//TIMER
////////////////////////////////////////
function initTimerMenu(sender, args){
	intervalMenu = setInterval(cambiaTasto2Menu, 5000); 		
}
function cambiaTasto2Menu() 
{ 
	//alert("cambiaTasto2Menu")
	numeroTastoPrecedente = numeroTastoAttuale;
	numeroTastoAttuale += 1
	if(numeroTastoAttuale > 3){
		numeroTastoAttuale = 2
	}
	//
	//PRECEDENTE
	tastoPrecedente = tasti.findName("tasto_" + numeroTastoPrecedente);	
	var tml_tasto_precedente = tastoPrecedente.findName("tasto_" + numeroTastoPrecedente + "_fine");	
	tml_tasto_precedente.begin();	
	//ATTUALE
	tastoAttuale = tasti.findName("tasto_" + numeroTastoAttuale);	
	var tml_tasto_attuale = tastoAttuale.findName("tasto_" + numeroTastoAttuale + "_inizio");	
	tml_tasto_attuale.begin();	
	//alert("CAMBIO fuori " + tml_tasto_precedente.name + " dentro " + tml_tasto_attuale.name)
	
} 
////////////////////////////////////////
//EVENTI
////////////////////////////////////////
function over_tasto(sender, args) {
	animaTasto(sender, args, "over");
}
function out_tasto(sender, args) {	
	animaTasto(sender, args, "out");
}
function release_tasto(sender, args){
	//area_sensibile_tasto_n
	
	var id=sender.name.slice(21)
	
	if(id==1){
		window.open("http://www.microsoft.com/italy/expo/", '_blank');
 	}else if(id==2){
		window.open("/storelocator.asp", '_self');
	}else if(id==3){
		window.open("/concorso.asp", '_self');
	}else if(id==4){
		window.open("/messenger.asp", '_self');
	}else if(id==5){
		window.open("/lifeCam.asp", '_self');
	}else if(id==6){
		window.open("/office.asp", '_self');
	}else if(id==7){
		window.open("/mobile.asp", '_self');
	}else if(id==8){
		window.open("/auguridinatale.asp", '_self');
	}else if(id==9){
		window.open("/savethechildren.asp", '_self');
	}else if(id==10){
				window.open("/default.asp", '_self');
	}else if(id==11){
		window.open("/office.asp", '_self');
	}else if(id==12){
		window.open("http://www.microsoft.com/italy/windows/products/winfamily/ie/beta/default.mspx", '_blank');
	}else if(id==13){
		window.open("/vista.asp", '_self');
	}else if(id==14){
		window.open("/messenger.asp", '_self');
	}else if(id==15){
		window.open("/mobile.asp", '_self');
	}else if(id==16){
		window.open("/lifeCam.asp", '_self');
	}else if(id==99){
		window.open("/concorso.asp", '_self');
	}	
	
}
function animaTasto(sender, args, tipo) {
		var id=sender.name.slice(21)		
		if(tipo =="over"){		
			var tml_form = sender.findName("tasto_"+ id +"_over");		
			tml_form.begin();
			//AUDIO
			//audioStart(sender, args)
		}else if(tipo =="out"){
			var tml_form = sender.findName("tasto_"+ id + "_out");		
			tml_form.begin();
		}else if(tipo =="release"){	
		}
		
}
function fineAnimazionTasti(sender, args){
    sender.findName("maschera_no_click").visibility="collapsed"
}
function audioStart(sender, eventArgs){
	var id=sender.name.slice(21)
  	var mediaElement=null 
	if(id==1){
	
 	}else if(id==2){
	
	}else if(id==3){
	
	}else if(id==4){
	
	}else if(id==5){
		mediaElement = sender.findName("cellulare");
	}else if(id==6){
		
	}else if(id==7){
		
	}else if(id==8){
		
	}else if(id==9){
		
	}else if(id==10){
		
	}else if(id==11){
		
	}else if(id==12){
		
	}
	if(mediaElement!=null){
		var position = mediaElement.position;
   		position.seconds = 0;
	   	mediaElement.position = position;
	   	mediaElement.Play();
	}
}

//////////////////////////////
//LOOP TASTI
//////////////////////////////
