﻿/*--------------------------------------------------------------------
JAVASCRIPT  "usados ao longo do site Litocar"

Version: 	1.0 - 2011
author: 	Burocratik
email: 		alex@burocratik.com
			ana@burocratik.com
website: 	http://www.burocratik.com
-----------------------------------------------------------------------*/
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);

/* =Open new window e Mandar Imprimir
-----------------------------------------------------------------------*/
$(document).ready(function(){
  //IE6
  if($.browser.msie && $.browser.version<"7.0"){window.top.location = "http://burocratik.com/error/ie6-please-no.html";}
  //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() {
    var aux = $(this).attr("class");
		if(aux != "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);
	 })
 })
 
/*-----------------------------------------------------------------------
 =NEWSLETTER VALIDACAO: based on: Adrian Gondelle & Ivan Castro
-----------------------------------------------------------------------*/
$(document).ready(function(){
 	$(".erroMail").fadeTo(0,0).hide();
	if($.browser.msie && $.browser.version<"9.0")$(".erroMail").css("background-color", "white");
	//
	var form = $("#formNewsletter");
	var email = $("#befl-befl");
	//
	email.blur(validateEmail);
	//On Submitting
	form.submit(function(){
		if(validateEmail())
			return true;
		else
		  return false;
	});
	//
	function validateEmail(){
		var a = $("#befl-befl").val();
		var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
		if(filter.test(a)){
			$(".erroMail").fadeTo(200,0);
			email.removeClass("erro");
			return true;
		}
		else{
			$(".erroMail").fadeTo(300,1).show();
			email.addClass("erro");
			return false;
		}
	}
})

/*-----------------------------------------------------------------------
 =OVERLAY - LIGHTBOX
 NOTAS: tentei usar png transp mas flipa np ie7
-----------------------------------------------------------------------*/


//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).hide(); ;
  	$(".overlayBox").fadeTo(0,0).hide(); ;
 	//	$(".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(){
  	$(".overlay").fadeTo(0,0).hide();
 	$(".overlayBoxP").fadeTo(0,0).css({width:"150px", height:"150px", display:"none"});
	$("#placeholder").fadeTo(0,0);
}
$(document).ready(function(){
  	//iniciar objectos
 	//$(".overlay").fadeTo(0,0).hide();  //ja feito em cima
  	$(".overlayBoxP").fadeTo(0,0).hide();
	$("#placeholder").fadeTo(0,0);
	var picLoad = $("#placeholder").attr("src");
  	// Botoes
  	$(".btPic").click(function(){
		var picNova = $(this).attr("href");
		//fundo
		var alturaStage = $.getDocHeight();
		$(".overlay").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();
     var posicaoXnew = $.getDocWidth()/2-(comP/2);
     $(".overlayBoxP").css({width:comP, height:altP, left:posicaoXnew});
		 $("#placeholder").fadeTo(250,1);
		}
		lerImg.src = picNova;
		return false;
  })
 	$(".overlay").click(function(){fTiraP();})
 	$(".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("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();})
})

/*-----------------------------------------------------------------------
 =Sliders
-----------------------------------------------------------------------*/
$(document).ready(function(){	
	$("#destaque div").easySlider({controlsShow: false, auto: true, continuous: true, pause: 7000});
	$("#slider").easySlider({numeric: true,	numericId: "controls01"});
	$("#slider02").easySlider({numeric: true, numericId: "controls02"});
	$("#slider03").easySlider({numeric: true, numericId: "controls03"});
	$("#slider04").easySlider({numeric: true, numericId: "controls04"});
	$("#noticias").easySlider({numeric: true, numericId: "controls05"});
	$("#sliderEmp").easySlider({numeric: true, numericId: "controlsEmp"});

	$("#formulario").hide(); 
	$("#marcacao h4").click(function () {
		$("#formulario").fadeIn(500);
	});
	$("#marcacao .btClose").click(function () {
		$(this).parent().fadeOut(500);
	});
});

/*-----------------------------------------------------------------------
 =Marcas
-----------------------------------------------------------------------*/
$(document).ready(function(){	
	$("ul ul").hide();
	$("#contentTop h4").click(function () {
    	$(this).next("ul").slideToggle("fast");
		$(this).toggleClass("on");
    });
	
	$("ul li.current h4").addClass("active").next("ul").show();
})

/*-----------------------------------------------------------------------
 =Marcas - Lista
-----------------------------------------------------------------------*/
$(document).ready(function(){
	$("dl ul li").hover(
	function(){
	if($(this).hasClass("active")){
	} else {
		$(this).children("div").show();
		$(this).css("z-index", "50");
		}
	},
	function(){
		if($(this).hasClass("active")){
		} else {
		$(this).children("div").hide();
		$(this).css("z-index", "0");
		}
	});
	
	$("dl ul li .btClose").click(function () {
    	$(this).parent().removeClass("active");
		$(this).hide();
    });
	
	
	$("dl dt:nth-child(1), dl dd:nth-child(2)").css("border-top", "none");
	
	
});
	
/*-----------------------------------------------------------------------
 =Serviços - Lista
-----------------------------------------------------------------------*/
// Check: http://css-tricks.com/equal-height-blocks-in-rows/

$(document).ready(function(){	

	var currentTallest = 0,
	currentRowStart = 0,
	rowDivs = new Array(),
	$el,
	topPosition = 0;
	
	$('#contentMain .bloco').each(function() {
	$el = $(this);
	topPostion = $el.position().top;
	
	if (currentRowStart != topPostion) {
		for (currentDiv = 0; currentDiv < rowDivs.length ; currentDiv++) {
			rowDivs[currentDiv].height(currentTallest);
		}
		rowDivs.length = 0; 
		currentRowStart = topPostion;
		currentTallest = $el.height();
		rowDivs.push($el);
	} else {
		rowDivs.push($el);
		currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest);
	}
	for (currentDiv = 0; currentDiv < rowDivs.length ; currentDiv++){
		rowDivs[currentDiv].height(currentTallest);
		
		}
	});
	
	$("#servicos #contentMain .bloco:nth-child(odd)").addClass("esq");
	$("#servicos #contentMain .bloco:nth-child(1), #servicos #contentMain .bloco:nth-child(2)").addClass("first");
	

/* LINK FORMULÁRIO */
	$("span.link").click(function () {
		$("p.info").toggleClass('off');
		$("div.switch").slideToggle(300);
	});
	
/* LINK CONTACTOS 	*/
	$(".contactos span.link").click(function () {
		$("#formContacto").slideDown(300);
		$("span.link").addClass("linkOn");
		$("span.linkOn").removeClass("link").parent().addClass("on");
		$("span.btClose").fadeIn("fast");
	});
	$(".contactos span.btClose").click(function () {
		$("#formContacto").slideUp(300);
		$("span.linkOn").addClass("link").parent().removeClass("on");
		$("span.link").removeClass("linkOn");
		$("span.btClose").fadeOut("fast");		
	});


/* BLOCO COM LINK */
	$("#contentMain .blocoLink").hover(
		function () {$(this).children(".pBottom").addClass("spot");},
		function () {$(this).children(".pBottom").removeClass("spot");}
	);
	
	
	
	
	
	

	
});





/*-----------------------------------------------------------------------
 =DESTAQUE - Canto Superior Direito
-----------------------------------------------------------------------*/
/**
 * @author Alexander Farkas
 * v. 1.02
 */
(function($) {
	$.extend($.fx.step,{
		backgroundPosition: function(fx) {
			if (fx.state === 0 && typeof fx.end == 'string') {
				var start = $.curCSS(fx.elem,'backgroundPosition');
				start = toArray(start);
				fx.start = [start[0],start[2]];
				var end = toArray(fx.end);
				fx.end = [end[0],end[2]];
				fx.unit = [end[1],end[3]];
			}
			var nowPosX = [];
			nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
			nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
			fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

		   function toArray(strg){
			   strg = strg.replace(/left|top/g,'0px');
			   strg = strg.replace(/right|bottom/g,'100%');
			   strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
			   var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
			   return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
		   }
		}
	});
})(jQuery);

$(document).ready(function(){
$('.usados100')
.css( {backgroundPosition: "5px -5px"} )
$('.usados100 a')
.mouseover(function(){
	$(this).parent().stop().animate(
		{backgroundPosition:"(0 0)"}, 
		{duration:100})
	})
.mouseout(function(){
	$(this).parent().stop().animate(
		{backgroundPosition:"(5px -5px)"}, 
		{duration:250}
	)
	})
})











