jQuery(function(){
	Cufon('.headerNav ul li a',{
		hover: {color: '#ABA5C0'}
	});
	Cufon.replace('.fonte',{fontFamily: 'Verdana' });
	
	$(".tabAbrangencia tbody tr:odd").addClass("corLinha");
	jQuery('#btnReset').click(function () { 
		jQuery('form')[0].reset();
	});
	
	jQuery(".listaStyle03 dd:last").css("border","none");
	
	//CONTENT lINK
	jQuery(".navContHome ul li,.listaStyle01 ul li,.listaStyle02 ul li,.listaStyle05 ul li").click(function(){
    	window.location=jQuery(this).find("a").attr("href");return false;
	});
	
	//SELECT
	jQuery(".select input").focus(function(){
		var pic = jQuery(this);
		pic.removeAttr("width");
		var wOpt = pic.width()+36;
		var numOpt = jQuery(this).next().next().children("li").length;
		jQuery(".select ul").hide();
		jQuery(this).attr("readonly", "readonly");
		jQuery(this).attr("autocomplete", "off");
		if(numOpt > 7){
			jQuery(this).next().next("ul").attr({style: "width:"+wOpt+"px;height:"+160+"px;overflow:auto;display:block;"});
			return false;
		}else{
			jQuery(this).next().next("ul").attr({style: "width:"+wOpt+"px;display:block;"});
			return false;
		}
	});
	
	var maskHeight = jQuery(document).height();
	var maskWidth = jQuery(window).width();
	jQuery(".fundoModal").css({'width':maskWidth,'height':maskHeight});
		
	jQuery(".abre_modalV").click(function(){
		jQuery(".fundoModal").fadeIn();	
		jQuery(".fundoModal").fadeTo("slow",0.5);
		
		jQuery(".areaModalV").fadeIn();	
			jQuery(".fechaModal, .fundoModal").click(function(){
			jQuery(".areaModalV, .fundoModal").fadeOut();	
				});
			
	});
	jQuery(".abre_modalA").click(function(){
		jQuery(".fundoModal").fadeIn();	
		jQuery(".fundoModal").fadeTo("slow",0.5);
		
		jQuery(".areaModalA").fadeIn("fast");
				
			jQuery(".fechaModal, .fundoModal").click(function(){
				jQuery(".areaModalA, .fundoModal").fadeOut();	
				});
			
	});
	
	
	jQuery(".select").click(function(){
		if(jQuery(this).find('ul').is(':hidden')){
			var pic = jQuery(this).find('input');
			pic.removeAttr("width");
			var wOpt = pic.width()+36;
			var numOpt = pic.next().next().children("li").length;
			jQuery(".select ul").hide();
			pic.attr("readonly", "readonly");
			pic.attr("autocomplete", "off");
			if(numOpt > 7){
				pic.next().next("ul").attr({style: "width:"+wOpt+"px;height:"+160+"px;overflow:auto;display:block;"});
				return false;
			}else{
				pic.next().next("ul").attr({style: "width:"+wOpt+"px;display:block;"});
				return false;
			}
		}
		else{
			jQuery(this).find('ul').fadeOut();
		}
		//return false;
	});
	
	
	jQuery(".select input").click(function(){
		return false;
	});
	/*jQuery("div.select").click(function(){
		if((jQuery(this).children("ul").css('display') == 'none')){
			jQuery(this).children("input").focus();
		}else{
			jQuery(".select ul").fadeOut();
		}
		return false;
	});*/
	jQuery(".select ul li a").click(function(){
		var value = jQuery(this).text();
		var valueReal = jQuery(this).attr("rel");
		jQuery(this).parent().parent().prev().prev().val(value);
		jQuery(this).parent().parent().next().val(valueReal);
	});
	jQuery(".select input").blur(function(){
		jQuery(".select ul").fadeOut();
	});
	
	//SELECT
	//SELECT FILTRO
	/*jQuery(".selectFiltro input").click(function(){
		var pic = jQuery(this);
		pic.removeAttr("width");
		var wOpt = pic.width()+36;
		var numOpt = jQuery(this).next().next().children("li").length;
		jQuery(".selectFiltro ul").hide();
		jQuery(this).attr("readonly", "readonly");
		jQuery(this).attr("autocomplete", "off");
		if(numOpt > 7){
			jQuery(this).next().next("ul").attr({style: "width:"+wOpt+"px;height:"+160+"px;overflow:auto;display:block;"});
			return false;
		}else{
			jQuery(this).next().next("ul").attr({style: "width:"+wOpt+"px;display:block;"});
			return false;
		}
		return false;
	});*/
	jQuery(".selectFiltro").click(function(){
		var pic = jQuery(this).find('input');
		pic.removeAttr("width");
		var wOpt = pic.width()+36;
		var numOpt = pic.next().next().children("li").length;
		jQuery(".selectFiltro ul").hide();
		pic.attr("readonly", "readonly");
		pic.attr("autocomplete", "off");
		if(numOpt > 7){
			pic.next().next("ul").attr({style: "width:"+wOpt+"px;height:"+160+"px;overflow:auto;display:block;"});
			//return false;
		}else{
			jQuery(this).next().next("ul").attr({style: "width:"+wOpt+"px;display:block;"});
			//return false;
		}
		//return false;
	});
	
	
	//SELECT FILTRO
	
	jQuery(".fechaModal,.mask,.areaModal,.areaModalEnquetes").click(function(){
		jQuery(".mask,.areaModal,.areaModalEnquetes").fadeOut("fast");
	});
	jQuery(".modal").click(function(){
		return false;
	});
	
	$('html').keypress(function(event) {
		if (event.keyCode == '13') {
			if($(".mask").css("display") == "block"){
				$(".mask,.mask02,.areaModal,.areaModalEnquetes").hide();
				$(".areaModal,.areaModal02").css({position: "fixed"});
				$('.btnHome').focus();
				return false;
			}
		}
	});
	
	
	
	/*jQuery("html").click(function(){
		jQuery(".select ul, .selectFiltro ul").fadeOut();
	});*/
	
	jQuery(document).click(function(event) {
		if (!jQuery(event.target).closest('.select').length) {
			jQuery('.select ul').hide();
		};
		if (!jQuery(event.target).closest('.selectFiltro').length) {
			jQuery('.selectFiltro ul').hide();
		};
	});
	
	
});

