/**
 * @author Jos� Orlando Sousa (joseorlandosousa@gmail.com)
 */
$(document).ready(function(){
	
	$('.round').css({position: "relative"});
	$('.round').append('<img src="/auriverde.am.br/img/layout/canto-te.gif" title="" style="position:absolute; top:-1px; left:-1px; border:0" alt="" />');
	$('.round').append('<img src="/auriverde.am.br/img/layout/canto-td.gif" title="" style="position:absolute; top:-1px; right:-1px; border:0" alt="" />');
	$('.round').append('<img src="/auriverde.am.br/img/layout/canto-be.gif" title="" style="position:absolute; bottom:-1px; left:-1px; border:0" alt="" />');
	$('.round').append('<img src="/auriverde.am.br/img/layout/canto-bd.gif" title="" style="position:absolute; bottom:-1px; right:-1px; border:0" alt="" />');
	
	
	$("#destaques a.aba").click( function(){
		$("#destaques").slideUp({ 
			duration: 1000, 
			easing: "easeOutBounce", 
			complete: $("a#aba-mostra-destaque").slideDown("slow")
		});	
		$.cookie('DestaquesStatus', 'desativado', {path: '/auriverde.am.br/', expires: 7 });	
	});
	$("a#aba-mostra-destaque").click( function(){
		$("#destaques").slideDown({ 
			duration: 1000, 
			easing: "easeOutBounce", 
			complete: $("a#aba-mostra-destaque").slideUp("slow")
		});
		$.cookie('DestaquesStatus', 'ativo', {path: '/auriverde.am.br/', expires: 7 });	
	});
	
	if($.cookie('DestaquesStatus')=="desativado"){
		$("#destaques").hide();
		$("a#aba-mostra-destaque").slideDown("slow");
	}
	
	$(".semRegistro").css({opacity: "0.3"});
	
// 
// # Win
//
//	
	$("a[class*='win']").click(function(){		
		
		var pagina 		= $(this).attr("href");
		
		var tamanhos 	= $(this).attr("rel");
		var tamanho  	= tamanhos.split(",");
		
		var width		= tamanho[0];
		var height		= tamanho[1];
		
		var arrPageSizes = ___getPageSize();
		 var Load = '<img src="images/lightbox-ico-loading.gif" alt="carregando" />';
		 
		 var fechar = '<a href="javascript:fechar()" title="Fechar" id="btnFechar" style="margin:-'+ (height/2+24) +'px 0 0 '+ (width/2-16) +'px"></a>';
		 
		$('body').append('<div id="box-fundo"></div><div id="box"></div>');	
		
		$('#box-fundo').css({
			backgroundColor:	"#000",
			opacity:			"0.8",
			width:				arrPageSizes[0],
			height:				arrPageSizes[1]
		}).fadeIn();
		$('#box').css({
			backgroundColor:	"#fff",
			border:				"4px solid #ccc",
			width:				width+"px",
			height:				height+"px",
			marginTop:			"-"+(height/2)+"px",
			marginLeft:		"-"+(width/2)+"px"
			
		}).slideDown({duration: 1000,easing: "easeOutBounce"});
		
		$('#box-fundo').click(function(){
			$(this).fadeOut({ 
				duration: 1000, 
				complete: $('#box').slideUp({duration: 1000,easing: "easeOutBounce",complete: $('#box-fundo', this).remove()  })
			})
		});

		$.ajax({
	            type: 'POST',// Usando metodo Post
	            url: pagina, // this.action pega o script para onde vai ser enviado os dados
	            data: "ajax=ok", // os dados que pegamos com a fun��o serialize()
				
	            beforeSend: function(){// Antes de enviar
					$('#box').html(Load);
					$('#box').append(fechar);	
	            },
	            success: function(data){
	            	$('#box').html(data);// Escrevo a mensagem
	            	$('#box').append(fechar);	
	            },
	            error: function(data){// Se acontecer algum erro � executada essa fun��o
	                $('#box').html("<h1>Erro 404: A p�gina solicitada n�o foi econtrada</h1>");
					$('#box').append(fechar);	
	            }
	        })
			
		
		return false;
	});//fim
	
	$("a.ajax").click(function(){		
		var caminho 	= $(this).attr("rel");
		var Load = '<img src="/site/images/lightbox-ico-loading.gif" alt="carregando" />';
		$.ajax({
	            type: 'POST',// Usando metodo Post
	            url: $(this).attr("href"), // this.action pega o script para onde vai ser enviado os dados
	            data: "ajax=ok", // os dados que pegamos com a fun��o serialize()
	
	            beforeSend: function(){// Antes de enviar
					$('#'+caminho).html(Load);
					$('#'+caminho).append(fechar);	
	            },
	            success: function(data){
	            	$('#'+caminho).html(data);// Escrevo a mensagem
	            	$('#'+caminho).append(fechar);	
	            },
	            error: function(data){// Se acontecer algum erro � executada essa fun��o
	                $('#'+caminho).html("<h1>Erro 404: A p�gina solicitada n�o foi econtrada</h1>");
					$('#'+caminho).append(fechar);	
	            }
	        });
			return false;
	});
	
	
});
function fechar (){
	$('#box-fundo').fadeOut({ 
		duration: 1000, 
		complete: $('#box').slideUp({duration: 1000,easing: "easeOutBounce",complete: $('#box-fundo', this).remove()  })
	})
}
// => MENU DROPDOWN
var obj = null;

function checkHover() {
    if (obj) {
        obj.find('ul').fadeOut('fast');    
    }
}

$(document).ready(function() {
    $('#menu ul.menu > li').hover(function() {
        if (obj) {
            obj.find('ul').fadeOut("fast").css({"z-index": 0});
            obj = null;
        } //if
        
        $(this).find('ul').fadeIn("slow").css({"z-index": 100});
    }, function() {
        obj = $(this);
        setTimeout(
            "checkHover()",
            400);
    });
});

function Fonte(Classe, TIPO){
	
	var tamanho = $('.'+Classe).css("fontSize");
	var TamanhoAtual = new Number(tamanho.replace(/px/, ""));
	var menos =TamanhoAtual-1;
	var mais =TamanhoAtual+1;
	
	if(TIPO == "menor"){
		$('.'+Classe).css({ fontSize:menos});
	}
	if(TIPO == "normal"){
		$('.'+Classe).css({ fontSize:"12px"});
	}
	if(TIPO == "maior"){
		$('.'+Classe).css({ fontSize:mais});
	}
}



/**
		 / THIRD FUNCTION
		 * getPageSize() by quirksmode.com
		 *
		 * @return Array Return an array with page width, height and window width, height
		 */
		function ___getPageSize() {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		};