﻿if (!window.HomePlataforma)
	HomePlataforma = {};

HomePlataforma.Page = function() 
{
}

HomePlataforma.Page.prototype =
{
	handleLoad: function(control, userContext, rootElement) 
	{
		this.control = control;
		
		this.control.content.findName("Txt_Aba_0").Text = "Descubra sua melhor opção";
		this.control.content.findName("Txt_Aba_1").Text = "Comunicações Unificadas";
		this.control.content.findName("Txt_Aba_2").Text = "Segurança e Gerenciamento";
		this.control.content.findName("Txt_Aba_3").Text = "Virtualização";
		this.control.content.findName("Txt_Aba_4").Text = "Produtos e Tecnologias";
		this.control.content.findName("Txt_Aba_5").Text = "Colaboração";
		this.control.content.findName("Txt_Aba_6").Text = "Microsoft Dynamics";
		this.control.content.findName("Txt_Aba_7").Text = "Implementação de Soluções";

		this.control.content.findName("Img_0").Tag = "melhorOpcao/introducao.aspx";
		this.control.content.findName("Img_1").Tag = "ComUnif";
		this.control.content.findName("Img_2").Tag = "segGerenc/sgCenario.aspx";
		this.control.content.findName("Img_3").Tag = "virtualizacao/vtCenario.aspx";
		this.control.content.findName("Img_4").Tag = "prodTecnologias";
		this.control.content.findName("Img_5").Tag = "colabEvoluc/ceCenario.aspx";
		this.control.content.findName("Img_6").Tag = "msDynamics/mdCenario.aspx";
		this.control.content.findName("Img_7").Tag = "deployment/dlCenario.aspx";

		tweening = false;

		wAba = 50;
		wImg = 496; // 547
		
		nElem = 8;
		
		aba = [];
		img = [];
		defPos = [];
						
				
		for(var i=0;i<nElem;i++){
			aba[i] = this.control.content.findName("Aba_"+i);
			//aba[i].Tag = i;
			img[i] = this.control.content.findName("Img_"+i);
		}
		
	    // Posiciona abas
	    for(var i=0;i<aba.length;i++){
			defPos[i] = aba[i]['Canvas.Left'] = i*wAba + (i+1);	
			
		}
		
		 // Posiciona e esconde elementos
	    for(var i=0;i<img.length;i++){
			img[i]['Canvas.Left'] = (1+i)*wAba + (i+2);
			img[i]['Canvas.ZIndex'] = 0;
			img[i].Opacity = 0;			
		}
		
		// Posição default do esquema

		currentImg = 7;
		img[currentImg].Opacity = 1;
		img[currentImg]['Canvas.ZIndex'] = 1;
		
		
		// Sample event hookup:	
		rootElement.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleMouseDown));

		aba[0].addEventListener("MouseEnter", Silverlight.createDelegate(this, this.posicionaAbas));
		aba[1].addEventListener("MouseEnter", Silverlight.createDelegate(this, this.posicionaAbas));
		aba[2].addEventListener("MouseEnter", Silverlight.createDelegate(this, this.posicionaAbas));
		aba[3].addEventListener("MouseEnter", Silverlight.createDelegate(this, this.posicionaAbas));
		aba[4].addEventListener("MouseEnter", Silverlight.createDelegate(this, this.posicionaAbas));
		aba[5].addEventListener("MouseEnter", Silverlight.createDelegate(this, this.posicionaAbas));
		aba[6].addEventListener("MouseEnter", Silverlight.createDelegate(this, this.posicionaAbas));
		aba[7].addEventListener("MouseEnter", Silverlight.createDelegate(this, this.posicionaAbas));

		aba[0].addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.posicionaAbas));
		aba[1].addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.posicionaAbas));
		aba[2].addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.posicionaAbas));
		aba[3].addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.posicionaAbas));
		aba[4].addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.posicionaAbas));
		aba[5].addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.posicionaAbas));
		aba[6].addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.posicionaAbas));
		aba[7].addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.posicionaAbas));

		img[0].addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.getURL));
		img[1].addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.getURL));
		img[2].addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.getURL));
		img[3].addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.getURL));
		img[4].addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.getURL));
		img[5].addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.getURL));
		img[6].addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.getURL));
		img[7].addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.getURL));

	},
	
	// Sample event handler
	handleMouseDown: function(sender, eventArgs) 
	{
		// The following line of code shows how to find an element by name and call a method on it.
		// this.control.content.findName("Storyboard1").Begin();
	},
	getURL: function(sender, eventArgs) 
	{
		window.location = sender.Tag;
	},

	
	posicionaAbas: function(sender, eventArgs) 
	{
		//if(sender) alert(sender.Tag);
		
		n = sender.Tag;
		var chase;

		if(n != currentImg && !tweening){
			if (chase != undefined) alert(chase);
			if(n < currentImg){
				tweening = true;
				// anda current e maiores p/ frente;
				for(var j=currentImg; j>n; j--)
					//aba[j]['Canvas.Left'] += wImg+1;
					 /*JSTweener.addTween(aba[j], {
					      time: 0.5,
					      transition: 'easeincubic',
						  onComplete: function(){ tweening = false; },
					      'Canvas.Left': aba[j]['Canvas.Left'] + wImg+1
					  });*/
					  chase = setTimeout("JSTweener.addTween(aba["+j+"], {time: 0.5,transition: 'easeincubic',onComplete: function(){ tweening = false; },'Canvas.Left': aba["+j+"]['Canvas.Left'] + "+wImg+"+1});",300);

			 }
			 else if(n > currentImg){
			 	tweening = true;
				// anda current e maiores p/ trás;
				for(var k=n; k>=currentImg; k--)
					if (k == n)
						//aba[k]['Canvas.Left'] -= wImg+1;
						/*JSTweener.addTween(aba[k], {
					      time: 0.5,
					      transition: 'easeincubic',
						  onComplete: function(){ tweening = false; },
					      'Canvas.Left': aba[k]['Canvas.Left'] - (wImg+1)
					  });*/
					  chase = setTimeout("JSTweener.addTween(aba["+k+"], { time: 0.5, transition: 'easeincubic', onComplete: function(){ tweening = false; }, 'Canvas.Left': aba["+k+"]['Canvas.Left'] - ("+wImg+"+1)});",300);

					else
						//aba[k]['Canvas.Left'] = k*wAba + (k+1);
						chase = setTimeout("JSTweener.addTween(aba["+k+"], { time: 0.5, transition: 'easeincubic', onComplete: function(){ tweening = false; }, 'Canvas.Left': "+k*wAba+" + ("+k+"+1)});",300);

						/*JSTweener.addTween(aba[k], {
						    time: 0.5,
						    transition: 'easeincubic',
							onComplete: function(){ tweening = false; },
						    'Canvas.Left': k*wAba + (k+1)
						  });*/

			 }
			 
			// transição das imagens
			JSTweener.addTween(img[currentImg], {
			    time: 0.5,
			    transition: 'easeincubic',
				onComplete: function(){ 
					JSTweener.addTween(img[currentImg], {
					    time: 0.5,
					    transition: 'easeincubic',
					    Opacity: 1
					  });

			    },
			    Opacity: 0
			    
			  });

			img[n]['Canvas.ZIndex'] = 1;
			for(var l=0;l<img.length;l++)
				if (l != n) img[l]['Canvas.ZIndex'] = 0;
			currentImg = n; 		
		}
	}


}