/**
 * @author marcosb
 */

function getList() {
	if (!list) {
		try {
			list = $(".banner_rotativo_img");
			var i=0;
			for (; i<list.length; i++) {
				var img = list[i];
				img.style.visibility = "visible";
				$("#"+list[i].id).hide();
			}
		} catch( e ) {
			return false;
		}
	}
	return true;
}

function hideTodos() {
	try {
		var i=0;
		for (; i<list.length; i++) {
			$("#"+list[i].id).hide();
		}
	} catch ( e ) { }
}

function showItem() {
	if ( parseInt(index) == Number.NaN ) index = 0;
	hideTodos();
	try {
		var img = list[index];
		$("#"+img.id).fadeIn("slow");
	} catch ( e ) { }
	clearTimeout( timerId );
	timerId = setTimeout( "timmerBanner()", DELAY_TIMMER);
}

function volta( e ) {
	getList();
	try {
		if (index>0) index--; else index = list.length - 1;
		showItem();
	} catch ( e ) { }
}

function frente( e ) {
	getList();
	try {
		if (index<list.length) index ++;
		if (index>=list.length) index = 0;
		showItem();
	} catch ( e ) { }
}

function timmerBanner() {
	try{
		frente();
	} catch( e ) { }
	timerId = setTimeout( "timmerBanner()", DELAY_TIMMER);
}

function mouseOver( ob ) {
	if (ob=="esq") {
		document.getElementById('esq').className = 'banner_rotativo_bot_esq_hover';
	} else {
		document.getElementById('dir').className = 'banner_rotativo_bot_dir_hover';
	}
}

function mouseOut( ob ) {
	if (ob=="esq") {
		document.getElementById('esq').className = 'banner_rotativo_bot_esq';
	} else {
		document.getElementById('dir').className = 'banner_rotativo_bot_dir';
	}
}

function initBanner() {
	try {
		$("#esq").mouseover( function () { mouseOver('esq'); } ).mouseout( function () { mouseOut('esq'); } );
		$("#dir").mouseover( function () { mouseOver('dir'); } ).mouseout( function () { mouseOut('dir'); } );
	} catch ( e ) { }
	try {
		getList();
		index = list.length-1;
	} catch ( e ) { }
	timmerBanner();
}

var timerId;
var list = false;
var index = 0;
var DELAY_TIMMER = 8000;