	/* Page bookmarking and Analytics ---------------------------------------------- */
	
	function gotopage(p) {
		$.historyLoad(p);
		return false;
	}
	
	function pageload(p) {
		if(typeof($) == 'undefined') {
			setTimeout(function(){pageload(p)},1000);
		} else {
		
			// if a hash is set, load the appropriate content
			if(p){
			
				if (pageType == 'tabs') { 
				// Analytics
				pageTracker._trackPageview('/grill/recipes/'+p);

				// assemble the name of the tab and icon id's you're targeting
				p = p.charAt(0).toUpperCase() + p.substr(1).toLowerCase(); // ridiculous how you have to capitalize a string in js
				iconID = 'grill'+ p;
				tabID = 'tab'+ p;

				tabSwap($('a#'+iconID));
				iconSwap($('a#'+iconID).find('img'));
				
				} else {
				
				// This is the video page
				pageTracker._trackPageview('/grill/videos/'+p);
				p = p.charAt(0).toUpperCase() + p.substr(1).toLowerCase();
				swapVideo('vid'+p);
				}
		}
	}
	}


	// initialize some vars
	iconON = '';
	tabOpen = '';
	videoOpen = false;
	
	// turn on an icon
	function turnON(obj) {
		imgsrc = $(obj).attr('src');
		imgsrcON = imgsrc.replace('OFF', 'ON');
		$(obj).attr("src", imgsrcON).addClass('trans');
	}
	
	// turn off icon
	function turnOFF(obj) {
		imgsrc = $(obj).attr('src');
		imgsrcOFF = imgsrc.replace('ON', 'OFF');
		$(obj).attr("src", imgsrcOFF);
	}
	
	
	// turn off currently activated icon, turn on new active icon
	function iconSwap(iconIMG) {
		
		// turn off any currently on icon
		if (iconON != '') {
			turnOFF($('img[src*="'+iconON+'"]'));
		}
		
		turnON($(iconIMG));
		iconSRC = $(iconIMG).attr('src');
		newSRC = iconSRC.replace('OFF','ON');
		iconON = newSRC;
	}
	
	
	
	
	// Function to slide accordion tabs up and down
	function tabSwap (tabLink) {
	
		//when clicked, take the id of the link and translate it to 
		// a corresponding tab id
		linkID = $(tabLink).attr('id');
		tabID = linkID.replace('grill', 'tab');


			// close currently open tab
			if (tabOpen != '') {
			
			$('#'+tabOpen+'.grillTabContainer').animate({
					top: '765px'
				}, 500);
				
				setTimeout(function() {
				$('#'+tabOpen+'.grillTabContainer').hide();
				}, 500);
			}

			// open the requested tab
			setTimeout(function(){ // wait a half second between transitions
				
			$('#'+tabID).show().animate({
				top: '350px'
			}, 500);
				
			$('.grillTips #grillShrubbery').show().animate({
				top: '350px'
			});
				
				// reset currently open tab ID
				tabOpen = tabID;
				
				$('#'+tabID+' .grillAccordion').accordion( { 
						autoHeight: false,
						collapsible: true
					 	}
				);
				
				// hide the intro text
				setTimeout(function() {
					$('#grillText').hide();
				}, 500);
				
			},500); //end first timeout

		//}
		
		return false;
	}
	
	
	// set up an array with flash videos
	videoList = new Object();
	videoList['vidFire'] = '/Content/flash/Grill/Starting_Fire.flv';
	videoList['vidMethods'] = '/Content/flash/Grill/Grilling_Methods.flv';
	videoList['vidBurgers'] = '/Content/flash/Grill/Bacon_Burgers.flv';
	videoList['vidChops'] = '/Content/flash/Grill/Pork_Chops.flv';
	videoList['vidPorchetta'] = '/Content/flash/Grill/Pork_Loin.flv';
	videoList['vidRibs'] = '/Content/flash/Grill/Easiest_Ribs.flv';
	videoList['vidBeans'] = '/Content/flash/Grill/Sweet_Tangy_Beans.flv';


	function swapVideo(linkID) {
		
		// switch bg's on any previously clicked link
		$('#grillVideoRight li a.selected').removeClass('selected');
	
		// swap backgrounds
		$('#'+linkID).addClass('selected');
		
		
		// lower the left tab out of sight
		$('#grillVideoLeft').animate({
			top: '510px'
		}, 500);
		
		setTimeout(function() {
		
		// if the video div is not yet active, hide the intro text
		// and show the video player
		$('#videoIntro').hide();
		
		$('#videoWrap').show();
		
			videoSRC = videoList[linkID];
			
			var so = new SWFObject("/content/flash/video_player_320x240.swf", "mymovie", "320", "240", "8", "#FFFFFF");
		   	so.addParam("wmode", "transparent");
		   	so.addVariable('vpath',videoSRC);
			so.addVariable('vwidth',320);
			so.addVariable('vheight',240);
			so.addVariable('autoplay',true);
			so.addVariable('isMute',false);
		   	so.write("videoPlayer");
		
		setTimeout(function(){
		
			// move the tab back up (delay a second to give the video time to appear)
			$('#grillVideoLeft').animate({
				top: '197px'
				}, 500);
			}, 1000);
						
		}, 500);
	
	} // end swapVideo()
		


$(document).ready(function() {

		// Preload all rollovers
		$("#grillNav img, #grillIcons img").each(function() {
			rollsrc = $(this).attr("src");
			//for ie6 replace png extension with jpg
			if(document.ie6=true){
				rollsrc = rollsrc.replace("png","jpg");
			}
			// Set the original src			
			rollON = rollsrc.replace('OFF', 'ON');
			newImg = new Image(); // create new image obj
			$(newImg).attr("src", rollON); // set new obj's src
		});

		
		// Navigation rollovers
		$("#grillNav a:not(.on), #grillIcons a").hover(
			function(){turnON($(this).children("img"));},//over
			function(){//out
				if (typeof(imgsrc) != 'undefined' && imgsrcON != iconON) {
					turnOFF($(this).children("img"));
				}
			}
		
		);
		
		$('table.recipes tr:nth-child(even) td').addClass('alt');

		/* Recipes and Tips ----------------------------------- */

		// Perform the tab swapping
		$('#grillIcons a').click(function() {
			tabSwap($(this));
			iconSwap($(this).find('img'));
			
			hash = $(this).attr('id');
			hash = hash.replace('grill', '');
			gotopage(hash.toLowerCase()); 
			return false;
		});


		/* Videos ---------------------------------------------- */
		
				
		
		$('#grillVideoRight li a').click(function() {
		
			linkID = $(this).attr('id');
			swapVideo(linkID);
			
			hash = linkID.replace('vid', '');
			gotopage(hash.toLowerCase());
			
			return false;
		});
		


});


