$(document).ready(function(){

	if($.browser.msie && $.browser.version=="8.0"){
		$('.subMenu .ressonancia').css('margin-top', '5px');
	}else if($.browser.msie && $.browser.version=="7.0"){
		$('.subMenu .ressonancia').css('margin-top', '15px');
	}else if($.browser.msie && $.browser.version=="9.0"){
		$('.subMenu .ressonancia').css('margin-top', '8px');
		}

	var baseHeader = ".headerLink";
	var baseOver = ".menu-over";

	$(".header").each(
		function(i){
			$(this).hover(function(){
				var label = $(baseHeader, this).html();
				if(!label){
					label = "";
				}
				var url = $(baseHeader, this).attr("href");
				var bkg = $(this).attr("id");
				var sizeW = $(this).width();
				
				$(this).append("<a href="+url+" class='menu-over'>"+label+"</a>");
				$(baseOver, this).css("width", sizeW);
				$(baseOver, this).css("background-image", "url('imagens/bkg-"+bkg+"-over.png')");
				$(baseOver, this).hide();
				$(baseOver, this).fadeIn("fast", "easeOutExpo");
				if($(this).children().is(".subMenu")){
					$(".subMenu", this).fadeIn("fast", "easeOutExpo");
				}
			}, 
		function(){
			$(".subMenu", this).fadeOut("fast", "easeOutExpo");
			$(baseOver, this).fadeOut("slow", function(){
				$(this).remove();
			});
		})
		var subMargin = ($(".subMenu", this).height()+60)*-1;
		$(".subMenu", this).css("margin-top", subMargin);
		$(".subMenu", this).css("display", "none");
	})
//*************************************************************************************	
	$(".rodape .menu li a, .subMenu li a").each(function(){
		var checaStatus = $(this).attr('id');
		if(checaStatus == 'current'){
			$(this).addClass('current_page');
		}else{
			$(this).hover(function(){
			$(this).stop().animate(
				{color: "#ff6600"}, {
					easing: 'easeOutExpo',
					duration: 500
				});
			}, function(){
			$(this).stop().animate(
				{color: "#fff"}, {
					easing: 'easeOutExpo',
					duration: 500
				});
			})
		}
	})
//*************************************************************************************	
	$(".rodape .menu-servicos").hover(function(){
		$('ul', this).fadeIn("fast", "easeOutExpo");
	}, function(){
		$('ul', this).fadeOut("slow", "easeOutExpo");
	})
})
//*************************************************************************************
function accordion(){
	$('.accordion').click(function() {
		var getId= $(this).attr("id");
        $(this).toggleClass("active").next().slideToggle('slow', 'easeOutExpo', function(){
	        if($(this).is(":visible")){
	        	$('html,body').animate({scrollTop: $("#"+getId).offset().top}, 700, 'easeOutExpo');
	       	}
        });
        return false;
    }).next().hide();
    $('.active').next().show();
}
// Scroll ************************************************************************************************************************	
function Scroll(){
	$('a[href*=#]').click(function() {
	 if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
	 && location.hostname == this.hostname) {
	   var $target = $(this.hash);
	   $target = $target.length && $target
	   || $('[name=' + this.hash.slice(1) +']');
	   if ($target.length) {
	  var targetOffset = $target.offset().top;
	  $('html,body')
		  .animate({scrollTop: targetOffset}, 700, 'easeOutExpo');
			return false;
		   }
		 }
		  });
}
// PreLoader ************************************************************************************************************************
(function($){
	var cache = [];
	$.preLoadImages = function(){
		var imageCount = arguments.length;
		for(var i=imageCount;i--;){
			var cacheImage = document.createElement('img');
			cacheImage.src = arguments[i];
			cache.push(cacheImage);
			return(cacheImage);
			}
		}
	})(jQuery)
// Galeria ************************************************************************************************************************	
function galeria(){
	
	var label = [];
	var zoom = [];
	var loadImages = [];
	var PosLin = [];
	var PosLp = [];
	var PosTp = [];
	var PosLg = [];
	var PosTg = [];
	var PosT = [];
	
	var PosL = [];
	var PosL = [];
	
	$('.galeria li').each(function(i){
	
		label[i] = $(this);
		
		PosLin[i] = $(this).offset().left;
		PosLp = 203;
		PosTp = 144;
	
		zoom[i] = $('img', this).attr("src").replace("p", "g");
		loadImages[i] = $.preLoadImages(zoom[i]);
		
		$(loadImages[i]).load(function(){
			
			$(label[i]).append("<div class='img-zoom'><img src='"+$(this).attr("src")+"' /></div>");
			
			PosLg[i] = $(".img-zoom", label[i]).width();
			
			PosTg[i] = $(".img-zoom", label[i]).height();
			PosT[i] = -1*((PosTg[i]-PosTp)/2);
			
			if(PosLin[i]>(PosLg[i]-PosLp)/2){
				PosL[i] = -1*((PosLg[i]-PosLp)/2);
			}else{
				PosL[i] = 0;
			}
			
			$(".img-zoom", label[i]).css('display', 'none');
			$(".img-zoom", label[i]).css('margin-left', PosL[i]+'px').css('margin-top', PosT[i]+'px');	
		})
		
		$('.galeria li').hover(
			function(){
				$(this).css('z-index', '3000');
				$(".img-zoom", this).fadeIn("fast", "easeOutExpo");
			},
			function(){
				$(".img-zoom", this).fadeOut("slow", "easeOutExpo");
				$(this).css('z-index', 'auto');
			}
		)

    })

}


