/* js functions specific to spd */
/* vars for showing and hiding the subnavs */
var subnavTimer;
var subnavOpen;

// jquery function for widget in sidebar
	$(document).ready(function(){
			$("#lists ul:not(:first)").hide();
			$("#lists h3 a").click(function(){
				if ($(this).parent().hasClass("open")) {
					$(this).parent().removeClass("open");
					$(this).parent().next().slideUp("slow");
					}else {
						$(this).parent().addClass("open");
						$(this).parent().next().slideDown("slow");
					}
				
				return false;
			});
			
			// to make sure that when user mouses over sub menu ul it stays open  
			 $("ul.subnav").mouseover(function() {  
				clearTimeout(subnavTimer);
			  $(this).show();  
			  // lets remember what's open  
			  subnavOpen = $(this);  
			 });
			$("ul.subnav").mouseout(function() {  
			  subnavTimer=setTimeout("hideSubnav()",250);
			 });

			 // when user mouses over main item in navbar  
			 $("a.main-link").mouseover(function() {  
			  // close other nav item submenus  
			  if (subnavOpen != null) subnavOpen.hide();  
			  // stop the timer  
			  clearTimeout(subnavTimer);  
			  // show this nav item's sub menu  
			  if ($(this).parent().children("ul") != subnavOpen){
			 		$(this).parent().children("ul:hidden").show();  
					subnavOpen = $(this).parent().children("ul");
					}
			 });

			 // when user's mouse leaves the navbar item  
			 $("a.main-link").mouseout(function() {  
				subnavTimer=setTimeout("hideSubnav()",250);
			 });
		});
		function hideSubnav(){
			subnavOpen.hide();
			subnavOpen = null;
			}

// field focus reset

function field_focus_reset(element, defaultString) {
	if (element.value==defaultString) {
		element.value="";
		element.style.color="#a8a9ad";
	}else{
		return false;
	}
}

function displaySignIn(formState){
		var signin = document.getElementById("signin-form");
		var signintitle = document.getElementById("signin-title");
	if(formState){
		signin.style.display = "block";
		signintitle.style.display = "none";
	}else{
		signin.style.display = "none";
		signintitle.style.display = "block";
	}

}

function hide(element){
	document.getElementById(element).style.display = "none";
}

///////////////////////////////////

function countdownstart() {
    var month = '0';     //  '*' for next month, '0' for this month or 1 through 12 for the month 
    var day = '16';       //  Offset for day of month day or + day  
    var hour = '17';        //  0 through 23 for the hours of the day
    var tz = -5;         //  Offset for your timezone in hours from UTC east coast time
    var lab = 'countdown';    //  The id of the page entry where the timezone countdown is to show

    displayTZCountDown(setTZCountDown(month,day,hour,tz),lab);
}

function setTZCountDown(month,day,hour,tz) {
    var toDate = new Date();

    if (month == '*')toDate.setMonth(toDate.getMonth() + 1);
    else if (month > 0) { 
        if (month <= toDate.getMonth())toDate.setYear(toDate.getYear() + 1);
        toDate.setMonth(month-1);
    }
    if (day.substr(0,1) == '+') {
        var day1 = parseInt(day.substr(1));
        toDate.setDate(toDate.getDate()+day1);
    } 
    else {
      toDate.setDate(day);
    }
	
    toDate.setHours(hour);
    toDate.setMinutes(0-(tz*60));
    toDate.setSeconds(0);
    var fromDate = new Date();
    fromDate.setMinutes(fromDate.getMinutes() + fromDate.getTimezoneOffset());
    var diffDate = new Date(0);
    diffDate.setMilliseconds(toDate - fromDate);
	
    return Math.floor(diffDate.valueOf()/1000);
}

function displayTZCountDown(countdown,tzcd) {
//    if (countdown < 0) document.getElementById(tzcd).innerHTML = "The day has arrived!"; 
    if (countdown < 0) {
        var tzcd_container = document.getElementById(tzcd);
        if (tzcd_container) {
            tzcd_container.innerHTML = "The day has arrived!"; 
        }
    } else {
        var secs = countdown % 60; 
	if (secs < 10) secs = '0'+secs;
	var countdown1 = (countdown - secs) / 60;
	var mins = countdown1 % 60; 
	if (mins < 10) mins = '0'+mins;
	countdown1 = (countdown1 - mins) / 60;
	var hours = countdown1 % 24;
	var days = (countdown1 - hours) / 24;

	var tzcd_container = document.getElementById(tzcd);
	if (tzcd_container) {
		tzcd_container.innerHTML = days + "<span style='color:#FFFFFF;'> day</span>" + (days == 1 ? '' : "<span style='color:#FFFFFF;'>s</span>") + "<span style='color:#FFFFFF;'>, </span>" +hours+ "<span style='color:#FFFFFF;'> hour</span>" + (hours == 1 ? '' : "<span style='color:#FFFFFF;'>s</span>") + "<span style='color:#FFFFFF;'>, </span>" +mins+ "<span style='color:#FFFFFF;'> minute</span>" + (mins == 1 ? '' : "<span style='color:#FFFFFF;'>s</span>");
		setTimeout('displayTZCountDown('+(countdown-1)+',\''+tzcd+'\');',999); 
	}
/*
	document.getElementById(tzcd).innerHTML = days + "<span style='color:#FFFFFF;'> day</span>" + (days == 1 ? '' : "<span style='color:#FFFFFF;'>s</span>") + "<span style='color:#FFFFFF;'>, </span>" +hours+ "<span style='color:#FFFFFF;'> hour</span>" + (hours == 1 ? '' : "<span style='color:#FFFFFF;'>s</span>") + "<span style='color:#FFFFFF;'>, </span>" +mins+ "<span style='color:#FFFFFF;'> minute</span>" + (mins == 1 ? '' : "<span style='color:#FFFFFF;'>s</span>");
	setTimeout('displayTZCountDown('+(countdown-1)+',\''+tzcd+'\');',999);
*/
    }
}


