$(window).load(function(){

	$('a[rel*=facebox]').facebox();
	$("a[rel=externo]").attr('target','_blank');
	$("input[type=submit]").css("cursor","pointer");
	$("input[type=button]").css("cursor","pointer");
	$(".opac").css("opacity","0.5");
	$(".bt-voltar").click(function(){history.back();});
	$(".bt-topo").click(function(){$(document).scrollTo( {top:'0px',left:'0px'}, 200 );});
	$(".lojas-unicas, .destaque-box-3, .destaque-box-2").hover(function(){
		$(this).css("opacity", "0.8");
		$(this).css("cursor", "hand");
	},function(){
		$(this).css("opacity", "1");
	});
	
	$('.paginations a')
		.css( {backgroundPosition: "0 0"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(-161px 0)"}, {duration:500})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:500})
		});
		
	$('.paginations a.paginaSel')
		.css( {backgroundPosition: "-161px 0"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:500})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(-161px 0)"}, {duration:500})
		});
		
	$('.link-leia-mais')
		.css( {backgroundPosition: "0 0"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(-315px 0)"}, {duration:500})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:500})
		});
	$('.lojas-box-noticias dl dd a.link-leia-mais')
		.css( {backgroundPosition: "0 0"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(-380px 0)"}, {duration:500})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:500})
		});
	
	
	/**
	   * Flash principal topo
	   **/
	var logo = $('.topo').attr('id');
	$('.topo').flash({
	    src: 'swf/top.swf',
	    width: 960,
	    height: 187,
		flashvars: { cmd: $('.topo').attr('id') },
		wmode: 'transparent',
		expressInstall: true
	});
	
	/**
	   * Flash do menu de lojas
	   **/
	$('.lojasmenu').flash({
	    src: 'swf/lojasmenu.swf',
	    width: 960,
	    height: 77,
		wmode: 'transparent',
		expressInstall: true
	});
	
	/**
	   * Flash do Logo Hive
	   **/
	$('.logo-hive').flash({
	    src: 'swf/logo-hive.swf',
	    width: 68,
	    height: 53,
		wmode: 'transparent'
	});
	
	/**
	   * Cycle da Home
	   **/
	$(".holder-home").cycle({
	    fx: "scrollHorz", 
	    prev: ".bt-left", 
	    next: ".bt-right",
		speed: 300,
	    timeout: 0 
	});
	
	/**
	   * Cycle das Lojas
	   **/
	$(".holder-lojas").cycle({
	    fx: "scrollHorz", 
	    prev: ".bt-left", 
	    next: ".bt-right",
		speed: 300,
	    timeout: 0 
	});
	
	// Script do google maps
	var textodomapa = $("a.mapa-google").attr("rel");
	var urldomapa = $("a.mapa-google").attr("title");
	
	// Script do google maps
	$(".mapa-google-clica").teste({
		// Background Color
		bgColor: "#000",		
		// Background Opacity
		bgOpacity: 0.8,		
		// Map Width
		mapWidth: 700,		
		// Map Height
		mapHeight: 500,		
		// The text below the map
		mapText: textodomapa,		
		// The map URL that come with the iFrame that you can generate at google.com/maps
		mapUrl: urldomapa
	});	
	
	/**
	   * Mascara
	   **/
	$(".telefone").mask("(99)9999-9999");
	$(".data").mask("99/99/9999");
});

/**
  * Função Validar Formulário
  * @param 
  * @return Boolean
  **/
function validaForm(form) {
    for (var i = 0; i < document.getElementById(form).elements.length; i++) {        
        var nomeObj = document.getElementById(form).elements[i].name;
        var idObj 	= document.getElementById(form).elements[i].id;
		var relObj 	= document.getElementById(form).elements[i].getAttribute('rel');				
		if ((relObj == "email")) {
			expressao = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/i;
			if(!expressao.test(document.getElementById(form).elements[i].value)){
				$.getErro(document.getElementById(form).elements[i].title);
				document.getElementById(form).elements[i].value = "";
				document.getElementById(form).elements[i].style.backgroundColor = "#666";
				document.getElementById(form).elements[i].style.color = "#FFF";
				document.getElementById(form).elements[i].focus();
				return false;
			}
		}else if (relObj == "required") {
			if((document.getElementById(form).elements[i].value == null) || (document.getElementById(form).elements[i].value == "")){
				$.getErro(document.getElementById(form).elements[i].title);
				document.getElementById(form).elements[i].style.backgroundColor = "#666";
				document.getElementById(form).elements[i].style.color = "#FFF";
				document.getElementById(form).elements[i].focus();
				return false;
			}
		}
    }
    return true;
}

/**
  * Função validar contato
  * @param nada
  * @return nada
  **/
function validarContato() {
	if (validaForm("form-contato")) {
		var str = $("#form-contato").serialize();
		$.ajax({
			type: "POST",
			url: "lib/acao-form-contato.php",
			data: str,
			beforeSend: function() {
			},
			success: function(txt) {
				$.getSucesso("Mensagem enviada com sucesso! Obrigado!");
				document.getElementById("form-contato").reset();
			},
			error: function(txt) {
				$.getErro("Erro: " + txt);
			}
		});
	}
}

/**
  * Função limpa espaço
  * @param str String
  * @return nada
  **/
function getTrim(str) {
	return str.replace(/^\s+|\s+$/g, "");
}

/**
  * Função validar Kock Express
  * @param nada
  * @return nada
  **/
function validarKockExpress() {
	if (validaForm("form-kock-express")) {
		var str = $("#form-kock-express").serialize();
		$.ajax({
			type: "POST",
			url: "lib/acao-form-kock-express.php",
			data: str,
			beforeSend: function() {
			},
			success: function(txt) {
				if (getTrim(txt) == "E-mail cadastrado com sucesso!") {
					$.getSucesso(txt);		
					document.getElementById("form-kock-express").reset();
				} else {
					$.getErro(txt);		
				}						
			},
			error: function(txt) {
				$.getErro("Erro: " + txt);
			}
		});
	}
}


/**
  * Função trocar foto
  * @param img Imagem
   * @return nada
  **/
function trocaFoto(img,legenda) {
	$("#div-imagem").attr("src", img);
	$("#span-legenda").html(legenda);
}
