//INICIO: Scripts gerais



$(document).ready(function() {

	iniciarLetreiro();

	iniciarMenu();

	iniciarComboBusca();
	
});



function iniciarLetreiro() {

	$("#letreiro").marquee("letreiro").mouseover(function () {

		$(this).trigger("stop");

	}).mouseout(function () {

		$(this).trigger("start");

	}).mousemove(function (event) {

		if ($(this).data("drag") == true) {

			this.scrollLeft = $(this).data("scrollX") + ($(this).data("x") - event.clientX);

		}

	}).mousedown(function (event) {

		$(this).data("drag", true).data("x", event.clientX).data("scrollX", this.scrollLeft);

	}).mouseup(function () {

		$(this).data("drag", false);

	});

}



function iniciarMenu() {

	$(".cabecalho .menu").mouseenter(function(){

		$(this).stop().animate({ height: "192px" }, { queue:false, duration:600 });

		$(this).find(".limitador .areas li").stop().animate({opacity: 0.0}, {queue:true, duration: 1}).each(function(i){

			$(this).animate({opacity: 1.0}, {queue:true, duration: (100*(i+1))});

		});

		

	}).mouseleave(function(){

		$(this).stop().animate({ height: "27px" }, { queue:false, duration:200 });

		$(this).find(".limitador .areas li").stop().each(function(i){

			$(this).animate({opacity: 0.0}, {queue:true, duration: 1});

		});

	});

}



function iniciarComboBusca() {

	$(".portais").selectable({

		selecting: function() {

			$(".portais").selectable("disable");

			$(".portais").fadeOut("fast", function(){$(".portais").selectable("enable");});

		},

		stop: function(){

			$(".ui-selected", this).each(function(){

				var index = $(".portais li").index(this);

				$("#txtPortal").val(index + 1);

				$(".selecionado").html($(this).html());

			});

		}

	});

	

	$(".selecionado").click(function(){$(".portais").fadeIn();document.getElementById("busca").style.zIndex='100';document.getElementById("usabilidade").style.zIndex='99';})

	$(".seletor").mouseleave(function(){$(".portais").fadeOut("fast");document.getElementById("usabilidade").style.zIndex='100';document.getElementById("busca").style.zIndex='99';});

	

	var valorPadraoBusca = $(".txtBusca").val();

	

	$(".txtBusca").focus(function(){

		if($(this).val() == valorPadraoBusca){

			$(this).val("");	

		}

	}).blur(function(){

		if($(this).val().length == 0){

			$(this).val(valorPadraoBusca);

		}

	});

}



function iniciarCalendario() {

	$("#datepicker").datepicker({ 

		monthNames: ['Janeiro', 'Fevereiro', 'Mar&ccedil;o', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'],

		monthNamesShort: ['Jan', 'Fev', 'Mar', 'Abril', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez'],

		dayNames: ['Domingo', 'Segunda', 'Ter&Ccedil;a', 'Quarta', 'Quinta', 'Sexta', 'S&aacute;bado'],

		dayNamesMin: ['D', 'S', 'T', 'Q', 'Q', 'S', 'S'] 

	});

}

function sumirLegendaCampo(strcomp, campo) {
    if(campo.value == strcomp) {
        campo.value = "";
    }
}

function aparecerLegenda(strval, campo) {
    if(!campo.value) {
        campo.value = strval;
    }
}

function trim(str){
    return str.replace(/^\s+|\s+$/g,"");
}


//FIM: Scripts gerais
