/**
 * Amanda site navigation jquery
 *
 * we hide the default navigation list item images and replace them with basic stars
 * on rollover we replace the images with the fancy star images
 * 
 * <div id="topNavigation"><ul class="navListTop"><li class="navListItem open"><a href="/dev/" class="home"><span>Home</span></a>
 */

/**
 * First lets make a simple preloader - copy and paste from this blog:
 
 * http://engineeredweb.com/blog/09/12/preloading-images-jquery-and-javascript
 */

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)

$(document).ready(function()
{
	var imageset = new Array();
	var index = 0;
	imageset[0] = "/images/StarHome.png";
	imageset[1] = "/images/StarArtist.png";
	imageset[2] = "/images/StarGallery.png";
	imageset[3] = "/images/StarEvents.png";
	imageset[4] = "/images/StarContact.png";	

	// lets preload the imageset so the rollovers can happen immediately

	ie6=$.browser.msie&&($.browser.version == "6.0")&&!window.XMLHttpRequest;

	if (!ie6)
	{
		$("#topNavigation ul.navListTop li").each(function()
		{
			var list_item = this;
			var hoverimage = imageset[index];
			if (hoverimage) $.preLoadImages(imageset[index]);
			
			$("(strong, a):first", list_item).each(function()
			{
				if ($(list_item).hasClass("current"))
				{
					$(list_item).css("background", "none");
					$(list_item).prepend('<img style="position: absolute; width: 150px; top: -60px; left: -80px;" src="/images/Star.png" />');
					
					/*
					var offset = $(this).offset();
					alert( "left: " + offset.left + ", top: " + offset.top );
					var list_offset = $(list_item).offset();
					alert( "left: " + list_offset.left + ", top: " + list_offset.top );
					
					$("img", list_item).each(function()
					{
						var image_offset = $(this).offset();
						alert( "left: " + image_offset.left + ", top: " + image_offset.top );
					});	
					*/
				}
				else if (hoverimage)
				{
					$(list_item).css("background", "none");
					$(list_item).prepend('<img style="position: absolute; width: 150px; top: -60px; left: -80px;" src="/images/Star.png" />');
					$(this).hover(
					function()
					{
						$("img", list_item).each(function()
						{
							$(this).attr("src", hoverimage);
						});
					},
					function()
					{
						$("img", list_item).each(function()
						{
							$(this).attr("src", "/images/Star.png");
						});
					});
				}
				else if ( $("#topNavigation ul.navListTop li:last").text() == $(this).text()) // if this the last on the list?
				{
					$.preLoadImages("/images/shop_now.png");
					$(list_item).css("background", "none");
					$(list_item).css("z-index", "1");
					$(this).attr("target", "_blank");
					$(this).prepend('<img style="position: absolute; width: 220px; top: -5px; left: 0px; z-index:-1;" src="/images/shop_now.png" />');
				}
			});
			index = (index + 1);
		});
	}
	else // apply our png fix
	{
		//DD_belatedPNG.fix('img, .navListItem, #scarlet_footer');
	}
});

