// JavaScript Document
var isIE6
/*----------Ajax Loader initialization----------- */
var ajaxLoader = new Image();
	ajaxLoader.src = '/images/offline/ajax-loader.gif';
/*----------Current and target dates----------- */
var targetDate = new Date(targetYear, targetMonth, targetDate, targetHours, targetMinutes, targetSeconds, 0);

/*----------Difference between target and current date----------- */
var diff = {};
	diff.ms = targetDate.getTime() - currentDate.getTime()
	diff.days = Math.floor((diff.ms)/(1000 * 60 * 60 * 24));
	diff.hours = (diff.ms - diff.days*(1000 * 60 * 60 * 24))/(1000 * 60 * 60);
	diff.fullHours = Math.floor(diff.hours);
	diff.mins = (diff.hours - diff.fullHours)*60;
	diff.fullMins = Math.floor(diff.mins);
	diff.seconds = (diff.mins - diff.fullMins)*60;
	diff.fullSec = Math.floor(diff.seconds);
if (diff.fullHours<10) diff.fullHours = "0"+diff.fullHours;
if (diff.fullMins<10) diff.fullMins = "0"+diff.fullMins;
if (diff.fullSec<10) diff.fullSec = "0"+diff.fullSec;
if (diff.days<100 && diff.days>=10) diff.days = "0"+diff.days;
if (diff.days<10) diff.days = "00"+diff.days;

$(function(){
	/*----------Clock Timer Initialization----------- */
	$(".day").html(diff.days);
	$(".hour").html(diff.fullHours);
	$(".minute").html(diff.fullMins);
	if ((diff.fullSec+"").length==2) {
			var second1 = (diff.fullSec+"").substr(0,1);
			var second2 = (diff.fullSec+"").substr(1,1);
	}
	else {
			var second1 = 0;
			var second2 = diff.fullSec;
	}
	$(".second1").html(second1);
	$(".second2").html(second2);
	function changeDay(){
			var currentDay = $(".day:first").html()*1;
			var newDay = currentDay-1;
			if (newDay < 100 && newDay >= 10) newDay = "0"+newDay;
			if (newDay < 10) newDay = "00"+newDay;
			$(".d-wrap").prepend('<div class="day">'+newDay+'</div>');
			$(".day:eq(0),.day:eq(1)").animate({top:"+=80px"},2500,function(){$('.day:eq(1)').remove()});
	}
	function changeHour(){
			var currentHour = $(".hour:first").html()*1;
			var newHour = currentHour-1;
			if (newHour < 0) {
				newHour = 23;
				changeDay();
			}
			if (newHour < 10 && newHour >= 0) newHour = "0"+newHour;
			$(".h-wrap").prepend('<div class="hour">'+newHour+'</div>');
			$(".hour:eq(0),.hour:eq(1)").animate({top:"+=80px"},2000,function(){$('.hour:eq(1)').remove()});
	}
	function changeMinute(){
			var currentMin = $(".minute:first").html()*1;
			var newMin = currentMin-1;
			if (newMin < 0) {
				newMin = 59;
				changeHour();
			}
			if (newMin < 10 && newMin >= 0) newMin = "0"+newMin;
			$(".m-wrap").prepend('<div class="minute">'+newMin+'</div>');
			$(".minute:eq(0),.minute:eq(1)").animate({top:"+=80px"},1500,function(){$('.minute:eq(1)').remove()});
	}
	function changeFirstSecond(){
			var currentSecond = $(".second1:first").html()*1;
			var newSecond = currentSecond-1;
			if (newSecond <0 ) {
				newSecond = 5;
				changeMinute();
			}
			$(".s-wrap").prepend('<div class="second1">'+newSecond+'</div>');
			$(".second1:eq(0),.second1:eq(1)").animate({top:"+=80px"},500,function(){$('.second1:eq(1)').remove()});
	}
	setInterval(function(){
			var currentSecond = $(".second2:first").html()*1;
			var newSecond = currentSecond-1;
			if (newSecond <0 ) {
				newSecond = 9;
				changeFirstSecond();
			}
			$(".s-wrap").prepend('<div class="second2">'+newSecond+'</div>');
			$(".second2:eq(0),.second2:eq(1)").animate({top:"+=80px"},500,function(){$('.second2:eq(1)').remove()});
			
	},1000);
	setTimeout(function(){$(".divider").hide()},500)
	setInterval(function(){
			$(".divider").show()
			setTimeout(function(){$(".divider").hide()},500)	
	},1000)	
	/*----------Glass panes animation----------- */
	$(".glass-panes").find("img").each(function(){
		makeItAnimated($(this),$(this).width())	
	})
	function makeItAnimated(img,imgWidth) {
		var newSmallWidth = imgWidth*0.9;
		img.hover(
			function(){
				
				img.animate({width:	newSmallWidth},150)
			},
			function(){
				img.animate({width:	imgWidth},150)
			}
		)
	}
	/*----------"Open Content" animation----------- */
	$(".openContent").click(function(e){
		e.preventDefault();
		$("h1.will-open").fadeOut(300);
		$(".clock").animate({top:"-80px"},600);
		$(".glass-panes").animate({top:"-110px",width:800},600);
		$(".glass-pane:eq(0),.glass-pane:eq(1)").animate({marginRight:128},600)
		$(".home-content,.footer").fadeOut(600);
		$(".content-wrap").delay(800).fadeIn(600)
	})
	/*----------"About" links animation----------- */
	$(".ul-links li a").hover(
		function(){
			$(this).animate({marginLeft:"5px"},150)	
		},
		function(){
			$(this).animate({marginLeft:"0px"},150)	
		}
	)
	/*----------Popup links handling----------- */
	$("a.popup").click(function(e){
		e.preventDefault();
		var filename = $(this).attr('href').substr(1);
		popUp({url : "content/"+filename+".html", pWidth : $(this).attr("rel")});
	})
	$(".dark-layer,.close-popup").click(function(){closePopup()})
	/*----------Send Email form----------- */
	$("input#email").click(function(){
		if($(this).val()=="Your email here") $(this).val("")
	})
	$("#sendEmail").click(function(){
		validateEmail("#email");
		if(!$("input#email").hasClass("required")) {
			$("input#email,#sendEmail").hide()
			$(".sendEmail").append('<img class="ajax-loader" src="'+ajaxLoader.src+'" width="'+ajaxLoader.width+'" height="'+ajaxLoader.height+'" />')
			jQuery.get("scripts/send-email.php",{email:$("input#email").val()},function(status){
				$(".sendEmail .ajax-loader").fadeOut(300,function(){$(".sendEmail .ajax-loader").remove()})
				$(".message-status").html(status)
				$(".message-status").delay(400).fadeIn(600)
			})
		}
	})
})
