// SOLUÇÃO PARA O SCRIPT DO JQUERY QUE ENTRA EM CONFLITO COM O SCRIPT DO PROTOTYPE.
// FOI SUBSTTITUIDO O $ PARA $foo PARA SOLUCIONAR O PROBLEMA DO CONFLITO ENTRE OS SCRIPTS.
var $foo = jQuery.noConflict();

//escreve o flash na div desejada para que nao precise clicar nele antes de usa-lo
function montaFlashParams(width, height, arquivo, params, destino){

	var parametro = false;
	
	if(params != null || params != "" || params != "none"){
		parametro = true;
	}
	
	var myFlash =
	'<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="'+width+'" height="'+height+'" id="'+arquivo+'" align="middle">'+
	'<param name="allowScriptAccess" value="sameDomain" />'+
	'<param name="movie" value="swf/'+arquivo+'.swf';if(parametro){ myFlash += '?'+params;} myFlash += '" />'+
	'<param name="wmode" value="transparent" />'+
	'<param name="scale" value="noscale" />'+
	'<param name="quality" value="high" />'+
	'<param name="bgcolor" value="#ffffff" />'+
	'<embed src="swf/'+arquivo+'.swf'; if(parametro){ myFlash += '?'+params;} myFlash += '" wmode="transparent" quality="high" width="'+width+'" height="'+height+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
	'</object>'
	;
	document.getElementById(destino).innerHTML = myFlash;
}


function init(){
	$foo('ul.btns li:last').attr({ style: "padding:0; border:0; text-align:left;"});
	$foo('ul.submenu li:last').attr({ style: "background:none;"});
}

//  FUNÇÃO PARA CALCULAR O TAMANHO DA <UL> DA ABA, BASEADA NO TAMANHO DAS <LI>'s
function getWidth(destino, elem){
	var width = 0;
	$foo("#"+destino+" ul."+elem+" li").each(function(){
		 width+= $foo(this).width()+2;
	});	
	
	if(width > 600){
		$foo("#"+destino+" a.seta_esq").attr({style: "display:block;"});
		$foo("#"+destino+" a.seta_dir").attr({style: "display:block;"});
		$foo("#"+destino+" .abas").attr({style: "width:550px;"});
		$foo("#"+destino+" ul."+elem).attr({style: "width:"+width+"px;"});
		
	}
}

// FUNÇÃO PARA MOVER AS ABAS PARA DIREITA E PARA ESQUERDA
function moveAba(direction, destino, aba){
	var distancia = 100;
	var width = $foo("#"+destino+" ul."+aba).width();
	
	var margin = $foo("#"+destino+" ul."+aba).css("marginLeft");
	margin = parseInt(margin.slice(0,-2));
	
	
	if(direction == "left"){
		margin = margin-distancia;
		$foo("#"+destino+" ul."+aba).animate( { marginLeft: margin+"px" }, 500 );
		
		
		//condição para trabalha com numeros positivos.
		if(margin<0){
			margin = margin*-1;
		}
		
		var aux = width - 550;
		
		
		if(margin>=aux){
			$foo("#"+destino+" ul."+aba).animate( { marginLeft: aux*-1+"px" }, 200 )
			$foo("#"+destino+" a.seta_dir img").attr("src", "img/aba_seta_dir2.jpg");
			$foo("#"+destino+" a.seta_dir").attr("href", "javascript:;");
			$foo("#"+destino+" a.seta_dir").attr({ style: "display:block; cursor:default;"});
		}
		
		
		$foo("#"+destino+" a.seta_esq img").attr("src", "img/aba_seta_esq1.jpg");
		$foo("#"+destino+" a.seta_esq").attr("href", "javascript:moveAba('right','"+destino+"','"+aba+"');");
		$foo("#"+destino+" a.seta_esq").attr({ style: "display:block; cursor:pointer;"});
	}else{
		margin = margin+distancia;
		$foo("#"+destino+" ul."+aba).animate( { marginLeft: margin+"px" }, 500 );
		
		
		if(margin>=0){
			$foo("#"+destino+" ul."+aba).animate( { marginLeft: 0+"px" }, 200 )
			$foo("#"+destino+" a.seta_esq img").attr("src", "img/aba_seta_esq2.jpg");
			$foo("#"+destino+" a.seta_esq").attr("href", "javascript:;");
			$foo("#"+destino+" a.seta_esq").attr({ style: "display:block; cursor:default;"});
		}
		
		
		$foo("#"+destino+" a.seta_dir img").attr("src", "img/aba_seta_dir1.jpg");
		$foo("#"+destino+" a.seta_dir").attr("href", "javascript:moveAba('left','"+destino+"','"+aba+"');");
		$foo("#"+destino+" a.seta_dir").attr({ style: "display:block; cursor:pointer;"});
	}
}


//  FUNÇÃO QUE MUDA A CLASSE DE CADA ABA CLICADA PARA A ATUAL 
//  E CHAMA O CONTEUDO DA ABA CLICADA
function abreAbas(destino, aba, pagina){
	$foo("#"+destino+" .menu_abas *").removeClass("atual");
	$foo("#"+destino+" .menu_abas ."+aba).addClass("atual");
	
	show_loading(destino);
	setTimeout("pausa('"+destino+"','"+pagina+"')",2000);
}

//  CARREGA A PAGINA DA ABA NO DESTINO
function pausa(destino, pagina) {
	$foo("#"+destino+" .conteudoAba").load("inc/"+pagina+".php", function() {											
	//$foo('#hotsite_imgs').load("ctrlImplementa.php?acao="+pagina, function() {
		hide_loading(destino);
	});
}

//  MOSTRA MENSAGEM DE CARRAGANDO DA ABA
function show_loading(destino) {
	$foo("#"+destino+" .carregando").fadeIn();
	$foo("#"+destino+" .conteudoAba").slideUp("slow");
}

//  OCULTA MENSAGEM DE CARRAGANDO DA ABA
function hide_loading(destino) {
	$foo("#"+destino+" .conteudoAba").slideDown("slow");
	$foo("#"+destino+" .carregando").fadeOut();
}