// JavaScript Document
$(document).ready(function () {

$('.style-select').each(function() {

var selectAtual = $(this);
var selected = '';

$('.style-select').hide();
if($(selectAtual).attr('default') == ''){
	$(selectAtual).attr('default','Selecione...');
}else
	selected = 'selected';
	
var htmlSelect = '<div class="select-container">';
	htmlSelect += '    <div class="select-text '+selected+'" id="select-'+$(this).attr('list')+'">'+$(selectAtual).attr('default')+'</div><div class="select-botao" id="select-botao-'+$(this).attr('list')+'"></div>';	
	htmlSelect += '       <div id="'+$(this).attr('list')+'" class="select-list">';
	htmlSelect += '           <div id="scroll-pane-'+$(this).attr('list')+'" class="scroll-pane">';

$(this).after(htmlSelect);

$('#'+$(this).attr('id')+' option').each(function() {
	$('#scroll-pane-'+$(selectAtual).attr('list')).append('<div class="itemSelect-'+$(selectAtual).attr('list')+'" id="'+$(this).val()+'">'+$(this).text()+'</div>');									
});

$('#scroll-pane-'+$(this).attr('list')).after('</div></div></div>');

$(document).click(function(){

	$('#'+$(selectAtual).attr('list')).hide();

});

$('#select-'+$(this).attr('list')).mouseup(
	function () { 
//		alert($('#'+$(selectAtual).attr('id')+' option').length);
		if($('#'+$(selectAtual).attr('id')+' option').length > 0){
			$('#'+$(selectAtual).attr('list')).slideDown('fast');	
			$('#scroll-pane-'+$(selectAtual).attr('list')).jScrollPane({showArrows:true});	  
		}
	}
);

$('#select-botao-'+$(this).attr('list')).mouseup(
	function () { 
//			alert($('#'+$(selectAtual).attr('id')+' option').length);
		if($('#'+$(selectAtual).attr('id')+' option').length > 0){
			$('#'+$(selectAtual).attr('list')).slideDown('fast');	
			$('#scroll-pane-'+$(selectAtual).attr('list')).jScrollPane({showArrows:true});	  
		}
	}
);	

$('.itemSelect-'+$(this).attr('list')).mouseup(
	function () { 
	  var valorSelecionado = $(this).attr('id');
	  $('#select-'+$(selectAtual).attr('list')).html($(this).html());	  
      $('#'+$(selectAtual).attr('list')).hide();		  			
	  if($(selectAtual).attr('list') == 'list')
		  document.location = 'index.php?com=trabalhos&pagina=trabalhos&idClienteClassico='+this.id;	  			
	  else	  
   	      document.location = 'index.php?com=trabalhos&pagina=trabalhos&idCliente='+this.id;	  				  
	}
);

htmlSelect = '';
});

$("#frmComentario").submit(function(){

	var params = $(this.elements).serialize();

	var self = this;

	if(($('#nome').attr('value') != '')&&($('#nome').attr('value') != 'NOME*')){
	
		$.ajax({
			type: 'POST',
			url: this.action,
			data: params,
			cache: false,
			beforeSend: function(){		
			   $('#cadastroSucesso').addClass('loader-comentario');
			   $('#tdBtComentario').html('<img src="'+caminhoSite+'template/images/bt_enviar_comentario_off.gif">');			
			   
			   $("#cadastroSucesso").fadeIn("slow");		   
			},
			success: function(txt){
			   $('#cadastroSucesso').addClass('sucesso-comentario');
			   $('#tdBtComentario').html('<input type="image" src="'+caminhoSite+'template/images/bt_enviar_comentario.gif" />');		   
			   self.reset();
			},
	
			// Se acontecer algum erro é executada essa funçao
			error: function(txt){
				$('#confirmacao').html('Erro ao enviar seu coment&aacute;rio, por favor tente novamente.');
			}
		})
	
	}else{
		$('#tdFormErro').html('Preencha o campo nome.');
		$('#nome').focus();
	}
	return false;
});

$('#btVoltar').click(function(){
	document.location = caminhoSite;							  
});

$('#s1').cycle({ 
	fx: 'scrollLeft',
	before: function(){
			
	}
	
});
$('#btFale').click(function () {
		
		$('#divFale').css('display','block');
		$('#divTrabalhe').css('display','none');
		$('#btFale').attr({
				src: caminhoSite+"template/images/bt_fale_conosco_on.gif"
		});
		$('#btTrabalhe').attr({
				src: caminhoSite+"template/images/bt_trabalhe.gif"
		});
		document.frmFale.reset(); 	
		$('#areaH').attr('value','1');
		$('#trabalheConfirmacao').html('');
});

$('#btTrabalhe').click(function () {

		$('#divTrabalhe').css('display','block');
		$('#divFale').css('display','none');
		$('#btFale').attr({
				src: caminhoSite+"template/images/bt_fale_conosco.gif"
		});
		$('#btTrabalhe').attr({
				src: caminhoSite+"template/images/bt_trabalhe_on.gif"
		});
		document.frmFale.reset();
		$('#areaH').attr('value','2');
		$('#faleConfirmacao').html('');
});

$('.accordion').click(function(){
	$('.open').slideUp('normal');	
	if($('#'+this.name).css('display') == 'none'){
		$('#'+this.name).slideDown('long');
		$('#'+this.name).addClass('open');
	}else{
		$('#'+this.name).slideUp('normal');
		$('#'+this.name).removeClass('open');
	}
});

});

function trataInput(campos){
	
	var inputs = new Array({nome:'nomeF', valor:'NOME*'},{nome:'emailF', valor:'E-MAIL*'},{nome:'nomeT', valor:'NOME*'},{nome:'emailT', valor:'E-MAIL*'},{nome:'assuntoF', valor:'ASSUNTO*'},{nome:'mensagemF', valor:'MENSAGEM*'},{nome:'mensagemT', valor:'MENSAGEM*'});

	for(var i=0;i<inputs.length;i++){

		if(campos.id == inputs[i].nome){
			if(campos.value == inputs[i].valor)
				campos.value = "";			
		}
	}
	
}
function trataInputBlur(campos){
	
	var inputs = new Array({nome:'nomeF', valor:'NOME*'},{nome:'emailF', valor:'E-MAIL*'},{nome:'nomeT', valor:'NOME*'},{nome:'emailT', valor:'E-MAIL*'},{nome:'assuntoF', valor:'ASSUNTO*'},{nome:'mensagemF', valor:'MENSAGEM*'},{nome:'mensagemT', valor:'MENSAGEM*'});

	for(var i=0;i<inputs.length;i++){

		if(campos.id == inputs[i].nome){
			if(campos.value == "")
				campos.value = inputs[i].valor;
		}
	}

}

