// verificar plugin flash
function flashPlugin( plugin_version ){
	var default_version = 5 ;
	var version ;
	if( plugin_version.length == "" ){
		version = new Number( default_version ) ;
	}
	else{
		version = new Number( plugin_version ) ;
	}
	var agent = navigator.userAgent.toLowerCase() ;
	var plugin = new String() ;
	var plugin_description = new String() ;
	if ( navigator.plugins && navigator.plugins.length ){
		for ( var i = 0 ; i < navigator.plugins.length ; i++ ){
			plugin = navigator.plugins[i] ;
			plugin_description = plugin.description.split( " " ) ;
	if ( plugin_description[0] == "Shockwave" && plugin_description[1] == "Flash" && plugin_description[2].split( "." )[0] >= version.valueOf() ){
	            return true ;
	        }
	        else{
		        for ( var j = 0 ; j < plugin.length ; j++ ){
		        	if ( plugin[j].type == "application/x-shockwave-flash"){
		        		return true ;
		        	}
		        }
		    }
		}
		return false ;
	}
	else if ( navigator.mimeTypes && navigator.mimeTypes.length ){
		var detectPlugin = navigator.mimeTypes[ "application/x-shockwave-flash" ] ;
		if( detectPlugin && detectPlugin.enabledPlugin ){
			return true ;
		}
		else{
			return false ;
		}
	}
	else if ( agent.indexOf( "msie" ) != -1 && parseInt( navigator.appVersion , 10 ) >= 4 ){
		document.write( "<scr" + "ipt language=\"VBScript\"> \n") ;
		document.write( "on error resume next \n" ) ;
		document.write( "dim plugin \n" ) ;
		document.write( "dim IEDetect \n" ) ;
		document.write( "set plugin = CreateObject(\"ShockwaveFlash.ShockwaveFlash." + version + "\") \n" ) ;
		document.write( "if IsObject( plugin ) then \n" ) ;
		document.write( "IEDetect = true \n" ) ;
		document.write( "else IEDetect = false \n" ) ;
		document.write( "end if" ) ;
		document.write( "<\/scr" + "ipt> \n") ;
		if( IEDetect ){
			return true ;
		}
	}
	return false ;
}


// Função genérica para navegação que utilize tabs
function show_tab( obj_id ){
	if ( !document.getElementById ){
		return ;
	}
	var i , obj , parent_node ;
	if ( document.getElementById( obj_id ) ){
		var obj = document.getElementById( obj_id ) ;
		var obj_list = obj.parentNode.getElementsByTagName( obj.tagName ) ;
		for ( i = 0 ; i < obj_list.length ; i++ ){
			obj_list.item(i).style.display = "none" ;
		}
		obj.style.display = "block" ;
	}
}

function browser_is_ie_mac(){
	return ( navigator.platform.toLowerCase().indexOf("mac") > -1 ) && ( navigator.appName.indexOf( "Internet Explorer" ) > -1 ) ;
}

/* flash erra ao converter texto acentuado por problemas de charset
O texto enviado ao flash deve ser enviado como codigos decimais de charset */
function browser_decompose( s ){
	var str = "" , val ;
	for( var i = 0; i < s.length; ++i ){
		val = s.charCodeAt(i).toString() ;
		while ( val.length < 3 ){
			val = "0" + val ;
		}
		str += val ;
	}
	return str ;
}

function show_layer(fname,visible){
	var s = '' ;
	var b = '' ;
	if (document.layers) {
		if( visible ){
			s = 'show' ;
			b = 'block' ;
		}
		else{
			s = 'hide' ;
			b = 'none' ;
		}
		document.layers[eval('"'+fname+'"')].visibility = s ;
	}
	else if (document.all){
		if( visible ) {
			s = 'visible' ;
			b = 'block' ;
		}
		else {
			s = 'hidden' ;
			b = 'none' ;
		}
		document.all[eval('"'+fname+'"')].style.visibility = s ;
	}
	else if (document.getElementById){
		if( visible ){
			s = 'visible' ;
			b = 'block' ;
		}
		else{
			s = 'hidden' ;
			b = 'none' ;
		}
		document.getElementById(eval('"'+fname+'"')).style.visibility = s ;
	}
}
function set_display( fname, b ){
	var s = '' ;
	( b ) ? s = 'block' : s = 'none' ;
	if ( document.layers ) {
		document.layers[eval('"'+fname+'"')].display = s ;
	} else if ( document.all ) {
		document.all[eval('"'+fname+'"')].style.display = s ;
	} else if ( document.getElementById ) {
		document.getElementById(eval('"'+fname+'"')).style.display = s ;
	}
}
/* handle_layer_display */
function j(fname,b){
	set_display( fname, b );
	show_layer( fname, b );
}

function draw_mini_player( url , text , width , height , path ){
	var tag = "" ;
	var flashvars = "url=" + escape( url ) + "&description=" + browser_decompose( text ) ;
	if ( navigator.appName.indexOf( "Internet Explorer" ) > -1 ){
		tag += "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\"" + width + "\" height=\"" + height + "\" id=\"player\" align=\"middle\">" ;
		tag += "<param name=\"movie\" value=\"" + path + "\">" ;
		tag += "<param name=\"allowScriptAccess\" value=\"always\">" ;
		tag += "<param name=\"quality\" value=\"high\">" ;
		tag += "<param name=\"flashvars\" value=\"" + flashvars + "\">" ;
		if ( browser_is_ie_mac() ){
			tag += "<embed type=\"application/x-shockwave-flash\" width=\"" + width + "\" height=\"" + height + "\" id=\"player\" allowScriptAccess=\"always\"  src=\"" + path + "\" flashvars=\"" + flashvars + "\"><\/embed>" ;
		}
	}
	else{
		tag += "<object type=\"application/x-shockwave-flash\" width=\"" + width + "\" height=\"" + height + "\" data=\"" + path + "\" flashvars=\"" + flashvars + "\"  allowScriptAccess=\"always\" id=\"player\">" ;
	}
	tag += "<\/object>";
	document.write(tag);
}

var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
function player_DoFSCommand(command, args) {
	var playerObj = isInternetExplorer ? document.all.player : document.player;
	//
	if(command == "start") start_refresh() ;
	if(command == "stop") stop_refresh() ;
	//
}
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub player_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call player_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('<\/script>\n');
}
function start_refresh(){
	var site_refresh = setInterval('top.location.reload()',300000);
}
function stop_refresh(){
	clearInterval(site_refresh);
}
start_refresh();


/* controle  foto rotativa */
var iDelaySlide = 10000 ; // ms
var iDelayOpacity = 80 ; // ms
var rotate_index = 0 ; // int
var rotate_interval = null ;
var timer = null ;

function rreload(){
	if( !document.getElementById ){
		return ;
	}

	rotate_index += 1 ;
	if( rotate_index < 0 ) rotate_index = aJJBA.length - 1;
	if( rotate_index > aJJBA.length - 1) rotate_index =  0;

	if ( rotate_interval ){
		rpause() ;
	}
}

function rnav( iPos ){
	if( !document.getElementById ){
		return ;
	}

	rotate_index += iPos ;
	if( rotate_index < 0 ) rotate_index = aJJBA.length - 1;
	if( rotate_index > aJJBA.length - 1) rotate_index =  0;

	if ( rotate_interval ){
		rpause() ;
	}

	if ( timer ){
		jjba_opcty(100);
	}

	with( document ) {
		var el_crd = getElementById( "ju_crd" );
		var el_img = getElementById( "ju_img" );
		var el_ftr = getElementById( "ju_ftr" );
		var el_lnk1 =  getElementById( "ju_link1" );
		var el_lnk2 =  getElementById( "ju_link2" );
	}

	if ( aJJBA && aJJBA.length > rotate_index ){
		el_crd.innerHTML = aJJBA[rotate_index][0];
		el_img.src = aJJBA[rotate_index][1];
		el_lnk1.href = aJJBA[rotate_index][2];
		el_lnk2.href = aJJBA[rotate_index][2];
		el_ftr.innerHTML = aJJBA[rotate_index][3] ;
		el_img.alt = aJJBA[rotate_index][3];
		if ( aJJBA[rotate_index][4] && aJJBA.length > rotate_index && aJJBA[rotate_index][4] == 'PUBLICIDADE' ){
			el_lnk1.target = '_blank' ;
			el_lnk2.target = '_blank' ;
		} else {
			el_lnk1.target = '' ;
			el_lnk2.target = '' ;
		}
	}
	jjba_opcty(10);
	jjba_rotate();
}

function jjba_opcty( iOpacity ){
	var curLayer = document.getElementById('ju_img');
	iOpacity == null ? iOpacity = 0 : iOpacity += 10;
	curLayer.style.opacity = iOpacity / 100 ;
	curLayer.style.filter = 'alpha(opacity=' + iOpacity + ')';
	if( iOpacity < 100 ) {
		timer = setTimeout('jjba_opcty(' + iOpacity + ')', iDelayOpacity);
	} else {
		clearTimeout(timer);
		timer = null ;
		jjba_reset();
	}
}

function jjba_reset(){
	var iOpacity = 99;
	var curLayer = document.getElementById('ju_img');
	curLayer.style.opacity = (iOpacity / 100);
	curLayer.style.filter = 'alpha(opacity=' + iOpacity + ')';
}

function jjba_rotate(){
	rotate_interval = window.setInterval('rnav(1)', iDelaySlide);
}

function rpause(){
	if ( rotate_interval ){
		clearInterval( rotate_interval );
		rotate_interval = null ;
	}
	else{
		rnav(1) ;
	}
}

function jjba_preload(a){
	var d = document;
	if(d.images) {
		if(!d.mm) d.mm = new Array();
		var i, j = d.mm.length ;
		for( i = 0; i < a.length; i++ ){
			if ( a[i][1].indexOf("#") != 0 ){
				d.mm[j] = new Image;
				d.mm[j++].src = a[i][1];
			}
		}
	}
}


// Função usada para "encodar" urls
function url_encode( str ) {
	var encoded = "" ;
	var valid_uri_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$-_.+!*'()," ;
	var hex_chars = "0123456789ABCDEF" ;
	for ( var i = 0 ; i < str.length ; i++ ) {
		if ( valid_uri_chars.indexOf( str.charAt( i ) ) == -1 ){
			encoded += "%" + hex_chars.charAt( str.charCodeAt( i ) >> 4 ) + hex_chars.charAt( str.charCodeAt( i ) & 0xF ) ;
		}
		else{
			encoded += str.charAt( i ) ;
		}
	}
	return encoded ;
}

// Retorna um número randômico de 10 digitos
function rand(){
	var r = new String( Math.round( Math.random()*100000000 ) ) ;
	while( r.length < 10 ){ r = "0" + r ; }
	return r ;
}


