// remap jQuery to $
(function($){})(window.jQuery);


/* trigger when page is ready */
$(document).ready(function (){
	
	if (section != "") {
		$(".sn-block[id='sn-" + section + "']").show();
	}
	
	//$("#side-nav li").children("ul").hide();
	var uri = location.pathname;
	
	// Directories
	if (uri.indexOf("members/connect/directory") != -1) {
		uri = "/members/connect/directory/";
	}
	if (uri.indexOf("visitors/play/shopping-directory") != -1) {
		uri = "/visitors/play/shopping-directory/";
	}
	if (uri.indexOf("residents/play/shopping-directory") != -1) {
		uri = "/residents/play/shopping-directory/";
	}
	if (uri.indexOf("visitors/sleep/hotels") != -1) {
		uri = "/visitors/sleep/hotels/";
	}
	
	//	Calendar
	if (uri.indexOf("visitors/plan/calendar") != -1) {
		uri = "/visitors/plan/calendar/";
	}
	if (uri.indexOf("visitors/play/calendar") != -1) {
		uri = "/visitors/play/calendar/";
	}
	if (uri.indexOf("residents/play/calendar") != -1) {
		uri = "/residents/play/calendar/";
	}
	
	$("#side-nav a[href='" + uri + "']").addClass("selected").parents("ul").show();
	$("#side-nav .selected").children("ul").show();
	$("#side-nav .selected").siblings("ul").show();
	
	$("#side-nav li").bind("click", function(event) {
		$(this).children().toggle();
	});
	
	/*
	*----------------------- Homepage
	*/
	if ($("#home").length > 0) {
		
		function switchHSlide(s) {
			$("#hs-wrapper div:eq(" + s + ")").siblings().css("z-index", 1);
			$("#hs-wrapper div:eq(" + s + ")").hide().css("z-index", 25).fadeIn(function() {
				$("#hs-wrapper div:eq(" + s + ")").siblings().hide();
			});
			//$("#hs-shadow").prependTo($("#hs-wrapper div:eq(" + s + ") a"));
			//$("#hs-highlight").prependTo($("#hs-wrapper div:eq(" + s + ") a"));
			
			$("#hs-controls div").removeClass("selected");
			$("#hs-controls div:eq(" + s + ")").addClass("selected");
		}
		
		$("<span>").attr("class", "hs-shadow").insertBefore("#hs-wrapper img");
		//$("<span>").attr("id", "hs-highlight").appendTo("#home-slides").hide();
		
		
		var slTotal = 0;
		
		$("<div>").attr("id", "hs-controls").appendTo("#home-slides");
		$("#hs-wrapper div").each(function(i) {
			slTotal++;
			$("<div>").appendTo("#hs-controls");
		}).bind("mouseover", function(event) {
			//$("#hs-highlight").fadeIn();
		}).bind("mouseout", function(event) {
			//$("#hs-highlight").fadeOut();
		});
		$("#hs-controls div").bind("click", function(event) {
			switchHSlide($(this).index());
			$(document).stopTime();
		});
		switchHSlide(0);
		
		var sl = 1;
		
		$(document).everyTime(5000, function(i) {
			//alert("test");
			switchHSlide(sl);
			//$("#home-nav a:eq(" + h + ")").trigger("click");
			sl++;
			if (sl == slTotal) {
				sl = 0;
			}
		});
	}
	
	$(".side-items").insertAfter($("#content header"));
	
	
	/*
	*--------- Directories
	*/
	if ($("#directories").length > 0) {
		$(".select-list").bind("click", function(event) {
			event.stopPropagation();
			$(this).children(".select-list-items").toggle();
			$(".select-list").not(this).children(".select-list-items").hide();
			$(this).children(".select-list-items").height($(this).children(".select-list-items").children("ul").height());
		});
		$(".select-list a").bind("click", function(event) {
			event.stopPropagation();
		});
		$("body").bind("click", function(event) {
			$(".select-list .select-list-items").hide();
		});
	}
	

});


/* optional triggers

$(window).load(function() {
	
});

$(window).resize(function() {
	
});

*/
