//<![CDATA[
(function($){ // Navigation js
	var winW = $(window).width();
	var mainNav = $(".navigation-outer").html();
	$("#topbar").append("<div class='navigation-outer mobile_navigation'>"+mainNav+"</div>");
	if(winW<968){ $("body").addClass("small-window"); $("body").removeClass("big-window"); }
	if(winW>968){ $("body").addClass("big-window"); $("body").removeClass("small-window"); }
	$(window).resize(function() { 
		winW = $(window).width();
		if(winW<968){ $("body").addClass("small-window").removeClass("big-window"); $(".big-window #navigation .sub-menu").attr("style","display:none;");} 
		if(winW>968){ $("body").removeClass("small-window").addClass("big-window"); $(".big-window #navigation .main-menu, .big-window #navigation .sub-menu").attr("style","");} 
	});
	
	$("[data-font-size]").each(function(){$(this).css({"font-size": ($(this).attr("data-font-size")+"px")});});
	$("[data-font-weight]").each(function(){$(this).css({"font-weight": ($(this).attr("data-font-weight"))});});
	$("[data-line-height]").each(function(){$(this).css({"line-height": ($(this).attr("data-line-height")+"px")});});
	
	$("#navigation .main-menu").append("<li class='arrow'>&nbsp;</li>");
	$("#navigation .sub-level").append("<span class='arrow'>&nbsp;</span>");
	$(".small-window #navigation .sub-level").hover(function(){
		$(this).addClass("sub-hover");
	},function(){ $(this).removeClass("sub-hover");});
	$(".small-window #navigation .sub-level").live("click", function(){
		if($(this).children().hasClass("sub-menu")){ $(this).toggleClass("sub-open").children(".sub-menu").slideToggle(0); }  
		else if($(this).children().hasClass("mega-menu")){ $(this).toggleClass("sub-open").children(".mega-menu").slideToggle(0);}
	});
	
	$(".small-window #navigation").live("click", function(){
		if($("#navigation .sub-level").hasClass("sub-hover")==false){ $(this).toggleClass("nav-open").children(".main-menu").slideToggle(0); }
		$(".call-us-content .close-btn").click();
	});
	$("#navigation").hover(function(){ $(this).addClass("nav-hover"); },function(){ $(this).removeClass("nav-hover"); });
	
	$(".tbar-socio-bar > img").live("click", function(){ $(this).parent(".tbar-socio-bar").toggleClass("open"); $(this).next(".tbar-socio-bar-inner").toggle(); });
	
	$(".tbar-mail-lnk > img").live("click", function(){ $(this).parent(".tbar-mail-lnk").toggleClass("open"); $(this).next(".serv-numb").toggle(); });
	
	
	$(".tbar-mail-lnk").hover(function(){ $(this).addClass("mail-lnk-hover"); },function(){ $(this).removeClass("mail-lnk-hover");});
	$(".tbar-socio-bar").hover(function(){ $(this).addClass("socio-hover"); },function(){ $(this).removeClass("socio-hover");});
	
	$(document).live("mousedown",function() {
		if($("#navigation").hasClass("nav-hover")==false){
			if($("#navigation").hasClass("nav-open")==true){
				
				$("#navigation").click();
			}
		}
		if($("#navigation .sub-level").hasClass("sub-hover")==false){ $(".sub-open").removeClass("sub-open").find(".sub-menu").hide(); $(".mega-menu[style*='display: block']").hide().parent(".sub-level").removeClass("sub-open"); }
		
		if($(".tbar-socio-bar").hasClass("socio-hover")==false){
			if($(".tbar-socio-bar").hasClass("open")==true){ $(".tbar-socio-bar > img").click(); }
		}
		if($(".tbar-mail-lnk").hasClass("mail-lnk-hover")==false){
			if($(".tbar-mail-lnk").hasClass("open")==true){ $(".tbar-mail-lnk > img").click(); }
		}
	});
	
	$(".align-table").each(function(){$(this).height($(this).parents(".align-height").height());});
	$(window).resize(function(){
		if($(window).width()>767){
			$(".align-table").each(function(){ $(this).height("auto"); $(this).height($(this).parents(".align-height").height());});
		} else { $(".align-table").each(function(){$(this).height("auto");});}
	});
	
	$(".max-width-fix").each(function(){
		if($(window).width()>767){
			if($(window).width()<1000){ $(this).addClass("span12").removeClass("mrg10-B"); }
		} else { $(this).removeClass("span12").addClass("mrg10-B"); }
	});
	$(window).resize(function(){
		$(".max-width-fix").each(function(){
			if($(window).width()>767){
				if($(window).width()<800){ $(this).addClass("span12").removeClass("mrg10-B");}
			}else{$(this).removeClass("span12").addClass("mrg10-B");}
		});		
		$(".tbar-mail-lnk .serv-numb").attr("style",""); $(".tbar-socio-bar .tbar-socio-bar-inner").attr("style","");
	});
	
	$(".bg-midbar .banner-next").click(function(){$(".bg-midbar").find(".tp-rightarrow").click();});
	$(".bg-midbar .banner-prev").click(function(){$(".bg-midbar").find(".tp-leftarrow").click();});
	
	if (/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)){/* TOOLTIP JS */
		$('.tooltip-main .ico-help').click(function(){ $(this).next('.tooltipbx').fadeIn(1000);});
		$('.tooltipbx .tooltip-close').click(function(){ $(this).parent('.tooltipbx').fadeOut(1000);});
	}
	else {
		$('.tooltip-main .ico-help,.tooltipbx').hover(function(){ $(this).parent().find('.tooltipbx').css({"display":"inline-block"});
		},function(){ $(this).parent().find('.tooltipbx').css({"display":"none"});});	
	}
	$('.tooltip-close').click(function(){ $(this).parents('.tooltipbx').css({'display':'none'});});
	
	$('.frm-txtbox1').live('focus' , function(){/*FORMBOX */ $('.frm-txtbox1').parent('.fields').parent('li').removeClass('current'); $(this).parent('.fields').parent('li').addClass('current');});
	
	/* MORE BUTTON SCROLL */
	var scrollH = 0
	$(window).scroll(function(){scrollH = $(window).scrollTop();});
	$.getScript('js/jquery-ui-1.8.24.custom.min.js', function(){
	   	$("#more").click(function(){ scrollH += $(window).height(); $("html, body").animate({scrollTop:scrollH},2000, 'easeInOutCubic'); return false; });
		
		$('.quicklinks').click(function(event){
			event.preventDefault();
			var HrefLinkName = $(this).attr('href');
			var HrefLinkNameOffset = $(HrefLinkName).offset().top;
			$('body,html').animate({ scrollTop: HrefLinkNameOffset },2000, 'easeInOutCubic');
		});
		
		$("#top").click(function(){$("html, body").animate({ scrollTop: 0 },2000, 'easeInOutCubic'); return false });
	});
	if(navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod'){$('html, body').animate({"scrollTop":0},300);}
	
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)){/* iPad TOPBAR DROPDOWN */
        $('.tbar-dd-open').click(function(){
			if($(this).hasClass('open')){$(this).next().css({'display':'none'}); $(this).removeClass('open');}
			else{ $('.tbar-dd .tbar-dd-data').css({'display':'none'}); $('.tbar-dd-open').removeClass('open'); $(this).next().css({'display':'block'});$(this).addClass('open');}
		});
		$(".goto-scroll-top, .goto-scroll-bottom").css({"display":"none"});
		window.addEventListener("orientationchange", function(){$('.tbar-dd .tbar-dd-data').css({'display':'none'});},false);
    }

    /* MORE BUTTON SCROLL */
    var scrollH = 0
    $(window).scroll(function(){scrollH = $(window).scrollTop();});
    $("#more").click(function(){scrollH += $(window).height();$("html, body").animate({scrollTop:scrollH},600);return false;});
    if (navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod'){$('html, body').animate({"scrollTop":0},300);}

    /* Got ot Top js */
    $(window).scroll(function () {
        if ($(this).scrollTop() > 100) {$("#top").fadeIn(1000); $('#top').css({ 'display': 'inline-block' });}
        else {$("#top").fadeOut(750); setTimeout(function(){ $("#more").fadeIn(750); }, 750);}       
        if (document.documentElement.clientHeight + $(document).scrollTop() >= document.body.offsetHeight - 5){
            $("#more").fadeOut(1000); // at the bottom of the page.
        }else{$("#more").fadeIn(1000);}

        if (navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod') {
            $(".goto-scroll-top").css({"top": $(this).scrollTop()});
            $(".goto-scroll-bottom").css({"top":($(window).scrollTop()+$(window).height()-15)});
            if($(window).outerHeight()+$(document).scrollTop()>= document.body.offsetHeight-21){$("#more").fadeOut(1000);}else{$("#more").fadeIn(1000);}
        }
    });
    $("#top").click(function(){$("html, body").animate({scrollTop:0}, 600); return false});

    if (navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod') {
        $(".goto-scroll-top, .goto-scroll-bottom").css("position", "absolute");
        $(".goto-scroll-top").css({"top":"0"});
        $(".goto-scroll-bottom").css({"top":$(window).height()});
    };		 
	
	var FadeLogoH = $('.fade-logo').next().height();// NEWS PAGE IMG VERTICAL ALIGNMENT
	// GOOGLE MAP
	$('.mappointerbx .mappointer > img').click(function(){ $('.mapinfobx').css({'display':'none'}); $(this).next('.mapinfobx').show();});
	$('.mappointerbx .close-small-btn').click(function(){ $(this).parents('.mapinfobx').hide(); });
	
})(jQuery);

$(function(){
	checkforfooterlinks();
	function checkforfooterlinks(){
		if($(window).width() < 768){
			$(".footer-nav-links .hd-typ4").each(function(){
				$(this).unbind("click");
				$(this).next().css({"display":"none"});
				$(this).bind("click",function(){
					if($(this).find("span").hasClass("ft-lnk-head-plus")){
						$(".footer-nav-links .hd-typ4 span.ft-lnk-head-minus").parent().next().slideUp(300);
						$(".footer-nav-links .hd-typ4 span.ft-lnk-head-minus").removeClass("ft-lnk-head-minus").addClass("ft-lnk-head-plus");
						$(this).next().slideDown(300);
						$(this).find("span").removeClass("ft-lnk-head-plus").addClass("ft-lnk-head-minus");
					}
					else{ $(this).next().slideUp(300); $(this).find("span").removeClass("ft-lnk-head-minus").addClass("ft-lnk-head-plus"); }
				});
			});
		}
		else { $(".footer-nav-links .hd-typ4").each(function(){ $(this).unbind("click"); $(this).next().css({"display":"block"}); }); }
	}
	if (/webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent)){}
	else{ $(window).resize(function(){ checkforfooterlinks();}); }
 });
//]]>