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

var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-12821435-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 content = {
	content:null,
	home: null,
	footer: null,
	perfil:function()
	{
		content.home.fadeOut( 'fast' );
		colecao.fadeOut( 'slow' );
		catalogo.fadeOut( 'slow' );
		lojas.fadeOut( 'slow' );
		videos.fadeOut( 'fast' );
		fotos.fadeOut( 'slow' );
		fotosver.fadeOut( 'slow' );
		contato.fadeOut( 'slow' );
		content.footer.removeClass( 'none' );
		perfil.fadeIn( 'slow' );
		content.wrapper.animate( {width: 960} );
		content.footer.animate( {width: 960} );
	},
	colecao:function()
	{
		content.home.fadeOut( 'fast' );	
		perfil.fadeOut( 'slow' );
		catalogo.fadeOut( 'slow' );
		lojas.fadeOut( 'slow' );
		videos.fadeOut( 'fast' );
		fotos.fadeOut( 'slow' );
		fotosver.fadeOut( 'slow' );
		contato.fadeOut( 'slow' );
		content.footer.removeClass( 'none' );		
		content.wrapper.animate( {width: '100%'} );
		content.footer.animate( {width: '100%'} );
	},
	catalogo:function()
	{
		content.home.fadeOut( 'fast');
		perfil.fadeOut( 'slow' );
		colecao.fadeOut( 'slow' );
		lojas.fadeOut( 'slow' );
		videos.fadeOut( 'fast' );
		fotos.fadeOut( 'slow' );
		fotosver.fadeOut( 'slow' );
		contato.fadeOut( 'slow' );
		content.footer.removeClass( 'none' );
		catalogo.fadeIn( 'slow' );
		content.wrapper.animate( {width: '100%'} );
		content.footer.animate( {width: '100%'} );
		
	},
	lojas:function()
	{
		content.home.fadeOut( 'fast');
		perfil.fadeOut( 'slow' );
		colecao.fadeOut( 'slow' );
		catalogo.fadeOut( 'slow' );
		videos.fadeOut( 'fast' );
		fotos.fadeOut( 'slow' );
		fotosver.fadeOut( 'slow' );
		contato.fadeOut( 'slow' );
		content.footer.removeClass( 'none' );
		lojas.fadeIn( 'slow' );
		content.wrapper.animate( {width: 960} );
		content.footer.animate( {width: 960} );
	},
	videos:function()
	{
		content.home.fadeOut( 'fast');
		perfil.fadeOut( 'slow' );
		colecao.fadeOut( 'slow' );
		catalogo.fadeOut( 'slow' );
		lojas.fadeOut( 'slow' );
		fotos.fadeOut( 'slow' );
		fotosver.fadeOut( 'slow' );
		contato.fadeOut( 'slow' );
		content.footer.removeClass( 'none' );
		videos.fadeIn( 'fast' );
		content.wrapper.animate( {width: 960} );
		content.footer.animate( {width: 960} );
	},
	fotos:function()
	{
		content.home.fadeOut( 'fast');
		perfil.fadeOut( 'slow' );
		colecao.fadeOut( 'slow' );
		catalogo.fadeOut( 'slow' );
		lojas.fadeOut( 'slow' );
		videos.fadeOut( 'fast' );
		contato.fadeOut( 'slow' );
		content.footer.removeClass( 'none' );
		fotos.fadeIn( 'slow' );
		fotosver.fadeOut( 'slow' );
		content.wrapper.animate( {width: 960} );
		content.footer.animate( {width: 960} );
	},
	fotosver:function( data )
	{
		fotosver.html( data );
		nav2.init();
		
		content.home.fadeOut( 'fast');
		perfil.fadeOut( 'slow' );
		colecao.fadeOut( 'slow' );
		catalogo.fadeOut( 'slow' );
		lojas.fadeOut( 'slow' );
		videos.fadeOut( 'fast' );
		contato.fadeOut( 'slow' );
		content.footer.removeClass( 'none' );
		fotos.fadeOut( 'slow' );
		fotosver.fadeIn( 'slow' );
		content.wrapper.animate( {width: 960} );
		content.footer.animate( {width: 960} );
	},
	contato:function()
	{
		content.home.fadeOut( 'fast');
		perfil.fadeOut( 'slow' );
		colecao.fadeOut( 'slow' );
		catalogo.fadeOut( 'slow' );
		lojas.fadeOut( 'slow' );
		videos.fadeOut( 'fast' );
		fotos.fadeOut( 'slow' );
		fotosver.fadeOut( 'slow' );
		content.footer.removeClass( 'none' );
		contato.fadeIn( 'slow' );
		content.wrapper.animate( {width: 960} );
		content.footer.animate( {width: 960} );
	},
	init:function()
	{
		content.home = $('.home');
		content.footer = $('#footer');
		perfil = $('#content .pgperfil');
		colecao = $('#content .pgcolecao');
		catalogo = $('#content .pgcatalogo');
		lojas = $('#content .pglojas');
		videos = $('#content .pgvideos');
		fotos = $('#content .pgfotos');
		fotosver = $('#content .pgfotosver');
		contato = $('#content .pgcontato');
		content.hidden = $('.hidden');
		content.wrapper = $('#wrapper');
	}
}

var nav = {
	
	voltar:function()
	{
		nav.current = nav.loop( nav.current - 1 );
		nav.update();
		i = nav.loop2( i - 1);
		nav.i = $( '.img'+i);
		a = i+1;
		nav.a = $( '.img'+a);
		nav.i.addClass( 'cor' );
		nav.a.removeClass( 'cor' );
		
	},
	
	avancar:function()
	{
		nav.current = nav.loop( nav.current + 1 );
		nav.update();
		i = nav.loop2( i + 1);
		nav.i = $( '.img'+i);
		a = i-1;
		nav.a = $( '.img'+a);
		nav.i.addClass( 'cor' );
		nav.a.removeClass( 'cor' );
	},
	
	loop:function( value )
	{
		return value < 0 ? nav.total + value : ( value >= nav.total ? value % nav.total : value );
	},
	loop2:function( value )
	{
		return value < 0 ? nav.total2 + value : ( value >= nav.total2 ? value % nav.total2 : value );
	},
	update:function()
	{
		var target = $( '#nav .imagens' );
		target.animate( { left: nav.current * -636 }, 300 );	
	},
	init:function()
	{
		i = 0;
		nav.current = 0;
		var fleft = $( '#nav .imagens img' );
		nav.total = fleft.length;
		nav.total2 = 15;
	}
}

var nav2 = {
	voltar:function()
	{
		nav2.current = nav2.loop( nav2.current - 1 );
		nav2.update();
	},
	
	avancar:function()
	{
		nav2.current = nav2.loop( nav2.current + 1 );
		nav2.update();
	},
	
	loop:function( value )
	{
		return value < 0 ? nav2.total + value : ( value >= nav2.total ? value % nav2.total : value );
	},
	update:function()
	{
		var target = $( '#nav2 .pgfotosver' );
		target.animate( { left: nav2.current * -210 }, 300 );	
	},
	init:function()
	{
		i = 0;
		nav2.current = 0;
		var fleft = $( '#nav2 .pgfotosver .box' );
		nav2.total = fleft.length;
		nav2.total;
	}
}

function addressChangeHandler( event )
{
	event = event || { path:SWFAddress.getValue() };
	
	if( event.path == "/" )
	{
		content.home.fadeIn( 'fast');
		perfil.fadeOut( 'slow' );
		colecao.fadeOut( 'slow' );
		catalogo.fadeOut( 'slow' );
		lojas.fadeOut( 'slow' );
		videos.fadeOut( 'fast' );
		fotos.fadeOut( 'slow' );
		fotosver.fadeOut( 'slow' );
		contato.fadeOut( 'slow' );
		content.footer.addClass( 'none' );
	}
	else
	{
		var t = event.path.split( "/" );
		
		if( t[1] == "perfil" && t.length >= 2 )
		{
			content.perfil();
		}
		else if( t[1] == "colecao" && t.length >= 2 )
		{
			content.colecao();
		}
		else if( t[1] == "catalogo" && t.length >= 2 )
		{
			content.catalogo();
		}
		else if( t[1] == "lojas" && t.length >= 2 )
		{
			content.lojas();
		}
		else if( t[1] == "videos" && t.length >= 2 )
		{
			content.videos();
		}
		else if( t[1] == "fotos" && t.length >= 2 )
		{
			if( t[2] == "ver" )
			{
				$.get(HOME+"home/ver/"+t[3],content.fotosver);
			}
			else
				content.fotos();
		}
		else if( t[1] == "contato" && t.length >= 2 )
		{
			content.contato();
		}
	}
}

function trocar(target)
{	
	$("#player").attr("src",$(target).attr("href"));
	$(".player2").html($(target).attr("value"));
	return false;
}

function openVideo( target )
{
	$.fancybox({
			'titleShow'     : true,
			'transitionIn'  : 'false',
			'transitionOut' : 'elastic',
			'href'			: target.href.replace(new RegExp("watch\\?v=", "i"), 'v/') + '&autoplay=1',
			'type'			: 'swf',
			'swf'			: {'wmode':'transparent','allowfullscreen':'true'}
	});
	
	return false;
}
$(document).ready(function()
{
	
	
	$("a.fancy").fancybox({
		'opacity'		: true,
		'overlayShow'	: false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'none'
	});
	
	content.init();
	nav.init();
});

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