
//Funções que inicializam com o Site
$(document).ready(function(){
	
	
	//MENU EM JS
	$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
	
	$(".submenu").mouseover(function() { //When trigger is clicked...
		
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){	
			$(this).parent().find("ul.subnav").slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() { 
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
	
	
	
	
	//marca d'agua;
	//watermark.init();
	$('.texto p:first').css('margin-top','54px');
});

function startLight(linkFake,id){
	$('#imagem').html(linkFake);
	$('a[@rel*=lightbox]').lightBox();
	$('#'+id).click();
}
function showFoto(src,id){	
	//criando um link falso, para o lightBox captar as informações
	var i = 0;
	var linkFake = "";
	for(el in src){
		linkFake += '<a href="'+src[el]+'" id="'+el+'" rel="lightbox"></a>';		
	}
	//chamando a função do lightbox responsável pelo início das ações
	startLight(linkFake,id);
	//anulando o link
	linkFake = null;
}

/**
 * var valEmail
 * Expressão regular de validação de e-mail
 */
var valEmail = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;

/**
 * Função de Validação do Formulário de Cadastro Fale conosco
 *
 * @return boolean
 */
function validaFaleConosco(){

	msg = "";
	
	if($('#nome').val() == "" || $('#nome').val() == "Seu Nome"){
		msg += "<span>Nome não preenchido.</span><br />";
    }
	
	if($('#email').val() == "" || $('#email').val() == "Email de Contato"){
		msg += "<span>Email não preenchido.</span><br />";
    }else if (!checkMail($('#email').val())) {
		msg += "<span>E-mail inválido.</span><br />";	
	}
	
	if($('#fone').val() == "" || $('#fone').val() == "Telefone com DDD"){
		msg += "<span>Telefone não preenchido.</span><br />";
    }
	
	if($('#cidade').val() == "" || $('#cidade').val() == "Cidade"){
		msg += "<span>Cidade não preenchida.</span><br />";
    }
	
	if($('#estado').val() == "-1"){
		msg += "<span>Estado não Selecionado.</span><br />";
    }
	
	if($('#cep').val() == "" || $('#cep').val() == "Cep"){
		msg += "<span>Cep não preenchido.</span><br />";
    }
	
	if($('#depart').val() == "-1"){
		msg += "<span>Departamento não Selecionado.</span><br />";
    }
	
	if($('#msg').val() == "" || $('#msg').val() == "Deixe aqui sua mensagem"){
		msg += "<span>Mensagem não preenchida.</span><br />";
    }
	

	if(msg != ""){
		msg = "<div id=\"topoValida\">Os seguintes campos encontram-se com problemas:<br /><br /></div>" + msg;
		jQuery.facebox(msg);
		return false;
	}
}

/**
 * Função de Validação do Formulário de Trabalhe conosco
 *
 * @return boolean
 */
function validaTrabalheConosco(){

	msg = "";
	
	if($('#campo').val() == "" || $('#campo').val() == "Os campos do formulário Trabalhe Conosco ainda não foram definidos"){
		msg += "<span>Campo não preenchido.</span><br />";
    }

	if(msg != ""){
		msg = "<div id=\"topoValida\">Os seguintes campos encontram-se com problemas:<br /><br /></div>" + msg;
		jQuery.facebox(msg);
		return false;
	}
}

/**
 * Função de Validação do Formulário Solicitar Acesso
 *
 * @return boolean
 */
function validaAcesso(){

	msg = "";
	
	if($('#campo').val() == "" || $('#campo').val() == "Os campos do formulário Trabalhe Conosco ainda não foram definidos"){
		msg += "<span>Campo não preenchido.</span><br />";
    }

	if(msg != ""){
		msg = "<div id=\"topoValida\">Os seguintes campos encontram-se com problemas:<br /><br /></div>" + msg;
		jQuery.facebox(msg);
		return false;
	}
}

function checkMail(mail){
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if(typeof(mail) == "string"){
        if(er.test(mail)){ return true; }
    }else if(typeof(mail) == "object"){
        if(er.test(mail.value)){
                    return true;
                }
    }else{
        return false;
        }
}

function abas(id){
	
	var num = $(".abas > *").size();
	
	if(document.getElementById("item_"+id).style.display == "none"){
		for(i=0;i<num;i++){
			if(document.getElementById("item_"+i).style.display == "block"){
				$("#item_"+i).toggle("slow");
				$("#lista_"+i).removeClass('down');
			}
		}
		$("#lista_"+id).addClass('down');
		$("#item_"+id).toggle("slow");
	}else{
		$("#item_"+id).toggle("fast");
		$("#lista_"+id).removeClass('down');
	}
	
}
function open_url(url){
	location.href = url;
}


function MM_findObj(n, d) { //v4.0
	var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_changeProp(objName,x,theProp,theValue) { //v3.0
	var obj = MM_findObj(objName);
	if (obj && (theProp.indexOf("style.")==-1 || obj.style)) eval("obj."+theProp+"='"+theValue+"'");
}

function fix_object(prop){
	var prop = prop;
	if(prop=="0"){
		//MM_changeProp('topo','','style.clip','rect(auto 941px 385px auto)','DIV');	
	} else {
		//MM_changeProp('topo','','style.clip','rect(auto 941px 190px auto)','DIV');	
	}
}

function CompilaFlash(arq,largura,altura) {
    document.write("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"+largura+"' height='"+ altura +"' id='flash' align='middle' VIEWASTEXT>"+
	 "<param name='allowScriptAccess' value='always' />"+
	 "<param name='movie' value='"+ arq +"' />"+
	 "<param name='quality' value='high' />"+
	 "<param name='wmode' value='transparent' />"+
	 "<param name='allowFullScreen' value='true' />"+
	 "<embed src='"+ arq +"' quality='high' wmode='transparent' menu='false' width='"+largura+"' height='"+ altura +"' name='flash' align='middle' allowScriptAccess='always' allowFullScreen='true' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />"+
	"</object>");
}
