﻿var currentTime, ctimes, so_timer;
var cmenu, lmenu;
var lt_timer;
var userAgent = navigator.userAgent.toLowerCase();
var ch= 0;
var lch= ch;
var chm = 0;

// Figure out what browser is being used
jQuery.browser = {
	version: (userAgent.match( /.+(?:rv|it|ra|ie|me)[\/: ]([\d.]+)/ ) || [])[1],
	chrome: /chrome/.test( userAgent ),
	safari: /webkit/.test( userAgent ) && !/chrome/.test( userAgent ),
	opera: /opera/.test( userAgent ),
	msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
	mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
};

$().ready(function(){
    ctime = $("#Footer1_hid_countdown").val();
    ctimes = MillisecondsToDuration(ctime).split("");
	lt_timer = ctime;
    
    mytimer();

	$("#menu ul.wrapper > li > a").hover(function(){
		lmenu = cmenu;
		cmenu =$(this);
		if(lmenu && lmenu!=cmenu){
			lmenu.parent().find(".submenu").stop().animate({top:-130},100);
			lmenu.removeClass("active");
		}
		if($(this).parent().find(".submenu").size()>0){
			$(this).parent().find(".submenu").stop().animate({top:31},100);

			$(this).addClass("active");
		}
	},function(){
	});
	$("#menu ul.wrapper a").hover(function(){
		lt_timer = ctime;
	},function(){});

	$(".submenu").hover(function(){
	},function(){
		lt_timer = ctime;
		$(this).parent().find("a:eq(0)").removeClass("active");
		$(this).stop().animate({top:-130},100);
	});
	
	$("#Header1_Login1_UserName, #Header1_Login1_Password").keypress(function(event){
		if(event.keyCode==13){
			WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("Header1$Login1$LoginButton", "", true, "login_group", "", false, true));
		};
	});
});

function mytimer(){
    ctime = ctime - 1000;
    ctimes = MillisecondsToDuration(ctime).split("");
	if((lt_timer-ctime)>=3000){
		lt_timer = ctime;
		$("#menu ul.wrapper .submenu").each(function(){
			var c_top = $(this).css("top");
			if(parseInt(c_top.substr(0,c_top.length-2))>0){
				$(this).stop().animate({top:-130},100);
				var _cmenu = $(this).parent().find("a:eq(0)");
				lmenu = cmenu;
				cmenu = _cmenu;
				lmenu.removeClass("active");
			}
		});
	}


    if (currentTime) currentTime(ctime);
    var tgt = document.getElementById("countdown_inner") ;
    
    if(tgt){
        tgt.innerHTML=('<div class="cd_d"><div class="w"><h4 class="no' + ctimes[0] + '">'+ctimes[0]+'</h4><h4 class="no' + ctimes[1] + '">' + ctimes[1] + '</h4><h4 class="no' + ctimes[2] + '">' + ctimes[2] + '</h4></div></div><div class="cd_h"><div class="w"><h4 class="no' + ctimes[3] + '">' + ctimes[3] + '</h4><h4 class="no' + ctimes[4] + '">' + ctimes[4] + '</h4></div></div><div class="cd_m"><div class="w"><h4 class="no' + ctimes[5] + '">' + ctimes[5] + '</h4><h4 class="no' + ctimes[6] + '">' + ctimes[6] + '</h4></div></div><div class="cd_s"><div class="w"><h4 class="no' + ctimes[7] + '">' + ctimes[7] + '</h4><h4 class="no' + ctimes[8] + '">' + ctimes[8] + '</h4></div></div>');
   }
   clearTimeout(so_timer);
   so_timer  = setTimeout("mytimer()",1000);
   
	lch= ch;
   //REFRESH CONTENT HEIGHT
   if($(window).height()>700){
	   
		if ($.browser.msie && parseInt($.browser.version) < 7){
			ch = $(window).height()+30;
			chm = $(window).height()-100;
	   }else if($.browser.safari){
		   
			ch = $(window).height()-30;
			chm = $(window).height()-30
		   if(isiPhone()){
				ch = $(window).height()-150;
				chm = $(window).height()-150;
		   }
	   }else{
		   if($(".auto-h #content .wrapper").height()<getDocHeight()){
				ch = $(window).height();
				chm = $(window).height()-100;
		   }else{
			    
		   }
	   }
	   if(lch!=ch){
			$(".auto-h #content .wrapper").css("height",ch);
			$(".auto-hm #content .wrapper").css("height",chm);
			lch = ch;
	   }
	   
   }else{
	   ch = 770;
	   chm = 720;
	   if(lch!=ch){
		   $(".auto-h #content .wrapper").css("height",ch);
		   $(".auto-hm #content .wrapper").css("height",chm);
			lch = ch;
	   }
   }
}
function isiPhone() {
	var agent = navigator.userAgent.toLowerCase();
	return agent.match(/iPhone/i);
}
function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}
function MillisecondsToDuration(n) {
	var hms = "";
	var dtm = new Date();
	dtm.setTime(n);
	var d = "000" + Math.floor(n / 86400000);
	var h = "0" + dtm.getUTCHours();
	var m = "0" + dtm.getMinutes();
	var s = "0" + dtm.getSeconds();

	var cs = "0" + Math.round(dtm.getMilliseconds() / 10);
	hms = d.substr(d.length-3) + h.substr(h.length-2) + m.substr(m.length-2);
	hms += s.substr(s.length-2) /*+ "." + cs.substr(cs.length-2)*/;

	return hms;
}

