var slide =
{
	total:null,
	current:null,
	container:null,
	
	back:function()
	{
		slide.current = slide.loop( slide.current - 1 );
		slide.update();
	},
	
	next:function()
	{
		slide.current = slide.loop( slide.current + 1 );
		slide.update();
	},
	
	loop:function( value )
	{
		return value < 0 ? slide.total + value : ( value >= slide.total ? value % slide.total : value );
		
	},
	
	update:function()
	{
		slide.container.animate( { left:slide.current * -914  }, 800 );
	},
	
	init:function()
	{
		slide.current = 0;
		slide.container = $("aside .content .showcase .conteiner .list");
		slide.total = slide.container.find( 'li' ).length;
		
		slide.container.css( { width:950* slide.total } );

	}
}


$(document).ready(function() {
	
	$('.form-search').submit(function()
	{
		var pergunta = $("#.form-search #search").val();
		
		if( $("#.form-search #search").val() != 'busca pelo site' || $("#.form-search #search").val() != ''){
			var contar = pergunta.length;
			for(i=0; i< contar; i++)
			{
				if(pergunta[i] == " " ) pergunta = pergunta.replace(/ /i , '-');
			}
			
			document.location.href=HOME+'busca/'+pergunta;
			
		}else
		{
			alert('por favor, digite alguma coisa no campo de busca.')
		}
		
		return false;
	});
    
	
	
	$('#navMenu > li').click(function(){
			
			$heading = $(this);			
			$expandedSiblings = $heading.siblings().find('.sub-menu:visible');
			if ($expandedSiblings.size() > 0) {
				$expandedSiblings.slideUp(500, function(){
				$heading.find('.sub-menu').slideDown();
				});
			} else {
				$heading.find('.sub-menu').slideDown();
			}
		
	});
	
	
	slide.init();
		
	$("a.fancy").fancybox({
		'opacity'		: true,
		'overlayShow'	: false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'none'
	});	


	$('#estado').change(function() {
		
			
		var estadoId = $("#estado option:selected").val();
		
		$("#cidade").html('<option value="0">Carregando...</option>');
		
		 $.post( 'http://servidor/aco/'+'cidades/'+estadoId ,
			{estadoNome:$(this).val()},
			function(valor){
			   $("#cidade").html(valor);
			})		
		return false;
	});

});


