Image1= new Image(208,13)
Image1.src = "images/loading.gif"
Image2= new Image(10,10)
Image2.src = "images/flavor-arrow-over.gif"
Image3= new Image(10,10)
Image3.src = "images/flavor-arrow-down.gif"

// Slideshow Vars
var topNum = 0;
var bottomNum = 0;
var topTimer = 3000;
var bottomTimer = 5000;

// Nav Vars
var nav = {};


function centerFrame() {
	var winHeight = $(window).height();
	var winWidth = $(window).width();
	var frameHeight = $('#frame').height();
	var frameWidth = $('#frame').width();
	var xOffset = (((winWidth - frameWidth) / 2) > 0) ? Math.floor((winWidth - frameWidth) / 2) : 0;
	var yOffset = (((winHeight - frameHeight) / 2) > 0) ? Math.floor((winHeight - frameHeight) / 2) : 0;
	$('#frame').css({'margin-left':xOffset,'margin-top':yOffset});
}
function animateHeader() {
	$('.anim').each(function() {
		var num = $(this).attr('id').split('-')[1];
		var rand = Math.floor(Math.random()*501) + 750;
		var toPos = 590 - (num * 118);
		$(this).animate({opacity:1,left:toPos},rand);
	});
}
function ajax(data) {
	
	$.ajax({
		method: "get",
		url: "?",
		data: "ajax=true&" + data,
		cache: false,
		beforeSend: function() {
			$('.content').html('<div  id="loading">Loading...<br /><img src="images/loading.gif"></div>');
		},
		success: function(html){
			
			$('#right').html(html);
			
			var pID = (data == undefined) ? false : data.split('&pID=')[1];
			
			if (pID != false) $('#pID-' + pID).addClass('active');
			if ($('.active').length > 0) {
				var parent = $('.active').attr('class').split(' ')[0];
			}
			
			$('#nav .' + parent).addClass('active');
			
			resetOpen();
			if ($('#subnav .active').length > 0) $('#subnav').show();
			//initLocal();
			
		}
	});
}
function shuffleRecipes() {
	$.ajax({
		method: "get",
		url: "?",
		data: "action=shuffle",
		cache: false,
		beforeSend: function() {
			$('.local').addClass('extract').removeClass('local');
		},
		success: function(html){
			html = '<div id="enlarge-mask"></div><div id="enlarge"></div><div id="shuffle"></div>' + html;
			$('#animation').html(html);
			animateHeader();
			initLocal();
			$('.extract').addClass('local').removeClass('extract');
		}
	});
	
}

function shuffle(target,num) {
	$('#' + target + '-' + num).fadeOut('slow');
}
function shuffleTop(target) {
	var max = $('#left img[id^="leftTop"]').length - 1;
	if (topNum == max) {
		topNum = 0;
		$('#leftTop-0').fadeIn('slow',function() {
			$('#left img[id^="leftTop"]').show();
			shuffle(target,topNum);
		});
	} else {
		shuffle(target,topNum);
	}
	topNum++;
}
function shuffleBottom(target) {
	var max = $('#left img[id^="leftBottom"]').length - 1;
	if (bottomNum == max) {
		bottomNum = 0;
		$('#leftBottom-0').fadeIn('slow',function() {
			$('#left img[id^="leftBottom"]').show();
			shuffle(target,bottomNum);
		});
	} else {
		shuffle(target,bottomNum);
	}
	bottomNum++;
}
function slideshow() {
	setInterval(function(){ shuffleTop('leftTop') },topTimer);
	setInterval(function(){ shuffleBottom('leftBottom') },bottomTimer);
}


function openSubNav(target) {
	if ($('#subnav:visible').length > 0) {
		$('#subnav .open').removeClass('open');
		$('#subnav ' + target).addClass('open');
	} else {
		$('#subnav ' + target).addClass('open');
		$('#subnav').slideDown('slow');
	}
}
function resetOpen() {
	$('#subnav .open').removeClass('open');
	if ($('#subnav .active').length > 0) {
		var open = $('#subnav .active').attr('class').split(' ')[0];
	}
	$('#subnav .' + open).addClass('open');
}
function initLocal() {
	$('.local').each(function() {
		if ($(this).attr('href').split('?').length > 1) {
			var href = $(this).attr('href').split('?')[1];
			$(this).attr('href','#' + href)
		}
	});
}
		
		
	
function hideFlash() {
	// Interface Animation
	animateHeader();
}
function destroyFlash() {
	swfobject.removeSWF("flashIntroAni");
	$('#flashIntro').remove();

}

$(document).ready(function() {
	
	/*
	$('input[name="location"]').live('click', function() {
		var value = $(this).attr('value');
		if (value == 'off-premise') {
			$('.toggle').animate({height:23},'fast', function() {
				$('#location-detail').fadeIn('fast',function() {
					$('#right .scroll').jScrollPane();
				});
			});
		} else {
			$('#location-detail').fadeOut('fast',function() {
				$('.toggle').animate({height:0},'fast',function() {
					$('#right .scroll').jScrollPane();
				});
			});
		}
	});
	*/
	
	// Frame Centering
	centerFrame();
	$(window).resize(function() {
		centerFrame();
	});
	
	
	// Page Init
	var url = (location.href.split('#')[1] == undefined) ? "" : location.href.split('#')[1];
	// See if page get string is set
	var getURL = (location.href.split('?')[1] == undefined) ? false : true;
	
	
	initLocal();
	
	$.address.change(function() {
		var url = (location.href.split('#')[1] == undefined) ? location.href.split('?')[1] : location.href.split('#')[1];
		if (location.href.split('action=')[1] == undefined) ajax(url);
	});
	
	slideshow();
	
	// Load intro flash animation
	if (swfobject.hasFlashPlayerVersion("6.0.0") && url == "" && getURL == false) {
		
		// has Flash
		var flashvars = {
			'xmlfile' : 'ufiles/gallery.xml',
			'xmlfiletype' : 'Default'
		};
		var params = {
			allowScriptAccess: "always",
			wmode: "transparent",
			scaleMode: "noScale",
			allowFullScreen : "true"
		};
		var attributes = {};
		swfobject.embedSWF("swf/intro.swf", "flashIntroAni", "935", "775", "6.0.0", "", flashvars, params, attributes);
		
	} else {
		
		// no Flash
		animateHeader();
		$('#flashIntro').remove();
	}
	
	
	
	// Navigation
	$('#nav li').mouseenter(function() {
		if (!$(this).hasClass('active')) {
	
			if($('#nav .active').length > 0) {
				nav.active = $('#nav .active').attr('id');
				$('#nav .active').removeClass('active');
			}
			$('#nav li.over').removeClass('over');
			$(this).addClass('over');
			var target = '.' + $(this).text();
	
		} else {
	
			$('#nav li.over').removeClass('over');
			var target = '.' + $(this).text();
		}
		openSubNav(target);
		nav.ok = true;
	});
	$('#subnav li').mouseenter(function() {
		
		$('#subnav .over').removeClass('over');
		$(this).addClass('over');
	});
	$('#menu').mouseleave(function() {
		$('.over').removeClass('over');
		$('#' + nav.active).addClass('active');
		resetOpen();
	});
	$('a.local').live('click',function() {
		
		if (!$(this).hasClass('foodmenu')) {
			$('.active').removeClass('active');
			$(this).parent('li').addClass('active');
		}
		
		nav.active = $(this).parent('li').attr('id');
		$('#subnav').hide();
		
		var data = $(this).attr('href').split('#')[1];
		ajax(data);
	});
	
	
	// Flavor of the Month
	$('#flavor-toggle,#flavor-close').hover(function() {
		$(this).addClass('over');
	});
	$('#flavor-toggle,#flavor-close').mouseleave(function() {
		$('#flavor-toggle,#flavor-close').removeClass('over');
	});
	$('#flavor-toggle, #flavor-close').click(function() {
		if ($('#flavor-toggle').hasClass('down')) {
			$('#flavor-toggle').removeClass('down');
		} else {
			$(this).removeClass('over').addClass('down');
		}
		$('#flavor-open').slideToggle('slow',function() {
			$('#left .scroll').jScrollPane({scrollbarWidth:8});
		});
	});
	
	$('.anim').live('mouseenter',function() {
		var posL = parseInt($(this).css('left').split('px')[0]) + 30;
		var posT = parseInt($('#enlarge').css('top').split('px')[0]);
		if (posT > -13) {
			$('#enlarge').stop().css({'top':-13,'left':posL}).animate({top:0},'fast');
		} else {
			$('#enlarge').css('left',posL).animate({top:0},'fast');
		}
	});
	$('#animation').live('mouseleave',function() {
		$('#enlarge').stop().animate({top:-13},'fast');
	});
	$('#shuffle').live('click',function() {
		shuffleRecipes();
		return false;
	});
});

// Change the Album title
// Event fired from Flash photogallery
function galleryChangeAlbum(galleryID) {
	for (var i=0; i<galleryArray.length; i++) {
		if (galleryArray[i][0] == galleryID) {
			$('#header h1 span').html(galleryArray[i][1]);
			
		}
		
	}
}
