var nevis = {};

nevis.weather = {
	init: function() {
		$.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20feed%20where%20url%3D'http%3A%2F%2Frss.wunderground.com%2Fauto%2Frss_full%2Fglobal%2Fstations%2F78859.xml%3Funits%3Denglish'&format=json&diagnostics=true&callback=?", function(data) {
			var result = data.query.results.item[0].description;
			var temperature = result.substring(13, 15);
			$(".local-temp").html(temperature + " <em>F</em>");

			var localTime = new Date();
			var hours = localTime.getHours() + 1;
			var minutes = localTime.getMinutes();
			var amPM = "";
			if (minutes < 10){
				minutes = "0" + minutes
			}
			
			if(hours > 11){
				amPM = "pm";
			} else {
				amPM = "am";
			}
			
			localTime = hours + ":" + minutes + "" + amPM;
			$(".local-time").text(localTime);

		});
	}
}
$(document).ready(function() {
	nevis.weather.init();
	
	$("ul.topnav li a").hover(function() { //When trigger is clicked...
		$(this).parent().find("ul.subnav").slideDown('fast').show();
		$(this).addClass("subhover");
	}, function() {
		$(this).parent().find("ul.subnav").slideUp('fast').hide();
		$(this).removeClass("subhover");
	});
	
});








var centerScreen = {
	center: function() {
    	var obj = $(".logo-link");
        obj.css('left', $(window).width()/2-obj.width()/2);
    }
}

function setActive() {
	$("ul#topnav li." + section).find("span").show(); //Show the subnav
} 

function setInActive() {
	$("ul#topnav li." + section).find("span").hide(); //Hide the subnav
}

function setSubsectionActive() {
	$("ul#topnav li." + section + " span a." + subsection).css({fontWeight:"bold"});
}

function setSection() {
		
		var url = document.URL;
		var index = 3;
		if(url.indexOf("designinmotion") != -1) {
			index = 3;
		}
		url = url.split("/");
		url = url[index];
		url = url.replace(".php","");
		
		subsection = url;	

		
	switch(url) {
		
		/* the mount nevis hotel */
		case "about-the-hotel":
			section = "nevis-hotel";		
			break;
		case "room-rate-and-info":
			section = "nevis-hotel";
			break;
		case "amenities":
			section = "nevis-hotel";
			break;
		case "dining":
			section = "nevis-hotel";
			break;
		case "faq":
			section = "nevis-hotel";
			break;
		case "mount-nevis-beach-club":
			section = "nevis-hotel";
			break;
		/* nevis island */
		case "about-the-island":
			section = "island";
			break;
		case "how-to-get-to-nevis":
			section = "island";
			break;
		case "amenities":
			break;
		
		/* deals */
		case "wedding":
			section = "deals";
			subsection = "wedding";
			break;
		case "deals":
			section = "deals";
			subsection = "deal";
			break;
		case "packages":
			section = "deals";
			break;
		/* reservation */
		case "make-a-reservation":;
			section = "make-a-reservation";
			break;
		case "mount-nevis-estate":;
			section = "mount-nevis-estate";
			break;
		default:break;
	}
}
