function clean(obj,txt){
 if(obj.value=='') {
 obj.value=txt;
 } else if (obj.value == txt) {
obj.value = '';
 }
}

$(document).ready(function() {
	
	if ($('#flutuante').size() > 0) {
		$("#flutuante").fadeTo(0, 0.8);
		
		widht= $('body').width();
		height = $('body').height();
		
		$('#combo').hide();
		
		$("#flutuante").width(widht);
		$("#flutuante").height(height);		
	}
	
	$('#fechar').click(function(event) {
		$("#flutuante").hide();
		$("#bannerF").hide();
		$('#combo').show();
		event.preventDefault(event);
	});
		// Verifica a quantidade de itens do player se for maior que 1 executa o player
	if ( $('#player-opcoes li').size() > 1) {		
		playerIndex(1);
		
		// Botao Anterior
		$('#player-anterior').click(playerAnterior);
		
		// Botao Proxima
		$('#player-proxima').click(playerProxima);
		
		// Click Nos item do player
		$('#player-opcoes li').click(playerItem)
		
	}
	else {
		// Caso so tenha um item no player
		$('#player-menu-1').addClass('hover');
		
		$('#player-anterior ,#player-proxima').click(function(event){
			event.preventDefault(event);
			return false;
		})
	}
	
	
	

});


/**
 * Player da Index 
 */
function playerIndex (item) {
	
	// Reinalizo o item	
	if (item > $('#player-opcoes li').size()) {		
		item = 1;		
	}		
		
	if (item != 1) {
		// Esconder todas as imagens e mostro a proxima
		$('#player-img').animate({"marginLeft": "-=381px"}, "slow");
		$('.player-menu').removeClass('hover');
		$('#player-menu-' + item).addClass('hover');
	}
	else {
		$('#player-img').animate({"marginLeft": "0px"}, "slow");		
		$('.player-menu').removeClass('hover');
		$('#player-menu-' + item).addClass('hover');
	}
	
	item++;
		
	
	tempoPlayerIndex = setTimeout('playerIndex ('+item+');', 6000);	
}

/**
 * Botao Anterior
 */
function playerAnterior() {
	atual = $('.player-menu.hover').attr('id');	
	atual = atual.replace('player-menu-','');
	
	if (atual > 1) {		
		atual = atual - 1;	
		
		clearInterval(tempoPlayerIndex);		
		$('#player-img').animate({"marginLeft": "+=381px"}, "slow");
		$('.player-menu').removeClass('hover');
		$('#player-menu-' + atual).addClass('hover');
		
		atual++;
		tempoPlayerIndex = setTimeout('playerIndex ('+atual+');', 6000);		
	}	
	
	return false;
}

/**
 * Botao Proxima
 */
function playerProxima() {
	atual = $('.player-menu.hover').attr('id');	
	atual = atual.replace('player-menu-','');
	
	if (atual < $('#player-opcoes li').size()) {
		atual = parseInt(atual);
		atual++;
		
		clearInterval(tempoPlayerIndex);		
		$('#player-img').animate({"marginLeft": "-=381px"}, "slow");
		$('.player-menu').removeClass('hover');
		$('#player-menu-' + atual).addClass('hover');
		
		atual++;
		tempoPlayerIndex = setTimeout('playerIndex ('+atual+');', 6000);		
	}
	
	return false;
}

/**
 * PLayer Item
 */
function playerItem () {
	
	//Paro o player
	clearInterval(tempoPlayerIndex);
	
	//Elemento Atual
	atual = $('.player-menu.hover').attr('id');	
	atual = atual.replace('player-menu-','');
	
	//Elemento do Click
	click = $(this).attr('id');
	click = click.replace('player-menu-','');
	
	// Coloco o item como Hover
	$('.player-menu').removeClass('hover');
	$('#player-menu-' + click).addClass('hover');
	
	// Caso click maior que o atual vai pra frente se naum para traz
	if (click > atual) {
		
		diferenca = click- atual;
		mover = diferenca * 381;
		$('#player-img').animate({"marginLeft": "-="+mover+"px"}, "slow");
		
		click++;
		
		tempoPlayerIndex = setTimeout('playerIndex ('+click+');', 8000);	
	}
	else {
		
		diferenca = atual - click;
		mover = diferenca * 381;
		$('#player-img').animate({"marginLeft": "+="+mover+"px"}, "slow");
		
		click++;
		tempoPlayerIndex = setTimeout('playerIndex ('+click+');', 8000);
	}
	
}

function abrir(pagina, largura, altura){
   var esquerda = (screen.width - largura)/2;
   var topo 	= (screen.height - altura)/2;

   window.open(pagina,'','height=' + altura + ', width=' + largura + ', top=' + topo + ', left=' + esquerda + ', Scrollbars=NO, resizable=NO, menubar=NO');
}


/****************************\
FUNCAO QUE CRIA O OBJETO AJAX
\****************************/
function criarAjax() {
var ajax;
	try{
	    ajax = new XMLHttpRequest(); 
	}catch(ee){
	    try{
	        ajax = new ActiveXObject("Msxml2.XMLHTTP"); 
	    }catch(e){
	        try{
	            ajax = new ActiveXObject("Microsoft.XMLHTTP");
	        }catch(E){
	            ajax = false;
	        }
	    }
	}
return ajax;
}


//Tenta criar o objeto xmlHTTP

try{

    xmlhttp = new XMLHttpRequest();

}catch(ee){

    try{

       xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

    }catch(e){

       try{

          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

       }catch(E){

          xmlhttp = false;

       }

    }

}



function enviar_enquete(){

	var pergunta = document.votacao.cod_pergunta.value;

	//O voto. Cria uma variável como a opção escolhida.

	if(document.votacao.escolha1.checked) var voto=0

	else if(document.votacao.escolha2.checked) var voto=1

	else if(document.votacao.escolha3.checked) var voto=2

	else if(document.votacao.escolha4.checked) var voto=3

	else var voto=""

    //Abre a conexão

    xmlhttp.open("GET","http://www.ocnet.com.br/votar.php?voto=" + voto + "&per=" + pergunta, true);

    //Função para tratamento do retorno

    xmlhttp.onreadystatechange=function() {

        if (xmlhttp.readyState==4){

            //Mostra mensagem

			var mensagem	= xmlhttp.responseText;

			mensagem		= mensagem.replace(/\+/g," ");

			mensagem		= unescape(mensagem);

            document.getElementById('votacao').innerHTML=mensagem;

        }

    }

    //Executa

    xmlhttp.send(null)

	return false;

}
