$(document).ready(function(){

	$(".sub-menu-nav").hide();
	$(".sub-sub-menu-nav").hide();

	$("#menu-left li a:not(.sub-menu-nav li a,a[rel='no_click'])").click(function() {
		if ($("#sub" + $(this).attr("id") ).is(':visible')) { 
			$(".sub-menu-nav").hide("normal");
			$("#sub" + $(this).attr("id") ).hide("slow");
		}
		else {
			$(".sub-menu-nav").hide("normal");
			$("#sub" + $(this).attr("id") ).show("slow");
		}
		return false;
	});

	$(".sub-menu-nav li a:not(.sub-sub-menu-nav li a, a[rel='no_click'])").click(function() {
		if ($("#sub_" + $(this).attr("id") ).is(':visible')) { 
			$(".sub-sub-menu-nav").hide("normal");
			$("#sub_" + $(this).attr("id") ).hide("slow");
		}
		else {
			$(".sub-sub-menu-nav").hide("normal");
			$("#sub_" + $(this).attr("id") ).show("slow");
		}
		return false;
	});

	$(".dialog").dialog({
		autoOpen: true,
		bgiframe: true,
		resizable: false,
		height: 'auto',
		modal: true,
		buttons: {
			Fechar: function() {
				$(this).dialog('close');
			}
		}
	});

	var id_pai = "piscinas-municipais.php?header=infra-estruturas";

	
	var menu_parent = $("#sub_sub_menu_piscinas-municipais.php?header=infra-estruturas").parents();

	

	$("#submenu_" + id_pai).show();
	$("#sub_sub_menu_" + id_pai).show();
	$(menu_parent).show();
	

	
	$("a.link-fechar").click(function() {
		$('#suggestions').hide("normal");
		return false;
	});

	$("#pesquisa_q").blur(function () {
		fill();
	});

	$("#pesquisa_q").keyup(function () {
		lookup(this.value);
	});

	

	$("a.fancy").fancybox({ 
		'zoomSpeedIn': 300, 
		'zoomSpeedOut': 300, 
		'overlayShow': false,
		'zoomOpacity': true,
		'overlayShow': true,
		'overlayOpacity': 0.7,
		'frameWidth': 655,
		'frameHeight': 480,
		'padding': 0
	}); 

});

$(function(){

	$(".dialog-closed").dialog({
		autoOpen: false,
		bgiframe: true,
		resizable: false,
		height: 'auto',
		modal: true,
		buttons: {
			Fechar: function() {
				$(this).dialog('close');
			}
		}
	});

	$('#resultados_link').click(function(){
		$('#resultados-poll').dialog('open');
		return false;
	});

	$('#destaque-rotator, #images-rotate').cycle({ 
    	fx:    'fade', 
    	speed:  2500,
		timeout:  10000
 	});

});

function lookup(pesquisa_q) {
	if(pesquisa_q.length == 0) {
		$('#suggestions').hide("normal");
	} else {
		$.post("/sugestoes.php", {queryString: ""+pesquisa_q+""}, function(data){
			if(data.length >0) {
				$('#suggestions').show("normal");
				$('#autoSuggestionsList').html(data);
			}
		});
	}
} 

function fill(thisValue) {
	$('#pesquisa_q').val(thisValue);
	setTimeout("$('#suggestions').hide('normal');", 200);
}