//////////////////////////////////////////////////////
//
//	The purpose of this file is to
//	apply a hover class on mouseover
//	on the <li> elements in the nav.
//	This is because IE doesn't put
//	the pseudo class :hover on <li> elements
//
//	This is code that uses the
//	jquery javascript library (http://jquery.com/)
//
//////////////////////////////////////////////////////
$(window).load(function() {
	if (document.all&&document.getElementById) {
		// this is needed for the IE 6 pseudo hover class bug
		$(".navtop > li").hover(function() {
			$(this).addClass("hover");
		},
		function () {
			$(this).removeClass("hover");
		});
		
		$(".navtop > li li ").hover(
		function () {
			$(this).addClass("hover");
		},
		function () {
			$(this).removeClass("hover");
			
		});
		
		
	} else {
		// this is need for safari when nav covers flash
		$(".navtop li ul").mouseover(function () {
			$(this).addClass("redraw");
		});
		$(".navtop li ul").mouseout(function () {
			$(this).removeClass("redraw");
		});
	}
	
	$('#imageMap').each(function(){
		var areas = $(this).find('#interactiveMap area');
		var hiddenText = $(this).find('#hiddenText p');
		$("#textDisplay").fadeTo("slow", 0.6);
		for(i = 0; i < areas.length; i++)
		{
			areas[i].hiddenText = $(hiddenText[i]).html();
			//alert($(hiddenText[i]).html());
		}
		$(areas).mouseover(function(){
			$('#textDisplay p').html(this.hiddenText);
			$('#textDisplay').dequeue();
			$('#textDisplay').animate({height: '60px'}, 'slow');
			//var tony = 'loader';
			//alert($(this).hiddenText);
		});
                $(areas).click(function(){
	             return false;
                 });
		/*$(areas).hover(function(){
			$('#textDisplay p').html(this.hiddenText);
			$('#textDisplay').dequeue();
			$('#textDisplay').animate({height: '60px'}, 'slow');
			//var tony = 'loader';
			//alert($(this).hiddenText);
		}, function(){
			$('#textDisplay p').html('');
			$('#textDisplay').dequeue();
			$('#textDisplay').animate({height: '0px'}, 'slow');
			
		});*/
		
	});
	
	
	$('.megaPan').each(function(){
		var aPan = 624;
		var currPan = 0;
		var itemsPerPan = 8;
		var items = $(this).find('.productList li');
		$(this).html('');
		var numPans = Math.ceil(items.length / 8);
		for(i = 0; i < numPans; i++)
		{
			var pan = $('<div class="pan"></div>').appendTo(this);
			var panUL = $('<ul class="productList"></ul>').appendTo(pan);
			for(j = 0; j < itemsPerPan; j++)
			{
				if(i * itemsPerPan + j < items.length)
					panUL.append(items[i * itemsPerPan + j]);
				else
					j = itemsPerPan;
			}
			$('.numList').append('<a href="">' + (i+1) +'</a>&nbsp;');
		}
		$($('.numList a')[0]).addClass('selected');
		function doPan(page)
		{
			$('.numList a').removeClass('selected');
			$($('.numList a')[page]).addClass('selected');
			var margLeft = -(page  * aPan) + 'px';
			$('.megaPan').animate({marginLeft: margLeft}, 1000, "easeInOutCirc" );
		}
		$('.numList a').click(function(){
			var page = parseInt($(this).html());
			currPan = page - 1;
			doPan(currPan);
			return false;
		});
		if(numPans == 1)
			$('#productPager').hide();
		$('#productPager .next').click(function(){
			if(currPan + 1 < numPans)
			{
				currPan = currPan + 1;
				doPan(currPan);
			}
			return false;
		});
		$('#productPager .prev').click(function(){
			if(currPan - 1 >= 0)
			{
				currPan = currPan - 1;
				doPan(currPan);
			}
			return false;
		});
		
	});
	
});

