/*  
        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 principal = {
	principal: null,
	home: null,
	carrosel: null,
	home:function()
	{
		carrossel.animate( {left: 0}, 900 );
		dicasver.fadeOut('slow');
		fotosver.fadeOut('slow');
		container.removeClass('none');
	},
	casaprado:function()
	{
		principal.scroll();
		carrossel.animate( {left: -989}, 900 );
		dicasver.fadeOut('slow');
		fotosver.fadeOut('slow');
		container.removeClass('none');
	},
	cpcard:function()
	{
		carrossel.animate( {left: -1979}, 900 );
		dicasver.fadeOut('slow');
		fotosver.fadeOut('slow');
		container.removeClass('none');
	},
	nossaequipe:function()
	{
		carrossel.animate( {left: -2968}, 900 );
		dicasver.fadeOut('slow');
		fotosver.fadeOut('slow');
		container.removeClass('none');
	},
	vendavip:function()
	{
		carrossel.animate( {left: -3960}, 900 );
		dicasver.fadeOut('slow');
		fotosver.fadeOut('slow');
		container.removeClass('none');
	},
	colecao:function()
	{
		carrossel.animate( {left: -4950}, 900 );
		dicasver.fadeOut('slow');
		fotosver.fadeOut('slow');
		container.removeClass('none');
	},
	dicas:function()
	{
		carrossel.animate( {left: -5940}, 900 );
		dicasver.fadeOut('slow');
		fotosver.fadeOut('slow');
		container.removeClass('none');
	},
	scroll:function()
	{
		$("#mcs_container .contenta").load("new.html", function(){
			$("#mcs4_container").mCustomScrollbar("vertical",200,"easeOutCirc",1.25,"fixed","yes","no",0);
			$("#mcs_container").mCustomScrollbar("vertical",200,"easeOutCirc",1.25,"fixed","yes","no",0);
		});
	},
	dicasver:function( data )
	{
	  
		dicasver.html( data );
	  
		principal.scroll();
		carrossel.animate( {left: 0}, 100 );
		dicasver.fadeIn('slow');
		fotosver.fadeOut('slow');
		container.addClass('none');
		
		
		
		
	},
	fotos:function()
	{
		carrossel.animate( {left: -6930}, 900 );
		dicasver.fadeOut('slow');
		fotosver.fadeOut('slow');
		container.removeClass('none');
	},
	fotosver:function( data )
	{
		fotosver.html( data );
		
		carrossel.animate( {left: 0}, 100 );
		dicasver.fadeOut('slow');
		fotosver.fadeIn('slow');
		container.addClass('none');
	},
	lojas:function()
	{
		carrossel.animate( {left: -7920}, 900 );
		dicasver.fadeOut('slow');
		fotosver.fadeOut('slow');
		container.removeClass('none');
	},
	contato:function()
	{
		carrossel.animate( {left: -8930}, 900 );
		dicasver.fadeOut('slow');
		fotosver.fadeOut('slow');
		container.removeClass('none');
	},
	init:function()
	{
		body = $( 'body' );
		carrossel = $('#principal .carrossel');
		dicasver = $('#principal .dicasver');
		fotosver = $('#principal .fotosver');
		container = $('.container');	
	}
}

var nav = {
	
	controle:function( pgnav, direcao, total )
	{
		switch(pgnav)
		{
			case 'colecao':
				target = $( '.hidden .fila' );
				tamanho = -222;
				nav.total = 4;
			break;
			case 'dicas':
				target = $( '#dicas .boxgrande .fila' );
				tamanho = -230;
				nav.total = total-3;
			break;
			case 'fotos':
				target = $( '#fotos .boxgrande .fila' );
				tamanho = -259;
				nav.total = total-2;
			break;
			default:
				target = $( '.fotosver .boxgrande .fila' );
				tamanho = -222;
				nav.total = total-3;
			break;
			
		}
		if(direcao=='voltar')
		{
			nav.voltar();
		}else
		{
			nav.avancar();
		}
	},
	voltar:function()
	{
		nav.current = nav.loop( nav.current - 1 );
		nav.update();
	},
	
	avancar:function()
	{
		nav.current = nav.loop( nav.current + 1 );
		nav.update();
	},
	
	loop:function( value )
	{
		
		return value < 0 ? nav.total + value : ( value >= nav.total ? value % nav.total : value );
	},
	update:function()
	{		
		target.animate( { left: nav.current * tamanho }, 300 );	
	},
	init:function()
	{
		nav.current = 0;
	}
}

var bg = {
	
	body1:function()
	{
		body.addClass('body1');
		body.removeClass('body2');
		body.removeClass('body3');
		body.removeClass('body4');
	},
	body2:function()
	{
		body.addClass('body2');
		body.removeClass('body1');
		body.removeClass('body3');
		body.removeClass('body4');
	},
	body3:function()
	{
		body.addClass('body3');
		body.removeClass('body2');
		body.removeClass('body1');
		body.removeClass('body4');
	},
	body4:function()
	{
		body.addClass('body4');
		body.removeClass('body2');
		body.removeClass('body3');
		body.removeClass('body1');
	},
	
	init:function()
	{
		var bg = parseInt(Math.random()*4);
		
		body = $( 'body' );
		switch(bg)
		{
			case 0:
				body.addClass('body1');
				body.removeClass('body2');
				body.removeClass('body3');
				body.removeClass('body4');
				break;
			case 1:
				body.addClass('body2');
				body.removeClass('body1');
				body.removeClass('body3');
				body.removeClass('body4');
				break;
			case 2:
				body.addClass('body3');
				body.removeClass('body2');
				body.removeClass('body1');
				body.removeClass('body4');
				break;
			default:
				body.addClass('body4');
				body.removeClass('body2');
				body.removeClass('body3');
				body.removeClass('body1');
		}
	}
	
}


function addressChangeHandler( event )
{
	event = event || { path:SWFAddress.getValue() };
	
	if( event.path == "/" )
	{
		principal.home();
		bg.body1();
	}
	else
	{
		var t = event.path.split( "/" );
		
		if( t[1] == "casaprado" && t.length >= 2 )
		{
			principal.casaprado();
			bg.body2();
		}
		else if( t[1] == "cpcard" && t.length >= 2 )
		{
			principal.cpcard();
			bg.body3();
		}
		else if( t[1] == "nossaequipe" && t.length >= 2 )
		{
			principal.nossaequipe();
			bg.body3();
		}
		else if( t[1] == "vendavip" && t.length >= 2 )
		{
			principal.vendavip();
			bg.body2();
		}
		else if( t[1] == "colecao" && t.length >= 2 )
		{
			principal.colecao();
			bg.body1();
		}
		else if( t[1] == "dicas" && t.length >= 2 )
		{
			if( t[2] == "ver" )
			{
				$.get(HOME+"Home/ver_dicas/"+t[3],principal.dicasver);
				bg.body3();
				
				
			}else
			{
				principal.dicas();
				bg.body3();
			}
		}
		else if( t[1] == "fotos" && t.length >= 2 )
		{
			if( t[2] == "ver" )
			{
				$.get(HOME+"Home/ver_fotos/"+t[3],principal.fotosver);
				bg.body3();
			}else
			{
			principal.fotos();
			bg.body3();
			}
		}
		else if( t[1] == "lojas" && t.length >= 2 )
		{
			principal.lojas();
			bg.body4();
		}
		else if( t[1] == "contato" && t.length >= 2 )
		{
			principal.contato();
			bg.body4();
		}
	}
}

function trocar(a)
{
	logowf = $('.logowf');
	
	if(a==0)
	{
		logowf.stop().animate( {right: 0}, 600 );
	}
	else{
		logowf.stop().animate( {right: -107}, 600 );
	}
}

$(document).ready(function()
{
	
	$('a.fancy').fancybox({
		'opacity'		: true,
		'overlayShow'	: false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'none'
	});
	
	principal.init();
	nav.init();
	
});

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