window.defaultUrl = "";

$(function(){
	
	if(!empty(s = $(document).find("SCRIPT")))
	{
		window.defaultUrl = s.attr("src").split("js/")[0];
	}
	
	$("#conteudo form fieldset select").find("option:odd").addClass("odd");	

	$("ul li:last-child").addClass("last");
	
	$("#conteudo table tr:odd").addClass("odd");
	
	showAguarde.create();
	
	$("#activity").ajaxStart(function(){
		window.showAguarde();
	}).ajaxComplete(function(){
		window.hideAguarde();
	});
	
	if($("div.message").length > 0)
	{
		$("div.message").css({"opacity": 0.9}).hide().slideDown("normal");
		window.hideMessage = function(){ $("div.message").stop().slideUp("normal"); };
		setTimeout("window.hideMessage();", 5000);
	}
	
	$("#q,#NewsletterName,#NewsletterEmail").initValue();
	
	$.fn.normalizeHeight = function(){
		var maxHeight = 0;
		$(this).each(function(){
			maxHeight = (maxHeight > $(this).outerHeight()) ? maxHeight : $(this).outerHeight();
		}).each(function(){
			$(this).css({
				'padding-bottom': maxHeight-$(this).outerHeight()+'px'
			});
		});
	};
	
});

$(window).load(function(){
	$('#comunicacao #videos li').normalizeHeight();
	$('#comunicacao #anuncios li').normalizeHeight();
	$('#comunicacao #logotipos li').normalizeHeight();
	$('#comunicacao #clippings li').normalizeHeight();
});

$.url = function(webroot)
{
	if(!webroot)
	{
		if(window.defaultUrl.indexOf(($ext="app")) > -1)
		{
			$url = window.defaultUrl.split($ext);
			return $url[0] + "index.php?/";
		}
		
		return window.defaultUrl;
	}
	else
	{
		return window.defaultUrl;
	}
}

function showAguarde()
{
	$("#activity").remClass("disabled");
	
	//fixed activity...
	window.onscroll = showAguarde.fixed;
	window.onscroll();
	
	showAguarde.inProcess = true;	
}
showAguarde.create = function()
{
	var d = $('<div id="activity" class="disabled">Carregando Dados...</div>');
	$(document.body).append(d);
}
showAguarde.fixed = function()
{
	var a = $("#activity");
	if(!empty(a))
	{
		var y1 = document.documentElement.scrollTop || 0;
		var y2 = document.body.scrollTop || 0;
		var y3 = window.scrollY || 0;
		
		var y = Math.max(y1, Math.max(y2, y3));
			
		a.css({"top": (y + 200) + "px"});
	}
	else
	{
		window.onscroll = function(){};
		delete window.onscroll;
	}
}
showAguarde.inProcess = false;

function hideAguarde(){ $("#activity").addClass("disabled"); showAguarde.inProcess = false; }