// JavaScript Document
jQuery.preloadImages = function() {   
	for(var i = 0; i<arguments.length; i++)   
	{
		  jQuery("<img>").attr("src", arguments[i]);   
	}
}

var thisIter;

$(document).ready(function(){
	$("#transOver").css({ opacity: .80 }); // works in all browsers 
	$("#transOver h1").css({ opacity: 1 }); // works in all browsers 
	
	//$("li.lounge").mouseover(function() {	$("li.lounge").css("background", "url(images/sectionsNav_Lounge_over.jpg)"); });
	//$("li.lounge").mouseout(function() {	$("li.lounge").css("background", "url(images/sectionsNav_Lounge.jpg)"); });	

	var arrImages = ""
		
	$('#dotsMenu_group div').each(function(index) {
		$(this).append("<a class='menuItem' id='menuItem-"  + index + "'>" + $(this).attr('title') + "<\/a>");
		arrImages = arrImages + "'..\/" + $(this).attr('imgPath_food') + "','..\/" + $(this).attr('imgPath_rest') + "'"; 		
		if (index != $('#dotsMenu_group div').size)
		{	arrImages = arrImages + ",";	}
	});
	
	//preload the images 
	$.preloadImages(arrImages); 
	
	// to start set 0
	$("#restaurantInterior").css("background", "url(" + $("#dotsMenu_group div:eq(0)").attr('imgPath_rest') + ")");
	$("#transOver h1").html($("#dotsMenu_group div:eq(0)").attr('title'));
	$("#mainImg").css("background", "url(" + $("#dotsMenu_group div:eq(0)").attr('imgPath_food')+ ")");
	$("#dotsMenu_group div:eq(0)").removeClass('dotsMenu_item');
	$("#dotsMenu_group div:eq(0)").addClass('dotsMenu_item_on');
	
	$("a[id|='menuItem']").live("click", function(){
		//swap out image and heading
		var theIndex = $(this).attr("id").replace('menuItem-','');
		$("#restaurantInterior").css("background", "url(" + $("#dotsMenu_group div:eq(" + theIndex + ")").attr('imgPath_rest') + ")");
		$("#transOver h1").html($("#dotsMenu_group div:eq(" + theIndex + ")").attr('title'));
		$("#mainImg").css("background", "url(" + $("#dotsMenu_group div:eq(" + theIndex + ")").attr('imgPath_food')+ ")");
		$("#dotsMenu_group div:not(" + theIndex + ")").removeClass('dotsMenu_item_on');
		$("#dotsMenu_group div:not(" + theIndex + ")").addClass('dotsMenu_item');
		$("#dotsMenu_group div:eq(" + theIndex + ")").removeClass('dotsMenu_item');
		$("#dotsMenu_group div:eq(" + theIndex + ")").addClass('dotsMenu_item_on');
		thisIter = theIndex;
	});
	
	callSwap(0);
});

function callSwap(i){
	$("#restaurantInterior").css("background", "url(" + $("#dotsMenu_group div:eq(" + i + ")").attr('imgPath_rest') + ")");
	$("#transOver h1").html($("#dotsMenu_group div:eq(" + i + ")").attr('title'));
	$("#mainImg").css("background", "url(" + $("#dotsMenu_group div:eq(" + i + ")").attr('imgPath_food')+ ")");
	$("#dotsMenu_group div:not(" + i + ")").removeClass('dotsMenu_item_on');
	$("#dotsMenu_group div:not(" + i + ")").addClass('dotsMenu_item');
	$("#dotsMenu_group div:eq(" + i + ")").removeClass('dotsMenu_item');
	$("#dotsMenu_group div:eq(" + i + ")").addClass('dotsMenu_item_on');
	
	thisIter = (parseInt(i) + 1);
	var totalItems;
	totalItems = $('#dotsMenu_group div').size();
	
	if (thisIter == totalItems) { thisIter = 0 }
	setTimeout( function() {
		callSwap(thisIter)
	}, 5000 );
}
