$(document).ready(function() {		
	$('#slideshow').cycle({
		fx:      'scrollLeft',
		speed:    200,
		timeout:  7000
	});
	
	$("ul.subnav").parent().append("<span class='sub'></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)
	
	$("ul.topnav li span.sub").click(function() { //When trigger is clicked...
	
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
		$(this).find("img").attr("src",$(this).find("img").attr("src").replace("out","over"));
				
		$(this).parent().hover(function() {
			}, function(){
				$(this).parent().find("ul.subnav").slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
				$(this).find("img").attr("src",$(this).find("img").attr("src").replace("over","out"));
		});
		
	//Following events are applied to the trigger (Hover events for the trigger)
	}).hover(function() {
		$(this).parent().addClass("ativo");
		$(this).addClass("subhover"); //On hover over, add class "subhover"
		$(this).find("img").attr("src",$(this).find("img").attr("src").replace("out","over"));
	}, function(){	//On Hover Out
		$(this).find("img").attr("src",$(this).find("img").attr("src").replace("over","out"));
		$(this).removeClass("subhover"); //On hover out, remove class "subhover"
		$(this).parent().removeClass("ativo");
		$(this).parent().removeClass("clicado");
	});
	
	$("ul.topnav li span.lnkMenu").click(function() { //When trigger is clicked...
	
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
		$(this).find("img").attr("src",$(this).find("img").attr("src").replace("out","over"));
		$(this).parent().addClass("clicado");
		$(this).parent().hover(function() {
			}, function(){
				$(this).parent().find("ul.subnav").slideUp('fast'); //When the mouse hovers out of the subnav, move it back up
				$(this).find("img").attr("src",$(this).find("img").attr("src").replace("over","out"));
		});
		
	//Following events are applied to the trigger (Hover events for the trigger)
	}).hover(function() {
		$(this).parent().addClass("ativo");
		$(this).addClass("subhover"); //On hover over, add class "subhover"
		$(this).find("img").attr("src",$(this).find("img").attr("src").replace("out","over"));
	}, function(){	//On Hover Out
		if (!$(this).parent().hasClass("clicado"))
		{
			$(this).find("img").attr("src",$(this).find("img").attr("src").replace("over","out"));						
		}
		$(this).removeClass("subhover"); //On hover out, remove class "subhover"
		$(this).parent().removeClass("ativo");
	});
	
	function submit_enter(myfield,e)
	{
		var keycode;
		if (window.event) keycode = window.event.keyCode;
		else if (e) keycode = e.which;
		else return true;
		
	    if (keycode == 13)
	    {
		    myfield.form.submit();
		    return false;
	    }
		else
			return true;
	}
	
	function limpa_busca()
	{
		$("#s").val("");		
	}
	
	function escreve_busca()
	{
		$("#s").val("O que você procura?");		
	}

	
});


