
var i = 0;
var slideshow = null;
var marqueeTimeDelay = 5000;
var NUMSLOTS = 4;
var previd = 4;	

$(document).ready(function(){
	$(".marqpic").hide();
	$("#pic1").show();
	$("#item1").bind("mouseenter", function (e) { i = 0; showThisItem(1); } );
	$("#item2").bind("mouseenter", function (e) { i = 1; showThisItem(2); } );
	$("#item3").bind("mouseenter", function (e) { i = 2; showThisItem(3); } );
	$("#item4").bind("mouseenter", function (e) { i = 3; showThisItem(4); } );
	$("#marqueelistcontainer > a").bind("mouseleave", function (e) { runSlideshow(); } );
	runSlideshow();
});

function showThisItem (itemid) {
	stopSlideshow();
	$(".marqpic").hide();
	$("#pic" + itemid).show();
	$(".marqitemon").addClass("marqitem");
	$(".marqitemon").removeClass("marqitemon");
	$("#item"+itemid).removeClass("marqitem");
	$("#item"+itemid).addClass("marqitemon");
	
}

function doMarquee( showid ) {
	previd = showid - 1;
	if (previd < 1) {
		previd = 4;
	}

	$("#pic" + previd).fadeOut(1000, 
		function() {
			$("#pic"+showid).fadeIn("normal");
			$("#item"+previd).removeClass("marqitemon");
			$("#item"+previd).addClass("marqitem");
			$("#item"+showid).removeClass("marqitem");
			$("#item"+showid).addClass("marqitemon");
		}
	);
	stopSlideshow();
};

function runSlideshow(marqnum) {
	if(marqnum) i = marqnum;
	else i = i + 1;
	if( i > ( NUMSLOTS ) ) {
		i = 1;
	};
	doMarquee( i );
	slideshow = setTimeout( 'runSlideshow()', marqueeTimeDelay );
};

function stopSlideshow() {
	clearTimeout(slideshow);
};
