﻿/* controle da 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' ;
		}*/
	}
	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];
			}
		}
	}
}