var ipg = 0;
function slideUp(lmu){
	$("#menu"+lmu).find(".smDiv").slideUp(50, function(){ document.getElementById("menu"+lmu).overmn = 0; });
}
function checkHover(){
	for(lm=1;lm<=12;lm+=2){
		if(document.getElementById("menu"+lm).overmn == 1){
			$("#menu"+lm).timemn = setTimeout("slideUp("+lm+")",300);
		}
	}
}
function fadeintlassoc(){ $("#intlassoc").fadeIn(1200); }

$(document).ready(function(){
	restaura();
	$(".mnabre").hover(function(){ $(this).addClass("mnabreOver");}, function(){ $(this).removeClass("mnabreOver"); });
	$(".mn").hover(
		function(){
			idThis = $(this).attr("id");
			$(this).addClass("mnOver");
			if(!document.getElementById(idThis).overmn) document.getElementById(idThis).overmn = 0;
			if(document.getElementById(idThis).overmn == 0){
				document.getElementById(idThis).overmn = 2;
				$(this).find(".smDiv").slideDown("fast",
					function(){
						document.getElementById(idThis).overmn = 1;
					}
				);
			}
		},
		function(){
			idThis = $(this).attr("id");
			for(lm=1;lm<=12;lm++){ if($("#menu"+lm)){ if($("#menu"+lm).hasClass("mnAtivo")){ } else { if(lm != parseInt(idThis.substr(4))){ $("#menu"+lm).removeClass("mnOff"); } } } }
			$(this).removeClass("mnOver");
			document.getElementById(idThis).overmn = 1;
			checkHover();
		}
	);
	
	$(".submn").hover(function(){ $(this).addClass("submnOver");}, function(){ $(this).removeClass("submnOver"); });
	$(".anoNews").hover(function(){ $(this).addClass("anoNewsOver");}, function(){ $(this).removeClass("anoNewsOver"); });
	$(".mesNews").hover(function(){ $(this).addClass("mesNewsOver");}, function(){ $(this).removeClass("mesNewsOver"); });
	$(".verTextoPrancha").hover(function(){ $(this).addClass("verTextoPranchaOver");}, function(){ $(this).removeClass("verTextoPranchaOver"); });
	$("a").hover(function(){ $(this).addClass("aOver");}, function(){ $(this).removeClass("aOver"); });
	$("#sitedesign").hover(function(){ $(this).attr("src","<?=$dirRoot;?>/image/site/sitedesign_over.gif");}, function(){ $(this).attr("src","<?=$dirRoot;?>/image/site/sitedesign.gif"); });
	$(".aDark").hover(function(){ $(this).addClass("aOver");}, function(){ $(this).removeClass("aOver"); });
	$(".mn").show();
	$(".mn").each( function(){ this.over = 0; } )
	$(".mnPg").show();
	$(".mnSlash").show();
	$(".mnAtivo").show();
	$(".cinzaproj").fadeIn(1000);
	if(document.getElementById("intlassoc")){ setTimeout("fadeintlassoc()",1200); }
	if(document.getElementById("tablePRJ")){ setLoaded(); }
	$(".pressmn").hover(function(){ $(this).addClass("pressmnOver");}, function(){ $(this).removeClass("pressmnOver"); });
	$(".prjmn").hover(function(){ $(this).addClass("prjmnOver");}, function(){ $(this).removeClass("prjmnOver"); });
	$(".power").hover(function(){ $(this).addClass("powerOver");}, function(){ $(this).removeClass("powerOver"); });
	
});
$(window).resize(function(){ restaura(); });
var listarpais = 0;
var listarpaisen = 0;



function makeWindow(vURL,nameW,w,h){
	if(w == 0 && h == 0){
		var vScreenWidth = window.screen.availWidth;
		var vScreenHeight = window.screen.availHeight;
		var lf = 0;
		var tp = 0;
		var vFeatures = "fullscreen=yes, toolbar=no, status=no, menubar=no, scrollbars=yes, resizable=yes, directories=no, location=no, left="+lf+", top="+tp+", width="+vScreenWidth+", height="+ vScreenHeight;
	} else {
		var vScreenWidth = w;
		var vScreenHeight = h;
		var lf = (window.screen.availWidth - w)/2;
		var tp = (window.screen.availHeight - h)/2;
		var vFeatures = "toolbar=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, directories=no, location=yes, left="+lf+", top="+tp+", width="+vScreenWidth+", height="+ vScreenHeight;
	}
	window.open(vURL,nameW,vFeatures);
}

function urlgo(link){
	$('#recJS').html(link);
	$.post('o_function_txt.php', {'id_pg': link}, function(data) {
		$("#Conteudo").hide();
		$("#Conteudo").html(unescape(data));
		$("#Conteudo").fadeIn(1000);
	});
}
var redH = 10;
function restaura(){
	if(document.getElementById("sizeH")){
		var altura = $(window).height() - redH;
		$("#sizeH").height(altura);
	}
	if(document.getElementById("setinhasDiv")){
		var largura = $(window).width() - 70;
		$("#setinhasDiv").width(largura);
	}
	if(document.getElementById("overCont")){
		var hoc = $(window).height() - 150;
		var woc = $(window).width() - 100;
		$("#overCont").height(hoc);
		$("#overCont").width(woc);
		$("#divOverCont").height(hoc);
		$("#divOverCont").width(woc);
	}
	//setLoaded();
}

function overMenu(ob, act){
	if(!document.getElementById(ob).vob) document.getElementById(ob).vob = "off";
	if(act == 1){
		if(document.getElementById(ob).vob == "off"){
			document.getElementById(ob).vob = "moving";
			$("#"+ob).slideDown("fast", function(){ document.getElementById(ob).vob = "over"; });
		}
	} else {
		document.getElementById(ob).vob = "moving";
		//$("#"+ob).slideUp("fast", function(){ document.getElementById(ob).vob = "off"; });
	}
}

function loopThumb(lanum, linum){ // (numero de referencia do layer, numero de imagens do layer)
	var vob = document.getElementById("thumb"+lanum);
	if(!vob.inum) vob.inum = 1;
	vob.inum++;
	if(vob.inum > linum) vob.inum = 1;
	for(la=1;la<=linum;la++){
		if(la == vob.inum){
			$("#t"+lanum+"_"+la).fadeIn(300);
			$("#c"+lanum+"_"+la).show();
		} else {
			$("#t"+lanum+"_"+la).fadeOut(300);
			$("#c"+lanum+"_"+la).hide();
		}
	}
	
}

function playThumb(anum, inum){
	$("#thumb"+anum).fadeIn(700);
	$(".thumbTit"+anum).each(function(i){ $(this).css("color","#333333"); });
	tempo = setInterval("loopThumb("+anum+", "+inum+")",1000);
}

function stopThumb(anum, inum){
	$("#thumb"+anum).fadeOut(700);
	$(".thumbTit"+anum).each(function(i){ $(this).css("color","#8E9093"); });
	if(tempo) clearInterval(tempo);
}

function overPress(idp, act){
	if(act == 1){
		$("#pressThumb"+idp).fadeIn(1000);
		$(".pressTit"+idp).each(function(i){ $(this).css("color","#000000"); });
	} else {
		$("#pressThumb"+idp).fadeOut(1000);
		$(".pressTit"+idp).each(function(i){ $(this).css("color","#666666"); });
	}
}

function gotToUrl(urltogoS){
	document.location = urltogoS;
}
function goNext(divPrev, urltogo){
	$("#"+divPrev).fadeOut(500);
	setTimeout("gotToUrl('"+urltogo+"')",1000);
}

function showTexto(divt){
	obd = document.getElementById(divt).style;
	if(obd.display == "none"){
		obd.display = "block";
	} else {
		obd.display = "none";
	}
}

function setLoaded(){
	if(document.getElementById("tableTitulo")) $('#tableTitulo').show();
	if(document.getElementById("tablePRJ")) $('#tablePRJ').show();
	$('#preloader').fadeOut(200);
}

var pranchaAtual = 0;
var pranchaArray = new Array();
var pranchaIdArray = new Array();
//var pranchaTituloArray = new Array();
//var pranchaTextoArray = new Array();
var pranchaTotal = 0;
var himgport = 450;
function change(np){
	$('#tableTitulo').hide();
	$('#tablePRJ').show();
	if(np == "prev"){
		if(pranchaAtual == 1){ pranchaAtual = pranchaTotal; } else { pranchaAtual = pranchaAtual-1; }
	} else {
		if(pranchaAtual == pranchaTotal){ pranchaAtual = 1; } else { pranchaAtual = pranchaAtual+1; }
	}
	$("#prancha").html("<img src='"+pranchaArray[pranchaAtual]+"' border='0' hspace='0' vspace='0' id='imgProj' onload='setLoaded();'>");
	
	//if(pranchaTextoArray[pranchaAtual].length > 0){
	//	$("#textoPranchaLink").fadeIn("fast");
	//} else {
	//	$("#textoPranchaLink").fadeOut("fast");
	//}
}

var obj = null;


function animaMn(imnidgo){
	$("#"+imnidgo).animate({left: '+=100px'}, { queue:false, duration:2000 }).fadeIn(2000);
}

// OLD Video Player 





// New Video Player 
function flash(arquivo, w, h){
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + w + '" height="' + h + '">');
	document.write('<param name="movie" value="'+arquivo+'">');
	document.write('<param name="quality" value="high">');
	document.write('<param name="wmode" value="transparent">');
	document.write('<embed src="'+arquivo+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + w + '" height="' + h + '" WMODE="transparent"></embed>');
	document.write('</object>');
}





// FORMULARIOS
function envia(formulario) {
	corfundoErro = "#FFEEEE";
	mensagem = "";
	var rn=0;
	var rc=0;
	valores = new Array();
	
	valores[1] = new Array("titulo_news",2,"TITULO DA NOTICIA");
	valores[2] = new Array("texto_news",2,"TEXTO DA NOTICIA");
	
	valores[3] = new Array("senha_user",2,"SENHA");
	valores[4] = new Array("email_user","email","EMAIL");
	
	valores[5] = new Array("nome_cli",2,"NOME DO CLIENTE");
	valores[6] = new Array("razaosocial_cli",2,"RAZAO SOCIAL DO CLIENTE");
	
	valores[7] = new Array("id_cli","select","CLIENTE");
	valores[8] = new Array("nome_marca",2,"NOME DA MARCA");
	
	valores[9] = new Array("id_cli","select","CLIENTE");
	valores[10] = new Array("id_marca","select","MARCA");
	valores[11] = new Array("nome_projeto",2,"NOME DO PROJETO");
	
	valores[12] = new Array("id_cli","select","CLIENTE");
	valores[13] = new Array("id_marca","select","MARCA");
	valores[14] = new Array("id_projeto","select","PROJETO");
	valores[15] = new Array("nome_sku",2,"NOME DO SKU");
	
	valores[16] = new Array("status_avaliador","radio","STATUS VALIDO");
	
	valores[100] = new Array("ipg",1,"PAGINA");
	
	if(formulario == "formNews"){ ni=1; nf=2;
	} else if(formulario == "formCli"){ ni=5; nf=6;
	} else if(formulario == "formMarca"){ ni=7; nf=8;
	} else if(formulario == "formProj"){ ni=9; nf=11;
	} else if(formulario == "formJob"){ ni=12; nf=15;
	} else if(formulario.substring(0,11) == "formAvalia_"){ ni=16; nf=16;
	} else { ni=100; nf=100; }
	
	for(n=ni;n<=nf;n++){
		//alert("ni: "+ni+" & nf: "+nf+" ===> n: "+n);
		elem = eval("document."+formulario+"."+valores[n][0]+".value");
		
		if(valores[n][1] == 'select'){
			if (eval("document."+formulario+"."+valores[n][0]+".options[document."+formulario+"."+valores[n][0]+".selectedIndex].value") == 0) {
				mensagem += "SELECIONE " + valores[n][2] + "\n";
			}
		} else if(valores[n][1] == 'radio'){
			groupradio = eval("document."+formulario+"."+valores[n][0]);
			ckd = 0;
			for(var r=0; r<groupradio.length; r++){ if(groupradio[r].checked){ ckd = r; } }
			if(groupradio[ckd].value == 3) mensagem += "SELECIONE " + valores[n][2] + "\n";
		} else if(valores[n][1] == 'email'){
			document.getElementById(""+valores[n][0]+"").style.backgroundColor="#FFFFFF";
			a=elem.indexOf('@');
			p=elem.indexOf('.');
			if (a<1 || p<1) {
				mensagem += 'E-MAIL v%E1lido.\n';
				document.getElementById(""+valores[n][0]+"").style.backgroundColor=corfundoErro;
			}
		} else {
			if(n != 100) document.getElementById(""+valores[n][0]+"").style.backgroundColor="#FFFFFF";
			if (elem.length < valores[n][1]) {
				mensagem += valores[n][2]+' \n';
				if(n != 100) document.getElementById(""+valores[n][0]+"").style.backgroundColor=corfundoErro;
			}
		}
	}
	if(mensagem.length > 2){
		alert("Preencha corretamente os seguintes campos:\n\n"+unescape(mensagem)+"\n");
		return false;
	} else {
		eval("document."+formulario).submit();
		return true;
	}
}


// FUNCOES SISTEMA EDITORIAL
// #########################

function edInsertLink(myField) {
	var defaultValue = 'http://';
	var URL = prompt('Endereco:' ,defaultValue);
	var URLTemp = URL.substr(7);
	URLText = URLTemp;
	var URLText = prompt('Texto "XXX" que aparece para o leitor:\n<a href="' + URL + '" target="_blank">XXX</a>' ,URLTemp);
	if(URL){
		myValue = '<a href="' + URL + '" target="_blank">' + URLText + '</a>';
		insertAtTexto(myField, myValue);
	}
}

imagemN = 0;
function insertAtTexto(myField, myValue) {
	var selTemp = "";
	if (document.selection) {
		myField.focus();
	    var sel = document.selection.createRange();
		if (sel.text.length > 0) {
			selTemp = sel.text;
		}
		
	} else if (myField.selectionStart || myField.selectionStart == '0') {
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		selTemp = myField.value.substring(startPos, endPos);
	}

	if(myValue == "urlInsert"){
		var defaultValue = 'http://';
		if(selTemp == ""){
			var URLText = prompt('Texto que aparece para o usuario:' ,selTemp);
		} else {
			URLText = selTemp;
		}
		var URLLink = prompt('Link externo:' ,defaultValue);
		var URLName = prompt('Nome da janela:' ,"ARTHURCASAS");
		var URLW = prompt('Largura da janela:' ,750);
		var URLH = prompt('Altura da janela:' ,420);
		myValue = "<a href=\"javascript:makeWindow('" + URLLink + "','" + URLName + "'," + URLW + "," + URLH + ");\">" + URLText + "</a>";
	}
	if(myValue == "internalLink"){
		var defaultValue = "http://www.arthurcasas.com/pt/news/";
		if(selTemp == ""){
			var URLText = prompt('Texto que aparece para o usuario:' ,selTemp);
		} else {
			URLText = selTemp;
		}
		var URLLink = prompt('Nome da secao e complementos:' ,defaultValue);
		myValue = "<a href='" + URLLink + "'>" + URLText + "</a>";
	}
	if(myValue == "b>" || myValue == "i>"){
		if(selTemp == ""){
			selTemp = prompt('Texto para formatar' ,'');
		}
		myValue = '<' + myValue + '' + selTemp + '</' + myValue;
	}
	
	if(myValue.length > 0){
		if (document.selection) {
			sel.text = myValue;
			myField.focus();
		} else if (myField.selectionStart || myField.selectionStart == '0') {
			myField.value = myField.value.substring(0, startPos)
						  + myValue 
						  + myField.value.substring(endPos, myField.value.length);
			myField.focus();
			myField.selectionStart = startPos + myValue.length;
			myField.selectionEnd = startPos + myValue.length;
		} else {
			myField.value += myValue;
			myField.focus();
		}
	}
}