
<!-- Paste this code into an external JavaScript file named: feelLucky.js  -->

/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: Will Bontrager :: http://www.bontragerconnection.com/ */

// Leave next line as is.
var Lucky = new Array();

// The cookie to keep track of which "lucky" destinations 
// have already been visited needs a name. Okay to change
//  the cookie name.

var FeelLuckyCookieName = "FeelLuckyCookie";

// When a "lucky" destination has been decided upon, shall 
// the browser open a new window with the desitination URL?
// (Specify "y" or "yes" if yes new window; otherwise "".)
var NewWindow = "";

// Specify your lucky destination URLs here. The first is 
// assigned to Lucky[0], the next to Lucky[1], and so 
// forth, in numerical sequence -- as many as you want.

Lucky[0] = "http://www.bigfoodmonster.com/meat/crackling.php";
Lucky[1] = "http://www.bigfoodmonster.com/meat/rump.php";
Lucky[2] = "http://www.bigfoodmonster.com/fish/gravadlax.php";
Lucky[3] = "http://www.bigfoodmonster.com/meat/roast-pork.php";
Lucky[4] = "http://www.bigfoodmonster.com/desserts/brownie.php";
Lucky[5] = "http://www.bigfoodmonster.com/meat/lamb_shank.php";
Lucky[6] = "http://www.bigfoodmonster.com/meat/rump.php";
Lucky[7] = "http://www.bigfoodmonster.com/desserts/sticky-toffee-pudding.php";
Lucky[8] = "http://www.bigfoodmonster.com/desserts/crumble.php";
Lucky[9] = "http://www.bigfoodmonster.com/desserts/gingercake.php";
Lucky[10] = "http://www.bigfoodmonster.com/desserts/yorkshire_curd_tart.php";
Lucky[11] = "http://www.bigfoodmonster.com/desserts/vanilla-ice-cream.php";
Lucky[12] = "http://www.bigfoodmonster.com/desserts/tiffin.php";
// No additional JavaScript customizations are required. //

var TabChar = String.fromCharCode(9);
var CurrentCookie = '';
function GetLuckyCookie() {
  var cookiecontent = '';
  if(document.cookie.length > 0) {
  	 var cookiename = FeelLuckyCookieName + '=';
  	 var cookiebegin = document.cookie.indexOf(cookiename);
  	 var cookieend = 0;
  	 if(cookiebegin > -1) {
     	cookiebegin  += cookiename.length;
     	cookieend = document.cookie.indexOf(";",cookiebegin);
     	if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
     	cookiecontent = document.cookie.substring(cookiebegin,cookieend);
    }
  }
  return cookiecontent;
}

function PutLuckyCookie(value) {
  if(CurrentCookie.length > 0) { value = CurrentCookie + TabChar + value; }
  value = escape(value);
  document.cookie = FeelLuckyCookieName + "=" + value;
}

function YesMakeMeLucky() { 
  CurrentCookie = GetLuckyCookie();
  CurrentCookie = unescape(CurrentCookie);
  if(CurrentCookie == '.') { CurrentCookie = ''; }
  var LuckyVisitedList = CurrentCookie.split(TabChar);
  if(LuckyVisitedList.length >= Lucky.length) {
   	document.cookie = FeelLuckyCookieName + "=.";
   	CurrentCookie = '';
   	LuckyVisitedList = Array();
  }
  for(var i = 0; i < LuckyVisitedList.length; i++) { Lucky[LuckyVisitedList[i]] = ''; }
  var LuckyL = new Array();
  for(var i = 0; i < Lucky.length; i++) {
   	if(Lucky[i].length > 0) { LuckyL.push('' + i + TabChar + Lucky[i]); }
  }
  var LuckyDestinationNumber = 0;
  if(LuckyL.length > 1) { LuckyDestinationNumber = Math.ceil((Math.random() * LuckyL.length) - 1); }
  var LuckyNumberPlace = new Array();
  LuckyNumberPlace = LuckyL[LuckyDestinationNumber].split(TabChar);
  PutLuckyCookie(LuckyNumberPlace[0]);
  NewWindow = NewWindow.toLowerCase();
  if(NewWindow.substr(0,1) == "y") { window.open(LuckyNumberPlace[1]); }
  else { document.location = LuckyNumberPlace[1]; }
}


