/*--------------------------------------------------------------------
JAVASCRIPT "usados ao longo do site" 

Version: 	2.0 - 2009/2010
author: 	Burocratik (alexandre gomes)
email: 		alex@burocratik.com
website: 	http://www.burocratik.com
-----------------------------------------------------------------------*/
/* =Open new window e Mandar Imprimir
-----------------------------------------------------------------------*/
$(document).ready(function(){
  //Open new window
  $("a[rel=external]").click(function(){
    var linkExterno = window.open($(this).attr("href"));
    return linkExterno.closed;
  });
	//Mandar Imprimir
  $("a[rel=print]").click(function(){
    var imprimir = window.print();
    return false;
  });
})
/*-----------------------------------------------------------------------
 =LIMPAR FORMULARIOS
So limpa nos forms os Input Text com class txtLimpar
-----------------------------------------------------------------------*/
$(document).ready(function() {
  $('input[type=text]').each(function() {
		if(!$(this).hasClass("textLimpar")) return;  //se nao tem a class sai
		var defeito = this.defaultValue; //this pois defaultValue é propriedade de javascript e nao jquery
		$(this).focus(function() {
			if($(this).val() == defeito) {$(this).val("")}
		});
		$(this).blur(function() {
			if($(this).val() == "") {$(this).val(defeito)
			}
		});

	});
});
/*-----------------------------------------------------------------------
=Inserir E-mails correctos: Obrigatorio class="email", e [-at-]
-----------------------------------------------------------------------*/
 $(document).ready(function(){
   $("a.email").each(function(){
     var mailReal = $(this).text().replace("[-at-]","@");
		 $(this).text(mailReal);
     $(this).attr("href", "mailto:"+mailReal);
	 })
 })

/*-----------------------------------------------------------------------
=Menu de Navegação
-----------------------------------------------------------------------*/
 $(document).ready(function(){
 	$("ul#navMain span").css("opacity","0"); //todos os span com opacidade zero
  $("ul#navMain span").css("left","0"); //todos na posição correcta
	$("ul#navMain span").hover(function () {
		$(this).stop().animate({opacity: 1}, "fast");
		},
		function () {
			$(this).stop().animate({opacity: 0}, "normal");
	});
 })

/*-----------------------------------------------------------------------
=Acordeao para lista definicao dl
-----------------------------------------------------------------------*/
 $(document).ready(function(){
   $(".acordeao dd").hide();
   $(".acordeao dt").click(function(){
   	 $(this).next().slideToggle("normal");
		 $(this).toggleClass("on");
   	 return false;
   });
 })

/*-----------------------------------------------------------------------
=Acordeao Normal = slide
-----------------------------------------------------------------------*/
 $(document).ready(function(){
   $(".slide").each(function(){
   	$(this).next().hide().css({overflow:"auto"});
   	if($(this).next().hasClass("show")){$(this).next().show(); $(this).addClass("slideon");}
	 });
   $(".slide").click(function(){
   	 $(this).next().slideToggle("normal");
		 $(this).toggleClass("slideon");
   	 return false;
   });
 })

/*-----------------------------------------------------------------------
=Acordeao tipo read more (abre e fecha o tag a frente)
NOTA: o txt tem de estar dentro de um tag (por exemplo span dentro de um p) e o proximo elemento tem de ter class open more
-----------------------------------------------------------------------*/
 $(document).ready(function(){
   $(".txtMore").hide();
   $(".openMore").click(function(){
   	 $(this).parent().next().slideToggle("normal");
		 $(this).toggleClass("on");
     $(this).hasClass("on") ?  $(this).text("[-]") : $(this).text("[+]");
   	 return false;
   });
 })


/*-----------------------------------------------------------------------
 =OVERLAY - LIGHTBOX
 NOTAS: tentei usar png transp mas flipa np ie7
-----------------------------------------------------------------------*/
var W3CDOM = (document.getElementsByTagName && document.createElement);
if (W3CDOM){
	var link = document.createElement('link');
	link.setAttribute("rel", "stylesheet");
	link.setAttribute("type", "text/css");
	link.setAttribute("href", "/scripts/javascript-corpo.css");
	link.setAttribute("media", "screen");
	document.getElementsByTagName("head")[0].appendChild(link);
}
//Função que determina a altura do Documento
(function($){
	$.getDocHeight = function(){
    return Math.max($(document).height(),$(window).height());
	};
})(jQuery);
//Função que determina o comprimento do Documento
(function($){
	$.getDocWidth = function(){
    return Math.max($(document).width(),$(window).width());
	};
})(jQuery);
//Funcao que posiciona segundo X a overlay box
function fPosicaoX(destino){
	var largStage = $.getDocWidth();
	var posicaoX = largStage/2-($(".overlayBox").width()/2);
	if($.browser.msie && $.browser.version<"9.0"){ /* IE-jQuery Cleartype glitch by Ben Novakovic*/
		$(destino).css({display:"block", left:posicaoX}).fadeTo(300,1,function() {this.style.removeAttribute('filter');});
	}else{
   	$(destino).css({display:"block", left:posicaoX}).fadeTo(300,1);
	}
}
//Funcao que tira os elementos do stage
function fTira(){
	$(".overlay").fadeTo(0,0).hide();
  $(".overlayBox").fadeTo(0,0).hide();
  $(window).unbind("resize"); //tirar o evento do resize
}
/////////
$(document).ready(function(){
  //iniciar objectos
 	$(".overlay").fadeTo(0,0);
  $(".overlayBox").fadeTo(0,0);
 //	$(".overlayBox").style.removeAttribute('filter');
	// Botoes
  $(".btOverlay").click(function(){
    var qualID = $(this).attr("href").replace("#","");//replace is javascript method;
		var destino = $("div#"+qualID+"");
		//fundo
		var alturaStage = $.getDocHeight();
		$(".overlay").css({height:alturaStage,display:"block"}).fadeTo(300,.9)
    //Interior e resize da janela
    fPosicaoX(destino);
    $(window).bind("resize", function(){
  		fPosicaoX(destino);
		});
  })
  $(".overlay").click(function(){fTira();})
  $(".btClose").click(function(){fTira();})
})
/*-----------------------------------------------------------------------
 =OVERLAY - LIGHTBOX Fotos (uso 2 imgs (loading e holder) para nao ter flicker)
-----------------------------------------------------------------------*/
function fPosicaoIni(){
	var largStage = $.getDocWidth();
	var posicaoX = largStage/2-($(".overlayBoxP").width()/2);
 	$(".overlayBoxP").css({display:"block", left:posicaoX}).fadeTo(200,1);
}
//Funcao que tira os elementos do stage
function fTiraP(){
  $(".overlayP").fadeTo(0,0).css("display", "none");
 	$(".overlayBoxP").fadeTo(0,0).css({width:"150px", height:"150px", display:"none"});
	$("#placeholder").fadeTo(0,0);
  $(".overlayBoxP .btClose span").css("display", "none");
}
$(document).ready(function(){
  //iniciar objectos
 	$(".overlayP").fadeTo(0,0);
  $(".overlayBoxP").fadeTo(0,0);
	$("#placeholder").fadeTo(0,0);
	var picLoad = $("#placeholder").attr("src");
  // Botoes
  $(".btPic").click(function(){
		var picNova = $(this).attr("href");
		//fundo
		var alturaStage = $.getDocHeight();
		$(".overlayP").css({height:alturaStage,display:"block"}).fadeTo(300,.9)
    fPosicaoIni()
    //LOADING novas fotos
   	var lerImg = new Image();
		lerImg.onload = function(){
		 lerImg.onload = null;
		 $("#placeholder").attr("src", lerImg.src);
		 var comP = $("#placeholder").width();
		 var altP = $("#placeholder").height()+25;
     var posicaoXnew = $.getDocWidth()/2-(comP/2);
     $(".overlayBoxP").css({width:comP, height:altP, left:posicaoXnew});
		 $("#placeholder").fadeTo(250,1);
		 $(".overlayBoxP .btClose span").css("display", "block");
		}
		lerImg.src = picNova;
		return false;
  })
 	$(".overlayP").click(function(){fTiraP();})
 	$(".overlayBoxP .btClose").click(function(){fTiraP();})
})
/*-----------------------------------------------------------------------
 =OVERLAY - LIGHTBOX VIDEO
-----------------------------------------------------------------------*/
//Funcao que tira os elementos do stage
function fTiraV(){
	$(".overlay").fadeTo(0,0).hide();
  $(".overlayBoxV").fadeTo(0,0).hide();
  $('#video1').load("/static/scripts/video-dummy.html");
}
/////////
$(document).ready(function(){
  //iniciar objectos
 	//$(".overlay").fadeTo(0,0).hide();  //ja feito em cima
  $(".overlayBoxV").fadeTo(0,0).hide();
	// Botoes
  $(".btOverlayV").click(function(){
    var qualURL = $(this).attr("href");
		//fundo
		var alturaStage = $.getDocHeight();
		$(".overlay").css({height:alturaStage,display:"block"}).fadeTo(300,.90);
    //Interior e resize da janela
		$('#video1').load(qualURL, function(){
    	var comV = $("#video").width();
			var altV = $("#video").height();
    	var posicaoXnew = $.getDocWidth()/2-(comV/2);
    	$(".overlayBoxV").css({width:comV, height:altV, left:posicaoXnew, display:"block"}).fadeTo(0,1);
		});
  	return false;
	})
	//
  $(".overlay").click(function(){fTiraV();})
  $(".btClose").click(function(){fTiraV();})
})
