﻿
// *****************************
// jQuery code for NOCHE.MASTER
// *****************************

// Create SHUFFLE functions
(function($) {
	$.fn.shuffle = function() {
		return this.each(function() {
			var items = $(this).children();
			return (items.length) ? $(this).html($.shuffle(items)) : this;
		});
	}
	
	$.shuffle = function(arr) {
		for (var j, x, i = arr.length; i; j = parseInt(Math.random() * i), x = arr[--i], arr[i] = arr[j], arr[j] = x);
		return arr;
	}
})(jQuery);

$(document).ready(function() {
	
	// Preload the background HOVER image
	var backgroundImage = $("<img />").attr("src", "images/IMGbannerHover.png");
	
	// If the site is launched without DEFAULT.ASPX specified, redirect to DEFAULT.ASPX
	// This ensures that the primary navigation toolbar will highlight the "active" home page
	if (window.location.toString().lastIndexOf("/") == (window.location.toString().length - 1))
	{
		window.location.replace("default.aspx");
	}
	
	// Enable the background HOVER image
	$("#primaryNavigation").hover(
		function() { $("#primaryNavigationWrapper").css("background-image", "url(images/IMGbannerHover.png)"); }, 
		function() { $("#primaryNavigationWrapper").css("background-image", "url(images/IMGbanner.png)"); }
	);
	
	// Find out which primary navigation link should be highlighted and set the CSS class accordingly
	$("#primaryNavigation").find("a").each(
		function(idx, el)
		{
			if (el.href === window.location.toString())
			{ $(el).parent().addClass("current"); }
		}
	);
});
