//
//
//
//
//
//

var isIE = false;
if (navigator.appVersion.match(/\bMSIE\b/)) { isIE = true;	}
var lnk_natela = false;
var aLnkShowAlt = [];

var lnk_natela = false;
updateBg = function() {
	$('box-conteudo').style.height = "auto";
	$("box-rodape").hide();
	var width_ = parseInt(document.body.scrollWidth);
	if (parseInt(document.body.scrollHeight) > 1095) {
		var height_ = 1190;//FIXO PELO BG, NAO ALTERAR
		var bgcxheight = 790;
		$('box-conteudo').style.height = "770px";
	} else {
		var height_ = parseInt(document.body.scrollHeight) + 70;
		var aTamConteudo = Element.getDimensions('box-conteudo');
		var bgcxheight = (aTamConteudo.height + 70);
	}
	//$('lbgGeral').style.height = height_ + "px";
	$("box-rodape").show();
	var aTamRodape = Position.cumulativeOffset($("box-rodape"));
	$("box-rodape").style.top = (height_ - 35) + "px";
	$("box-rodape").style.width = (width_ - aTamRodape[0] - (isIE?0:25)) + "px";	
	$('bg-caixa').style.height = bgcxheight+"px";	
}
	
MenuOver = function(obj_) {
	$(obj_).addClassName('item-menu-over');	
}
MenuOut = function(obj_) {
	$(obj_).removeClassName('item-menu-over');
}

LoginCliente = function() {
	$('lErroLogin').show();
	$('lErroLogin').update('Login ou senha incorretos !').style.color = "#CC0000";
	return false;
}
SendNews = function() {
	$('lStatusNews').hide();
	if (!$('news-email').present()) { 
		$('lStatusNews').update("Preencha seu e-mail!").style.color="#CC0000";
		$('lStatusNews').show();
	} else {
		$('bt-news').hide(); $('lCadastrando-news').show();		
		param_ = key_news+$('news-email').serialize();
		new Ajax.Updater('lStatusNews', 'index.php', 
		{ method: 'post', parameters: param_, evalScripts: true });			
	}
	return false;
}
abreHome = function() {
	$('bg-caixa').hide();
	$('menu-item-home').hide(); $('box-conteudo').hide(); $('box-home').show();
	updateBg();
}

linkHome = function() { abreHome(); }

linkContato = function() { abreLink('lnk-contato'); }

linkEmpresa = function() { abreLink('lnk-1'); }

linkRepertorio = function() { abreLink('lnk-2'); }

linkServicos = function() { abreLink('lnk-3'); }

linkRepertorioCategoria = function(cod_secao,tit_secao,passo_) { 
	if (passo_==null) { abreLink('lnk-2'); }
	try {
		ShowRepertoriosCat(cod_secao,tit_secao);
	} catch(e) {
		window.setTimeout('linkRepertorioCategoria('+cod_secao+',"'+tit_secao+'",1);',600);
	}	
}

mkLinkCat = function(obj_) {
	var	cod_secao = $(obj_).readAttribute('idcat');
	var	tit_secao = $(obj_).readAttribute('titcat');
	linkRepertorioCategoria(cod_secao,tit_secao);
}

linkRepertorioItem = function(cod_secao,tit_secao,cod_item,link_item,passo_) { 
	if (passo_==null) { linkRepertorioCategoria(cod_secao,tit_secao); }
	try {
		ShowVideoRepertorio(cod_item,link_item,'l');
	} catch(e) {
		window.setTimeout('linkRepertorioItem('+cod_secao+',"",'+cod_item+',"'+link_item+'",1);',600);
	}	
}

mkLinkRep = function(obj_) {
	var	cod_secao = $(obj_).readAttribute('idcat');
	var	tit_secao = $(obj_).readAttribute('titcat');
	var	cod_item = $(obj_).readAttribute('iditem');
	var	link_item = $(obj_).readAttribute('videoitem');
	linkRepertorioItem(cod_secao,tit_secao,cod_item,link_item);
}

abreLink = function(layer_) {
	$('bg-caixa').hide();
	$('lnk-2').update();
 	/* Repertorio */
	if (layer_=="lnk-2") { 
		param_ = key_repertorio;
		new Ajax.Updater('lnk-2', 'index.php', 
		{ method: 'get', parameters: param_, evalScripts: true });
	} 
	$('box-home').hide(); $('menu-item-home').show(); $('box-conteudo').show();
	if (lnk_natela) { $(lnk_natela).hide(); }
	$(layer_).show();
	lnk_natela = layer_;
	if (layer_!="lnk-2") {
		try { if (!aLnkShowAlt[layer_]) { $(layer_+"-alt").hide(); $('lT'+layer_).update(); $(layer_+"-main").show(); } } catch(e) { }
		window.setTimeout("showCaixa();",250);
	}
	window.setTimeout("updateBg()",100);
}
send_contato = function() {
	if (!$('fcontato-nome').present() || !$('fcontato-email').present() || !$('fcontato-mensagem').present()) { 
		$('lErroContato').update("Preencha seu nome, e-mail e mensagem!").style.color="#CC0000";
		$('lErroContato').show();
		new Effect.Highlight('lErroContato');
		updateBg();
	} else {
		$('bt-contato').hide(); $('lEnviando').show();		
		param_ = key_contato+Form.serialize('fcontato');
		new Ajax.Updater('lJSContato', 'index.php', 
		{ method: 'post', parameters: param_, evalScripts: true });			
	}
	return false;
}
send_ok = function() {
	$('lErroContato').update("<strong>Obrigado! Sua mensagem foi enviada com sucesso.</strong>").style.color="#009900";
	$('lErroContato').show();
	new Effect.Highlight('lErroContato');
	$('fcontato').reset();
	$('bt-contato').show();
	$('lEnviando').hide();
	updateBg();
}
newscad_ok = function() {
	$('lStatusNews').update("<strong>E-mail cadastrado! Obrigado.<br>Você receberá uma confirmação em seu email.</strong>");	
	$('lStatusNews').style.color="#009900";
	$('lStatusNews').show();
	
	new Effect.Highlight('lStatusNews');
	$('fnews').reset();
	$('bt-news').show();
	$('lCadastrando-news').hide();
	window.setTimeout("new Effect.Fade('lStatusNews');",'8000');
}
lerNoticia = function(noticia_) { 
	param_ = key_lernoticia+"noticia="+noticia_;
	new Ajax.Updater('lNovidadeContent', 'index.php', 
	{ method: 'get', parameters: param_, evalScripts: true });
	abreLink('lnk-novidades');
}
PopVideo = function(arquivo_) {
	var janela_ = window.open(arquivo_,'jVideo',"width=450,height=390,top=100,left=50");
	janela_.focus();
}
var repnatela_ = 0;
ShowRepertoriosCat = function(categoria_,descricat_) {
	if (repnatela_ && categoria_!=repnatela_) { $('lrepcat'+repnatela_).hide(); }
	try { $('lrepcat'+categoria_).show(); repTrocaPagina(categoria_,"lRep-"+categoria_+"-1"); repnatela_ = categoria_; } catch(e) { }
	$('lTCat').update(descricat_);
}
SetEffects = function() {
	new Effect.Opacity("bg-caixa", {to:0.3});
	new Effect.Opacity("box-rodape", {to:0.7});
	new Effect.Opacity("box-noticia-home", {to:0.6});	
}
showCaixa = function() {
	new Effect.Appear("bg-caixa",  {to:0.3});
}
ShowVideoRepertorio = function(cod_,video_,Hl_) {
	$(Hl_+'ContentRepertorio').hide();
	$(Hl_+'RepFocus').update( "<br>"+$(Hl_+'RepContent-'+cod_).innerHTML );

	var swfv = new SWFObject(video_+"&rel=0", "flashVideo", "425", "350", "8");
	swfv.addParam("wmode", "transparent");
	swfv.addParam("allowScriptAccess", "sameDomain");
	swfv.write(Hl_+"PlayerRepertorio");

	$(Hl_+'PlayerRepertorio').show();
	$(Hl_+'PlayerBackButton').show();
	$(Hl_+'RepFocus').show();
	if (Hl_=="l") { 
		window.setTimeout("updateBg();showCaixa();",100);	
	}
}
PlayerBack = function(Hl_) {
	$(Hl_+'PlayerRepertorio').hide(); $(Hl_+'PlayerBackButton').hide(); 
	$(Hl_+'RepFocus').update(); $(Hl_+'RepFocus').hide();
	$('bg-caixa').hide(); $(Hl_+'ContentRepertorio').show();
}
SwfPng = function(obj_,img_,h_) {
	if (h_==1) { 
		window.setTimeout("SwfPng('"+obj_+"','"+img_+"')",800);
		return;
	}
	var swfi = new SWFObject("imagens/img_repertorio.swf", "imgPng", "160", "148", "8");
	swfi.addVariable("imgurl", img_);
	swfi.addParam("wmode", "transparent");
	swfi.addParam("menu", "false");
	swfi.addParam("allowScriptAccess", "sameDomain");
	swfi.write(obj_);
}
var pagRepNatela = [];
repTrocaPagina = function(cat_,pagina_,modo_) { 
	if (modo_==1 || modo_==-1) {
		var lastnt_ = 0;
		if (pagRepNatela[cat_]) { lastnt_ = pagRepNatela[cat_]; lastnt_ = lastnt_.sub(pagina_,""); }
		lastnt_ = (parseInt(lastnt_)+modo_);
		pagina_ = pagina_+ lastnt_;
		if (lastnt_==0 || lastnt_>$('p-'+cat_).options.length) { return; }
		$('p-'+cat_).selectedIndex = (lastnt_-1);
	} 
	
	if (modo_==null && $('p-'+cat_)) { $('p-'+cat_).selectedIndex = 0; }
	//try { $(pagRepNatela).hide(); } catch(e) { }
	if (pagRepNatela[cat_] && pagRepNatela[cat_]!=pagina_) { $(pagRepNatela[cat_]).hide(); } 
	$(pagina_).show(); 
	pagRepNatela[cat_]=pagina_;
	$('box-conteudo').scrollTo(0,0);
	window.setTimeout("updateBg()",100);
}


window.setTimeout("updateBg();SetEffects();",600);

