window.defaultUrl = "";

$(function(){
	
	if(!empty(s = $(document).find("SCRIPT")))
	{
		window.defaultUrl = s.get(0).src.toString().split("js/")[0];
	}
	
	if(typeof Flash != "undefined")
	{
		$("head").append("<script type='text/javascript' src='" + window.defaultUrl + "js/jquery/jquery.flashtag.js'></script>");
	}
	
	var a = document.links;
	for(var i=0; i<a.length; i++)
	{
		if(a[i].rel && a[i].rel == "thumb")
		{
			a[i].onclick = ampliaHandler;
		}
	}	
	
	showAguarde.create();
	
	$("#activity").ajaxStart(function(){
		window.showAguarde();
	}).ajaxStop(function(){
		window.hideAguarde();
	}).ajaxComplete(function(){
		window.hideAguarde();
	});

	$("#conteudo form fieldset select").find("option:odd").addClass("odd");
	
	writeSWFs();
	
	if($("#ultimos-eventos").length > 0)
	{
		$("#ultimos-eventos").find("a img").load(function(){
			var $height_img = $(this).height();
			var $height_a = $(this).parent().height();
			if($height_img >= $height_a)
			{
				var $marginTop = parseInt((diff=($height_img - $height_a)) / 3.5) * -1;
				$(this).animate({
					"marginTop": $marginTop + "px"
				}, 1200);
			}
			else
			{
				$(this).height($height_a);
			}
		});
	}
	
});

$(window).load(function(){
	if($("#ultimos-eventos").length > 0)
	{	
		$("#ultimos-eventos").find("a img").trigger("load");
	}
});

$.url = function(webroot)
{
	if(!webroot)
	{
		return window.defaultUrl;
	}
}

function ampliaHandler()
{	
	ampliarImg(this.href.toString());
	return false;
}

function ampliarImg(src)
{
	window.open(window.defaultUrl + "show/?src=" + src, "aw", "width=200, height=200,resizable=yes, status");
}

function writeSWFs()
{
	$("#conteudo h2.titulo").each(function(){
		$(this).flash({
			url: window.defaultUrl + "swf/titulo.swf",
			width: "100%",
			height: "100%",
			wmode: "transparent",
			variables: {
				"titulo": $(this).html()
			}
		});
	});
}

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; }