/*  
        Data: maio/2011
        Author: Anselmo Cobain (@anselmocobain)
        Autor URI: http://www.webflavia.com.br
*/
/* google analytics script */

var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-16639262-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

/* end analytics */

var teste = {
	
	diminuir:function(direcao)
	{
		if(direcao=='voltar')
		{
			a=7
		}
		else
		{
			a=1;
		}
		teste.loop(a);
		
		img1 = $('#wrapper .img'+a);
		limpar1 = 'img'+a;
		teste.controle(direcao);
		teste.loop(a);
		teste1 = 'img'+a;
		
		img2 = $('#wrapper .img'+a);
		limpar2 = 'img'+a;
		teste.controle(direcao);
		teste.loop(a);
		teste2 = 'img'+a;
		
		img3 = $('#wrapper .img'+a);
		limpar3 = 'img'+a;
		teste.controle(direcao);
		teste.loop(a);
		teste3 = 'img'+a;
		
		img4 = $('#wrapper .img'+a);
		limpar4 = 'img'+a;
		teste.controle(direcao);
		teste.loop(a);
		teste4 = 'img'+a;
		
		img5 = $('#wrapper .img'+a);
		limpar5 = 'img'+a;
		teste.controle(direcao);
		teste.loop(a);
		teste5 = 'img'+a;
		
		img6 = $('#wrapper .img'+a);
		limpar6 = 'img'+a;
		teste.controle(direcao);
		teste.loop(a);
		teste6 = 'img'+a;
		
		img7 = $('#wrapper .img'+a);
		limpar7 = 'img'+a;
		teste.controle(direcao);
		teste.loop(a);
		teste7 = 'img'+a;
		
		img1.removeClass( limpar1);
		img1.addClass( teste1 );
		img1.animate( { top: 40, left: left2, width: 119, height: 196 }, 1000 );
		limpar1 = teste1;
		
		img2.removeClass( limpar2);
		img2.addClass( teste2 );
		img2.animate( { top: 10, left: left3, width: 157, height: 260 }, 1000 );
		limpar2 = teste2;
		
		img3.removeClass( limpar3);
		img3.addClass( teste3 );
		img3.animate( { top: 0, left: left4, width: 179, height: 297 }, 1000 );
		limpar3 = teste3;
		
		img4.removeClass( limpar4);
		img4.addClass( teste4 );
		img4.animate( { top: 10, left: left5, width: 157, height: 260 }, 1000 );
		limpar4 = teste4;
		
		img5.removeClass( limpar5);
		img5.addClass( teste5 );
		img5.animate( { top: 40, left: left6, width: 119, height: 196 }, 1000 );
		limpar5 = teste5;
		
		img6.removeClass( limpar6);
		img6.addClass( teste6 );
		img6.animate( { top: 30, left: left7, width: 92, height: 153 }, 1000 );
		limpar6 = teste6;
		
		img7.removeClass( limpar7);
		img7.addClass( teste7 );
		img7.animate( { top: 30, left: left1, width: 92, height: 153 }, 1000 );
		limpar7 = teste7;
		
	},
	loop:function( value )
	{
		if(a>7)
		{
			a=1;
		}else if(a<1)
		{
			a=7;
		}
	},
	controle:function( direcao )
	{
		
		if(direcao=='voltar')
		{
			a--;
			left7 = '190';
			left6 = '100';
			left5 = '200';
			left4 = '325';
			left3 = '470';
			left2 = '600';
			left1 = '540';
		}
		else
		{
			a++;
			left1 = '190';
			left2 = '100';
			left3 = '200';
			left4 = '325';
			left5 = '470';
			left6 = '600';
			left7 = '540';
		}
		
	},
	init:function()
	{
		
		a=0;
		
	}
}

var nav = {
	wrapper: null,
	home:function()
	{
		carrossel.fadeIn('slow');
		historico.fadeOut('slow');
		missao.fadeOut('slow');
		arede.fadeOut('slow');
		wrapper.removeClass('bg_interna');
	},
	arede:function()
	{
		historico.fadeOut('slow');
		missao.fadeOut('slow');
		carrossel.fadeOut('slow');
		arede.fadeIn('slow');
		wrapper.addClass('bg_interna');
	},
	historico:function()
	{
		carrossel.fadeOut('slow');
		arede.fadeOut('slow');
		missao.fadeOut('slow');
		historico.fadeIn('slow');
		wrapper.addClass('bg_interna');
	},
	missao:function()
	{
		carrossel.fadeOut('slow');
		arede.fadeOut('slow');
		historico.fadeOut('slow');
		missao.fadeIn('slow');
		wrapper.addClass('bg_interna');
	},
	init:function()
	{
		
		wrapper = $('#wrapper');
		carrossel = $('#carrossel');
		arede = $('#arede');
		missao = $('#missao');
		historico = $('#historico');
		
	}
}

function addressChangeHandler( event )
{
	event = event || { path:SWFAddress.getValue() };
	
	if( event.path == "/" )
	{
		nav.home();
	}
	else
	{
		var t = event.path.split( "/" );
		
		if( t[1] == "arede" && t.length >= 2 )
		{
			nav.arede();
		}
		else if( t[1] == "historico" && t.length >= 2 )
		{
			nav.historico();
		}
		else if( t[1] == "missao" && t.length >= 2 )
		{
			nav.missao();
		}
	}
}


$(document).ready(function()
{
	teste.init();
	nav.init();		
	
	teste.init();	
});

//SWFAddress.addEventListener( SWFAddressEvent.CHANGE, addressChangeHandler );
//addressChangeHandler();
