﻿$(document).ready(function () {

	var activediv = null;
	var nextdiv = null;
	$("div.promoImg").change(function () {
		if (activediv!=null)
		{
			if (activediv!=this)
			{
				nextdiv = this;
				$(activediv).fadeOut("fast", function(){
					$(nextdiv).fadeTo(100, 1.0);
					activediv=nextdiv;
				});
			}
		}
		else
		{
			$(this).fadeTo(100, 1.0);
			activediv = this;
		}
	})
	
	$("div.promoButton").mouseover(function (event) {
		var targetId = event.currentTarget.id.replace(/[^0-9]*/, '');
		//alert(targetId);
		$("div#promoImg"+targetId).change();
		
		$("div.promoButton").removeClass("select");
		$(this).addClass("select");
		
		//alert($("div#promoButton"+targetId).attr('title'));
		window.location.hash = "" + $("div#promoButton"+targetId).attr('title');
	});
	
	var anchor = window.location.hash.substring(1);
	var itemId = $("div[title='" + anchor + "']").attr('id');
	
	if ( $("div#promoButton1").is('*') ) {
		
		if (itemId && (itemId.substring(0, 11) == "promoButton")) {
			
			$("#promoImg" + itemId.replace(/[^0-9]*/, '')).change();
			$("div#" + itemId).addClass("select");
		}
		else {
		
			//do {
				//var showId = (Math.floor(Math.random()*4))+1; /*(random number between 0 and 3) + 1*/
				
				//if ( !$("div#promoTitle" + showId).is('*') ) {
				//	showId = 1;
				//}
			//}
			//while( $.cookie("lastPromoTitleId") == showId );
			showId = 1;
			
			$("#promoImg" + showId).change();
			$("div#promoButton" + showId).addClass("select");
			
			//$.cookie("lastPromoTitleId", showId, { expires: 2 });
		}
	}
	
});
