var days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var delta = 0;

function displayTime() {
	var d = new Date(start + delta);
	var output = "";
	var date = d.getDate();
	var formattedDate;
	var hours = d.getHours();
	var formattedHours;
	var mins = d.getMinutes();
	var formattedMins;
	//var secs = d.getSeconds();
	//var formattedSecs;
	if (date === 1 || date === 21 || date === 31) {
		formattedDate = date + "st";
	} else if (date === 2 || date === 22) {
		formattedDate = date + "nd";
	} else if (date === 3) {
		formattedDate = date + "rd";
	} else {
		formattedDate = date + "th";
	}
	
	if (hours < 10) {
		formattedHours = "0" + hours;
	} else {
		formattedHours = "" + hours;
	}
	if (mins < 10) {
		formattedMins = "0" + mins;
	} else {
		formattedMins = "" + mins;
	}
	/*if (secs < 10) {
		formattedSecs = "0" + secs;
	} else {
		formattedSecs = "" + secs;
	}*/
	
	output += days[d.getDay()];
	output += " ";
	output += formattedDate;
	output += " ";
	output += months[d.getMonth()];
	output += " ";
	output += d.getFullYear();
	output += " <strong>";
	output += formattedHours;
	output += ":";
	output += formattedMins;
	//output += ":";
	//output += formattedSecs;
	output += "</strong>";
	return output;
}

function updateTime() {
	$("#time").html(displayTime());
	delta = delta + 1000;
}

function load_page(myoptions) 
{
        destination = myoptions[myoptions.selectedIndex].value;
        if (destination == "null")
        {
                return true;
        }
        window.open(destination, '_top');
        myoptions.selectedIndex = 0;

        return true;
}


var moreInfo = false;

$(document).ready(function () {

	if ($(document.body).hasClass("slideshow")) {
		$('#photos').galleryView({
			panel_width: 520,
			panel_height: 320,
			frame_width: 100,
			frame_height: 70,
			transition_speed: 1200,
			transition_interval: 15000,
			background_color: '#222',
			border: '1px solid black',
			easing: 'easeInOutBack',
			pause_on_hover: true,
			nav_theme: 'custom',
			overlay_height: 45,
			overlay_font_size: '8pt',
			filmstrip_position: 'bottom',
			overlay_position: 'bottom'
		});

	}

	$("input:text").hint();
	$("#search-submit").click(function () {
		$("#search-form").submit();
	});
	$("#location-display").click(function () {
		$(this).toggleClass("selected");
		$("#location-menu").toggle();
	});
	$("#location-menu li").click(function () {
		var index = $("#location-menu li").index(this);
		$("#weather span").removeClass("selected").eq(index).addClass("selected");
		$("#location-display").text($("strong", this).text());
		$("#location-display").removeClass("selected");
		$("#location-menu").hide();
	});
	$("#location-menu li").hover(function () {
		$(this).addClass("hover");
	}, function () {
		$(this).removeClass("hover");
	});
	$("#location-menu").bind("mouseleave", function () {
		$("#location-display").removeClass("selected");
		$(this).hide();
	});
	updateTime();
	setInterval(updateTime, 1000);
	$("#more").click(function () {
		moreInfo = !moreInfo;
		moreInfo ? $(this).html("Less info") : $(this).html("More info");
		$("#more_info").slideToggle("fast");
		return false;
	});
	$("#links li.cards > a, #links li.results > a, #links li.prices > a, #links li.entries > a").click(function () {
		if ($(document.body).hasClass("slideshow")) {
			$("#content").addClass("slideshow");
			$("#featured").addClass("slideshow");
		}
		if ($(document.body).hasClass("allcards")) {
			$("#content").addClass("allcards");
			$("#featured").addClass("allcards");
		}
		if ($(document.body).hasClass("statistics")) {
			$("#content").addClass("statistics");
			$("#featured").addClass("statistics");
		}
		if ($(document.body).hasClass("info")) {
			$("#content").addClass("info");
			$("#featured").addClass("info");
		}

		$(document.body).removeClass();
		$("#links > ul > li").removeClass("selected");
		$(this.parentNode).addClass("selected");
		$(this).blur();
		return false;
	});
});