$(document).ready(function(){

	var URL = "/";
	
	//procura
	$("form[id='frm_busca']").submit(function()
		{
			$action = $(this).attr("action");
			$input = $("input[name='s']").val();
			window.location = $action+$input;
			return false;
		}
	)
	//formularios footer
	$("form[id='frm_contatofooter']").submit(function()
		{
			$.post(URL+'core/cadastro.php',$(this).serialize(), function(data){
				alert (data);
				$("input[name='txt_nomefooter']").val("");
				$("input[name='txt_emailfooter']").val("");
			});
			return false;
		}
	)
	//formularios mande projeto
	$("form[id='frm_mandeprojeto']").submit(function()
		{
			$.post(URL+'core/seusprojetos.php',$(this).serialize(), function(data){
				alert (data);
				$("input[name='txt_nome']").val("Nome:");
				$("input[name='txt_email']").val("E-mail:");
				$("input[name='txt_telefone']").val("Telefone:");
				$("input[name='txt_email']").text("Mensagem:");
			});
			return false;
		}
	)
	//focus mande projeto inputs
	$campos = Array();
	$("form[id='frm_mandeprojeto'] ul li input[name != 'submit'], form[id='frm_mandeprojeto'] ul li textarea").each (function ($i)
	{
		$e = $(this);
		$campos.push($e.val());
		
		$e.focusin ( function (){
			if ($(this).val() == $campos[$i]){
				$(this).val("");
			}
		});
		$e.focusout ( function (){
			if ($(this).val() == "")
			{
				$(this).val($campos[$i]);
			}
		});
	});
	//formularios orcamento produtos single
	$("form[id='frm_orcamento']").submit(function()
		{
			$.post(URL+'core/orcamento.php',$(this).serialize(), function(data){
				alert (data);
				$("input[name='txt_nome_orc']").val("");
				$("input[name='txt_email_orc']").val("");
				$("input[name='txt_fone_orc']").val("");
				$("textarea[name='txt_msg_orc']").val("");
			});
			return false;
		}
	)	
	//formulario contato
	$("form[id='frm_contato']").submit(function()
		{
			$.post(URL+'core/contato.php',$(this).serialize(), function(data){
				alert (data);
				$("input[name='txt_nome']").val("");
				$("input[name='txt_email']").val("");
				$("input[name='txt_fone']").val("");
				$("input[name='txt_msg']").text("");
			});
			return false;
		}
	)

	//destaques da home	primeiro
	$destaque = $("div[id='nav_destaque'] ul li:first");
	$destaque.addClass ("active");
    $destaque.children("a").addClass ("active");
	
	if ($destaque.text() != "")
	{
		$dest_arquivo = $destaque.children("a").attr("rel");
		$dest_url = $destaque.children("a").attr("href");
		setDestaque ($dest_arquivo, $dest_url);
	}
	
	tSWF = 0;
	
	//destaques da home clicks
	$("div[id='nav_destaque'] ul li").each( function (i)
		{		
            tSWF = i;
			$e = $(this);
			$e.click ( function ()
				{
					$("div[id='nav_destaque'] ul li, div[id='nav_destaque'] ul li a").removeClass ("active");
					$(this).addClass("active");
                    $(this).children("a").addClass("active");
					$dest_arquivo = $(this).children("a").attr("rel");
					$dest_url = $(this).children("a").attr("href");
					setDestaque ($dest_arquivo, $dest_url);
					return false;
				}
			);
		}
	);    
	//thumbs home [V]
	$('.home_thumb').hover(function(){  
         $('.thumb_conteudo', this).stop().animate({top:'-150'},{queue:false,duration:300});  
    }, function() {  
         $(".thumb_conteudo", this).stop().animate({top:'0px'},{queue:false,duration:300});  
    });
    
    //Efeito thumbs produtos [V]
    $('.produtos_grid_thumb').hover(function(){  
        $('.produtos_thumb_conteudo', this).stop().animate({top:'-130'},{queue:false,duration:300});  
    }, function() {  
        $(".produtos_thumb_conteudo", this).stop().animate({top:'0px'},{queue:false,duration:300});  
    });
    
    //Efeito thumbs projetos[V]
    $('.relacionados_thumb').hover(function(){  
         $('.relacionados_conteudo', this).stop().animate({top:'-130'},{queue:false,duration:300});  
    }, function() {  
         $(".relacionados_conteudo", this).stop().animate({top:'0px'},{queue:false,duration:300});  
    });
    //Efeito thumbs relacionados [V]
	 $('.projetos_grid_thumb').hover(function(){  
         $('.projetos_thumb_conteudo', this).stop().animate({top:'-130'},{queue:false,duration:300});  
     }, function() {  
         $(".projetos_thumb_conteudo", this).stop().animate({top:'0px'},{queue:false,duration:300});  
     });
     	 
	 $('#fotoprincipal_loja').cycle({
		fx:'fade', 
        speed: 1500,
		timeout: 5000,
		fastOnEvent: 1500
	});
	$("div[id='sidebar_interna_thumbloja'] ul li").each(function ($i){
		$e = $(this);		
		$e.click (function (){
			$('#fotoprincipal_loja').cycle($i); 
			return false; 
		});		
	});
	//Efeito slideshow produto[V]
	$('#produto_foto_destaque').cycle({
		fx:'fade', 
        speed: 1500,
		timeout: 5000,
		fastOnEvent: 1500
	});
	$("div[id='produto_area_thumb_produto'] ul li").each(function ($i){
		$e = $(this);		
		$e.click (function (){
			$('#produto_foto_destaque').cycle($i); 
			return false; 
		});		
	});
	//Efeito slideshow projeto[V]
	$('#projetos_foto_destaque').cycle({
		fx:'fade', 
        speed: 1500,
		timeout: 5000,
		fastOnEvent: 1500
	});
	$("div[id='projetos_area_thumb_interna'] ul li").each(function ($i){
		$e = $(this);		
		$e.click (function (){
			$('#projetos_foto_destaque').cycle($i); 
			return false; 
		});		
	});
	// Galeria Podutos/Projetos[V]
	$("a#single_image").fancybox({
		'showCloseButton': true,
		'padding': 5,
		'overlayOpacity':0.7,
		'overlayColor':'#000b1f',
		'transitionIn': 'elastic',
		'transitionOut': 'elastic'
	});
	// Thumbs projetos[V]
	$(".externalControl .widgetdestaque_style").jCarouselLite({
		btnPrev: ".previous",
		btnNext: ".next",
		circular: false,
		mouseWheel: true,
		visible: 6,
		speed:300
	});
	// Thumbs projetos produtos relacionados
	$(".externalControl .widgetrelacionados_style").jCarouselLite({
		btnPrev: ".previousrelacionados",
		btnNext: ".nextrelacionados",
		circular: false,
		mouseWheel: true,
		visible: 1,
		speed:300
	});	
});

var timer;

function setDestaque ($arquivo, $url)
{
    clearTimeout(timer);
    
	$extArray = $arquivo.split(".");
	$ext = $extArray[$extArray.length - 1];
	
	$("div[id='destaque']").html("");
	
	if ($ext == "swf")
	{
		$("div[id='destaque']").flashembed({src:$arquivo, wmode : "transparent"});
	}
	else if ($ext == "jpg" || $ext == "png")
	{
		if ($url != "")
		{
			$("div[id='destaque']").html("<a href='"+$url+"'><img src='"+$arquivo+"' border='0' /></a>");
		}
		else
		{
			$("div[id='destaque']").html("<img src='"+$arquivo+"' border='0' />");
		}
        timer = setTimeout ( "NEXTDESTAQUE()", 7000 );
	}
}
function NEXTDESTAQUE ()
{   
    var destaque = $("div[id='nav_destaque'] ul li.active");
    nSWF = destaque.prevAll('li').length + 1;
    if (nSWF > tSWF){
        nSWF = 0;
    }
    $("div[id='destaque']").html("");
    destaque.removeClass("active");
    destaque.children("a").removeClass("active");
    
    $dest = $("div[id='nav_destaque'] ul li:eq("+nSWF+")")
    $dest.addClass("active");
    $dest.children("a").addClass("active");
        
    $dest_arquivo = $dest.children("a").attr("rel");
    $dest_url = $dest.children("a").attr("href");
    setDestaque ($dest_arquivo, $dest_url);
    //alert (nSWF);
}
//Efeito imagens pb com hover colorido
$(window).bind("load", function() {
//$(document).ready(function() {
	var swap = function() {
	var left = 'src';
	var right = 'original-src';
	var temp = $(this).attr(left);
	$(this)
		.attr(left, $(this).attr(right))
		.attr(right, temp);
	}
	$('img.grayscalehover').grayscale().hover(swap, swap);
});


