﻿if (!window.DestaqueInterna)
	DestaqueInterna = {};

DestaqueInterna.Page = function() 
{
}

DestaqueInterna.Page.prototype =
{
	handleLoad: function(control, userContext, rootElement) 
	{
		this.control = control;
		setaEsq = this.control.content.findName("setaEsq");
		setaDir = this.control.content.findName("setaDir");
		filme = this.control.content.findName("filme");
		imgSalvat = this.control.content.findName("imgSalvat");
		imgComunic = this.control.content.findName("imgComunic");
		imgProd = this.control.content.findName("imgProd");
		//imgCasos = this.control.content.findName("imgCasos");
		imgDeploy = this.control.content.findName("imgDeploy");
		imgVirt = this.control.content.findName("imgVirt");
		imgSeg = this.control.content.findName("imgSeg");
		imgColab = this.control.content.findName("imgColab");
		imgDynam = this.control.content.findName("imgDynam");	
		
		imgSalvat.Tag = "../salvattore";
		imgComunic.Tag = "../comUnif"; 
		imgProd.Tag = "../prodTecnologias"; 
		//imgCasos.Tag = "../casosSucesso"; 
		imgDeploy.Tag = "../deployment/dlCenario.aspx";
		imgVirt.Tag = "../virtualizacao/vtCenario.aspx";
		imgSeg.Tag = "../segGerenc/sgCenario.aspx";
		imgColab.Tag = "../colabEvol/sgCenario.aspx";
		imgDynam.Tag = "../msDynamics/mdCenario.aspx";
		
		final = filme["Canvas.Left"];
		
		tweening = false;
		animDir = 1;
		nItens = 8;
		
		this.control.content.findName("guias").Visibility = "Collapsed";
		
		// Sample event hookup:	
		setaEsq.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.moveEsq));
		setaDir.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.moveDir));
		setaEsq.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.moveEsq));
		setaDir.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.moveDir));
		
		imgSalvat.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.getURL));
		imgComunic.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.getURL));
		imgProd.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.getURL));
		imgDeploy.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.getURL));
		imgVirt.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.getURL));
		imgSeg.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.getURL));
		imgColab.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.getURL));
		imgDynam.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.getURL));

		imgSalvat.addEventListener("MouseEnter", Silverlight.createDelegate(this, this.pauseAnim));
		imgComunic.addEventListener("MouseEnter", Silverlight.createDelegate(this, this.pauseAnim));
		imgProd.addEventListener("MouseEnter", Silverlight.createDelegate(this, this.pauseAnim));
		imgDeploy.addEventListener("MouseEnter", Silverlight.createDelegate(this, this.pauseAnim));
		imgVirt.addEventListener("MouseEnter", Silverlight.createDelegate(this, this.pauseAnim));
		imgSeg.addEventListener("MouseEnter", Silverlight.createDelegate(this, this.pauseAnim));
		imgColab.addEventListener("MouseEnter", Silverlight.createDelegate(this, this.pauseAnim));
		imgDynam.addEventListener("MouseEnter", Silverlight.createDelegate(this, this.pauseAnim));

		imgSalvat.addEventListener("MouseLeave", Silverlight.createDelegate(this, this.resumeAnim));
		imgComunic.addEventListener("MouseLeave", Silverlight.createDelegate(this, this.resumeAnim));
		imgProd.addEventListener("MouseLeave", Silverlight.createDelegate(this, this.resumeAnim));
		imgDeploy.addEventListener("MouseLeave", Silverlight.createDelegate(this, this.resumeAnim));
		imgVirt.addEventListener("MouseLeave", Silverlight.createDelegate(this, this.resumeAnim));
		imgSeg.addEventListener("MouseLeave", Silverlight.createDelegate(this, this.resumeAnim));
		imgColab.addEventListener("MouseLeave", Silverlight.createDelegate(this, this.resumeAnim));
		imgDynam.addEventListener("MouseLeave", Silverlight.createDelegate(this, this.resumeAnim));



		
		anim = setInterval(this.triggerAnim,2000);
		
	},
	
	getURL:function(sender, eventArgs){
		window.location = sender.Tag;
	},
	pauseAnim: function(sender, eventArgs){
		clearInterval(anim);
	},
	resumeAnim: function(sender, eventArgs){
		this.verifDirec();
		anim = setInterval(this.triggerAnim,2000);
	},
	verifDirec: function(sender, eventArgs){
		if(filme["Canvas.Left"] == 0){ animDir = 0; }
		else if(filme["Canvas.Left"] == -(nItens*180 - 180)){ animDir = 1; }
	},

	triggerAnim: function(sender, eventArgs)
	{
		  if (animDir == 1){
		  	  
		  	  setaEsq.Opacity = "1";
		  	  
			  tweening = true;
			  final+=180;
			  
			  if(final >= 0) setaDir.Opacity = "0.3";	
			  	
			  JSTweener.addTween(filme, {
			      time: 0.4,
			      transition: 'easeoutexpo',
				  onComplete: function(){ tweening = false; DestaqueInterna.Page.prototype.verifDirec(); },
			      "Canvas.Left": final
			  });
			  	if(final == 0){ animDir = 0; }
				if(final == -(nItens*180 - 180)){ animDir = 1; }
			}
			else {
			  
			  setaDir.Opacity = "1";
			  
			  tweening = true;	
			  final-=180;
			  
			  if(final <= -(nItens*180 - 180)) setaEsq.Opacity = "0.3";
			  
			  JSTweener.addTween(filme, {
			      time: 0.4,
			      transition: 'easeoutexpo',
				  onComplete: function(){ tweening = false; DestaqueInterna.Page.prototype.verifDirec(); },
			      "Canvas.Left": final
			  });
			  
			    if(final == 0){ animDir = 0; }
				if(final == -(nItens*180 - 180)){ animDir = 1; }

			}
			  
			
		

	},


	moveEsq: function(sender, eventArgs)
	{
		clearInterval(anim);
		anim = setInterval(this.triggerAnim,2000);
		
		if(final > -(nItens*180 - 180) && !tweening){
		  
		  setaDir.Opacity = "1";
		  tweening = true;	
		  final-=180;
		  
		  if(final <= -(nItens*180 - 180)) setaEsq.Opacity = "0.3";
		  
		  JSTweener.addTween(filme, {
		      time: 0.4,
		      transition: 'easeoutexpo',
			  onComplete: function(){ tweening = false; DestaqueInterna.Page.prototype.verifDirec(); },
		      "Canvas.Left": final
		  });
		}

	},
	moveDir: function(sender, eventArgs) 
	{
		clearInterval(anim);
		anim = setInterval(this.triggerAnim,2000);
	
		if(final < 0 && !tweening){
		  
		  setaEsq.Opacity = "1";
		  tweening = true;
		  final+=180;
		  
		  if(final >= 0) setaDir.Opacity = "0.3";	
		  	
		  JSTweener.addTween(filme, {
		      time: 0.4,
		      transition: 'easeoutexpo',
			  onComplete: function(){ tweening = false; DestaqueInterna.Page.prototype.verifDirec(); },
		      "Canvas.Left": final
		  });
		 }
	}
	
}