// permit debugging; turn off ehen live
var allow = true;

// if debug = true, show gallery HTML in a textarea
var debug = ( parseQueryString("d") && allow ) ? true :  false;
var showHTML = ( parseQueryString("h") && allow ) ? true :  false;

var fpoPath = "images/fpo/";

var fishFinalists = new Array ();

fishFinalists["hide_and_seek_balltag"] = 
	{
	"gameTrackNumber":"1", 
	"gameName":"Hide &amp; Seek Ball Tag",
	"gameCreator":"Nicolas Z.",
	"gameLocation":"Natick, MA",
	"gameDescription":"One person has the ball and is the \"Seeker\"; the rest are \"Hiders\". Seeker counts to 30 while Hiders find hiding spots. Seeker must then find the Hiders and throw the ball at them to get them \"Out\". Players who are Out stand off to the side, but can be brought back in to the game by a Hider tagging them. If a Hider catches the ball thrown by the Seeker, that Hider becomes the new Seeker and a new round starts.",
	"gameEquipment":"1 Soft Dodgeball, Hiding Places."
	};

fishFinalists["knockdown_garbage"] = 
	{
	"gameTrackNumber":"2", 
	"gameName":"Knockdown Garbage",
	"gameCreator":"Joshua M.",
	"gameLocation":"Ronkonkoma, NY",
	"gameDescription":"Each player takes a turn throwing ball into garbage can from a distance. Players get 3 throws each. Player with the most points wins. Points: Ball knocks down can = 4 pts. Ball goes in can = 8 pts. Ball goes in + knocks it down = 29 pts.",
	"gameEquipment":"Basketballs, 1 Garbage Can."
	};

fishFinalists["trash_raquetball"] = 
	{
	"gameTrackNumber":"3", 
	"gameName":"Trash Raquetball",
	"gameCreator":"Geoffrey B.",
	"gameLocation":"Hartsdale, NY",
	"gameDescription":"Set up trash cans as goals. Each team's Goalie wears apron with 12 tennis balls of one color in pockets. Goalie serves a ball every 30 seconds, counting out loud, to teammates. Players must use racquets to move the ball and score on opposing team's goal. Goalies must defend goal. First team to score all their balls WINS!",
	"gameEquipment":"2 Trash Cans, Tennis Racquets, 24 Balls (2 colors, 12 of each), Team Jerseys, 2 Aprons with Pockets."
	};

fishFinalists["airskate"] = 
	{
	"gameTrackNumber":"4", 
	"gameName":"Air Skate",
	"gameCreator":"Tyler W.",
	"gameLocation":"Sparta, NJ",
	"gameDescription":"Place goals on either end of court. Players must wear skates, helmets, pads. Object is to get balloons, by air or ground, into opposing team's goal using only hockey sticks. Game starts with all 3 balloons in center of field. Players have no assigned positions. Highest scoring team wins.",
	"gameEquipment":"Helmets, 2 Netted Goals, 3 Air-filled Balloons, Roller-Skates (outdoors) or Carpet Skates (indoors), Youth Hockey Sticks, Knee Pads."
	};

fishFinalists["kick_the_cow"] = 
	{
	"gameTrackNumber":"5", 
	"gameName":"Kick the Cow",
	"gameCreator":"Garrett T.",
	"gameLocation":"Midlothian, TX",
	"gameDescription":"Set up field edge with cones. The container starts in the middle. Teams compete in a way similar to soccer to get the carton to the opposing end of the field. If the carton goes out of bounds it is thrown back in. When the carton reaches a \"goal\" the number facing up is the number of points that team gets. Game continues until one team reaches 11 points.",
	"gameEquipment":"9 Road Cones, a Milk Carton with a Number (1-4) Written on Each Side."
	};

fishFinalists["wacked_out_baseball"] = 
	{
	"gameTrackNumber":"6", 
	"gameName":"Wacked Out Baseball",
	"gameCreator":"Karoline G.",
	"gameLocation":"San Antonio, TX",
	"gameDescription":"Similar to baseball, but no pitching or hitting. \"Batter\" throws ball from home plate as far as possible. Opposing team fields the ball and tries to get the Batter \"Out\" by tagging or catching a fly ball.Batter Must: 1) Laugh all the way to 1st Base; 2) Skip all the way to 2nd Base; 3) Run backwards to 3rd Base; 4) Scream all the way Home and then Dance. (Dance must be good!) Team with most runs WINS!",
	"gameEquipment":"1 Baseball, 4 Bases."
	};

allFish = fishFinalists.length;
//fishes["fishFinalists"] = { "allFish":,  "showVoteButton":true  };


/* begin create dengol javascripts */
var dengol_prefix = "dengol_GoldfishGamesWatchVideo";
var dengol_suffix = "Button_10";
//var dengol_code1 = '<script language="JavaScript" src="http://view.atdmt.com/jaction/';
//var dengol_code2 = '"></script>\n<noscript><iframe src="http://view.atdmt.com/iaction/';
var dengol_code1 = '<iframe src="http://view.atdmt.com/jaction/';
var dengol_code2 = '" width="1" height="1" frameborder="0" scrolling="No" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0"></iframe>\n<noscript><iframe src="http://view.atdmt.com/iaction/';
var dengol_code3 = '" width="1" height="1" frameborder="0" scrolling="No" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0"></iframe></noscript>';

var tcode1 = '<iframe src="http://pepperidge.promotionexpert.com/jaction/';
var tcode2 = '" width="1" height="1" frameborder="0" scrolling="No" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0"><\/iframe>\n<noscript><iframe src="http://pepperidge.promotionexpert.com/iaction/';
var tcode3 = '" width="1" height="1" frameborder="0" scrolling="No" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0"><\/iframe><\/noscript>;';
 

function create_dengol_javascript(which_dengol)
	{
	tracking_code = dengol_prefix + which_dengol + dengol_suffix;
	j = dengol_code1 + tracking_code + dengol_code2 + tracking_code + dengol_code3;
	if (debug) { j = j+ "\n" + tcode1 + tracking_code + tcode2 + tracking_code + tcode3; }
	return j;
	}

var closeWindow = "<div class=\"closeWindowButtonDiv\"><a href=\"javascript:return false;\" onclick=\"self.parent.tb_remove(); return false;\" class=\"closeWindowButton\">Close Window</a></div><!-- end close window -->\n";

function create_movie(whichFinalist)
	{
	// see videos_code.js
	var myMovieCode = generateMovie(whichFinalist);

	scriptNumber = fishFinalists[whichFinalist]['gameTrackNumber'];
	gameName = fishFinalists[whichFinalist]['gameName'] ;
	gameCreator = fishFinalists[whichFinalist]['gameCreator'];
	gameLocation = fishFinalists[whichFinalist]['gameLocation'];
	gameDescription = fishFinalists[whichFinalist]['gameDescription'];
	gameEquipment = fishFinalists[whichFinalist]['gameEquipment'];

	externalTrackingScript = create_dengol_javascript(scriptNumber)  ;
	internalTrackGIF = dynamicGIF(whichFinalist);
	//film = "<div class='myMovieContainer'><div class='myMovie'><img src='" +fpoPath + whichFinalist + ".gif' width='640' height='400' border='0' /></div>"; 

	filmOpen = "<div class='myMovieContainer'>"
	+ "<div class='vChromeTopRow'><table  border='0' cellspacing='0' cellpadding='0'><tr>\n"
	+ "<td><img src='images/popups/video_chrome/tl1.gif' alt='' width='49' height='59' border='0'></td>\n"
	+ "<td><img src='images/popups/video_chrome/tl2.gif' alt='' width='274' height='59' border='0'></td>\n"
	+ "<td width='100%' class='vChromeTop'><img src='images/popups/video_chrome/tc.gif' alt='' width='2' height='59' border='0'></td>\n"
	+ "<td><img src='images/popups/video_chrome/tr_close.gif' alt='' width='325' height='59' border='0' usemap='#tr_close_map'></td>\n"
	+ "</tr></table></div>\n"
	+ "<div class='vChromeLeftBG'><div class='vChromeLeft'><div class='vChromeRightBG'><div class='vChromeRight'>\n"
	+ "<div class='myMovie'>"+myMovieCode+"</div><!-- end myMovie -->\n"
	+ "<div class='vChromeInnerContainer'>\n"
	+ "<!-- begin video text -->\n";

	filmClose = "<!-- end video text -->\n"
	+ "</div></div></div></div></div><div class='clear'></div></div>\n"
	+ "<div class='vChromeBottomRow'><table  border='0' cellspacing='0' cellpadding='0'><tr>\n"
	+ "<td><img src='images/popups/video_chrome/bl.gif' alt='' width='49' height='31' border='0'></td>\n"
	+ "<td width='100%' class='vChromeBottom'><img src='images/popups/video_chrome/bc.gif' alt='' width='1' height='31' border='0'></td>\n"
	+ "<td><img src='images/popups/video_chrome/br.gif' alt='' width='51' height='31' border='0'></td>\n"
	+ "</tr></table></div>\n"
	+ "<map name='tr_close_map'><area  id='trCloseMap'   href='javascript:return false;' onclick='self.parent.tb_remove();location.href=this.href;return false;'       shape='poly' title='Close' alt='Close' coords='228,24,231,14,236,6,243,1,246,0,300,0,305,3,308,8,309,13,310,38,302,32,293,29,274,27'></map>\n";

	filmInfo = "<div class='movieInfo'>\n"
	+ "<div class='gameName'>" + gameName + "</div><!-- end game name -->\n" 
	+ "<div class='gameCreator'>By: " + gameCreator + ", " + gameLocation + "</div><!-- end creator/location -->\n" 
	+ "<div class='gameDescription'>" + gameDescription + " <div class='gameEquipment'><i>Equipment:</i> " + gameEquipment + "</div></div><!-- end game description -->\n" ;
	+ "</div><!-- end movieInfo -->\n";
	
	canvas = filmOpen + filmInfo + externalTrackingScript + internalTrackGIF + filmClose +"</div><!-- end myMovieContainer -->";

	canvas = (debug) ?  showDebugInfo(canvas)  : canvas;

	document.getElementById("controlBox").innerHTML=canvas;

	}

// -----------------------------------


// prefs for generating tr.gif

var imageName = "images/global/tr.gif"

var stageWidth = 360;
var stageHeight = 445;

var pinLength = 50;
var prefix="xtreme_";
var showFullName=false;

var characters = "abcdefghijklmnopqrstuvwxyz0123456789";
var allChars = characters.length;
// parameters
var prmoParameterName = "prmo";
var pageParameterName = "page";
var trackingParameterName = "SID";
var trackDIV1 ='<div class="trackDIV">';
var trackDIV2 ='<\/div>';

// turn the tracking on and off (if you need to)
var trackPages = true;

// if you want track subdirectory and page name as 
// separate parameters make true.
var trackParametersSeparately = true;

// to view output from this js make this true 
// makes html visible as text instead of rendering the html
// to implement this, put on separate page rather than a live page
var traceParameter = false;

// if you want upper and lower case letters in the code
var upperAndLowerCase = true;



// -----------------------------------


function  createAlreadyVoted(  )
	{
	$("#TB_window").remove();
	$("body").append("<div id='TB_window'></div>");
	trackGIF = dynamicGIF("oops_youve_already_voted");
	var error = '<div class="bigCircleVoted">' 
	+ '<div class="buttonClose"><a href=\"#\" onclick=\"self.parent.tb_remove(); return false;\" ><img src="images/popups/button_close.gif" alt="" width="59" height="25" border="0"></a></div>' 
	+ '<div class="goldfishfun"><a class="goldfishLink" href="http://www.goldfishfun.com/" target="_blank"></a></div>' 
	+ 'already voted</div>'
	+ trackGIF;

	error = (debug) ? showDebugInfo(error)   : error;

	document.getElementById("controlBox").innerHTML=error;
	
//	prepPage();
	
	u= "#TB_inline?height=300&width=300&inlineId=controlBox&modal=true";
	tb_show("", u, "")   ; 
	}


// -----------------------------------


function createThankYou(  )
	{

	$("#TB_window").remove();
	$("body").append("<div id='TB_window'></div>");
	trackGIF = dynamicGIF("thanks_for_voting");
	var thanks= "<div class=\"bigCircle\">"
	+ "<div class=\"buttonClose\"><a href=\"#\" onclick=\"self.parent.tb_remove(); resetVote(); return false;\" ><img src=\"images/popups/button_close.gif\" alt=\"\" width=\"59\" height=\"25\" border=\"0\"></a></div>"
	+ "<div class=\"goldfishfun\"><a class=\"goldfishLink\" href=\"http://www.goldfishfun.com/\" target=\"_blank\"></a></div>"
	+ "</div>"
	+ trackGIF
	+ '<script language="JavaScript" src="http://view.atdmt.com/jaction/dengol_GoldfishGamesClickButtonNowF09_10"></script>'
	+ '<noscript><iframe src="http://view.atdmt.com/iaction/dengol_GoldfishGamesClickButtonNowF09_10" width="1" height="1" frameborder="0" scrolling="No" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0"></iframe></noscript>';
	//var thanks= "<a href=\"\"  onclick=\"self.parent.tb_remove();location.href=this.href;return false;\">THANK YOU</a>";
	
	thanks = (debug) ?  showDebugInfo(thanks)   : thanks;

	document.getElementById("controlBox").innerHTML =  thanks;
	
//	prepPage();
	
	u= "#TB_inline?height=300&width=300&inlineId=controlBox&modal=true";
	tb_show("", u, "")   ;
	}




// -----------------------------------


function createCaptcha()
	{
	$("#TB_window").remove();
	$("body").append("<div id='TB_window'></div>");
	var sed = Math&&Math.random?Math.floor(Math.random()*10000000000000):(new Date()).getTime();
	var captchawin= '<div class=\"bigCircleCaptcha\">'
	+ "<div class=\"buttonCloseCaptcha\"><a href=\"#\" onclick=\"self.parent.tb_remove(); return false;\"><img src=\"images/popups/button_close.gif\" alt=\"\" width=\"59\" height=\"25\" border=\"0\"></a></div>"
	+ "<div class=\"captchaImage\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td valign=\"top\"><img src=\"http://pepperidge.promotionexpert.com/PepperidgeGoldfishGames/ti?nehowma=221&leivviel=19132133847524&scrid=" + document.reg.scrid.value + "&rand=" + sed + "\" width=\"76\" height=\"17\" /></td><td valign=\"top\">&nbsp;&nbsp;<input type=\"text\" name=\"captchap\" id=\"captchap\" size=\"6\" maxlength=\"20\" style=\"font-size:12px;font-family:Arial;\" /></td></tr></table></div>"
//	+ "<div class=\"captchaImage\"><img src=\"http://pepperidge.promotionexpert.com/PepperidgeGoldfishGames/ti?nehowma=221&leivviel=19132133847524&scrid=" + document.reg.scrid.value + "&rand=" + sed + "\" width=\"76\" height=\"17\" />&nbsp;&nbsp;<input type=\"text\" name=\"captchap\" id=\"captchap\" size=\"6\" maxlength=\"20\" style=\"height:20px;\" /></div>"
	+ "<div class=\"submitCaptcha\"><a class=\"submitCaptchaLink\" href=\"#\" onclick=\"checkAll(document.reg); return false;\" title=\"Submit Vote\"></a>"
	+ "<a class=\"startOverCaptchaLink\" href=\"#\" onclick=\"self.parent.tb_remove(); resetVote(); return false;\" title=\"Start Over\"></a></div>"
	+ "</div>";
	captchawin = (debug) ?  showDebugInfo(captchawin)   : captchawin;

	document.getElementById("controlBox").innerHTML =  captchawin;

//	prepPage();
	
	u= "#TB_inline?height=400&width=400&inlineId=controlBox&modal=true";
	tb_show("", u, "")   ;
	}




// -----------------------------------


function generatePin(pl)
	{ var p="";
	for(x=0;x<pl;x++)
		{
		character = characters.substr( rand(allChars), 1);
		p+= (rand(2) && upperAndLowerCase ) ?  character.toUpperCase() : character;
		}
	return prefix + p;
	}


// -----------------------------------


function dynamicGIF(whichPop)
	{
	pl = pinLength;
	whichPop =  (whichPop) ? "&amp;whichFishViewed="+whichPop : "";
	var theGIF = "";	
	gif1='<img src="'+imageName;
	gif2 = 	'" width="1" height="1" border="0" />';
	if (traceParameter)
		{   
		gif1 = gif1.replace(/^</,"&lt;");
		gif2 = gif2.replace(/>$/,"&gt;");
		trackDIV1 = trackDIV1.replace(/^</,"&lt;"); trackDIV1 = "<br />"+trackDIV1.replace(/>$/,"&gt;");
		trackDIV2 = trackDIV2.replace(/^</,"&lt;"); trackDIV2 = trackDIV2.replace(/>$/,"&gt;");
		}

	if ( trackPages )
		{
		var ranNum = generatePin(pl);
		var trackInfo = "";
		var temp = location.href;
		// first chop off extra parameters
		// theHREF = url - data parameters
		var theHREF = temp.indexOf('?') > -1 ? temp.substring( 0,temp.indexOf('?')) : temp;
		
		// x = url - parameters - filename
		// then chop off everything to the right of the last slash '/'
		// this chops off the file name
		var x = theHREF.lastIndexOf('/') > -1 ? theHREF.substring(0,theHREF.lastIndexOf('/')) : theHREF;
		var paramVal = "";
		// if tracking the directory and the filename separately
		if (trackParametersSeparately)
			{
			// now using 'x' can determine the root directory of the prmo
			var subDirectory = prmoParameterName + "=" + escape( (x.lastIndexOf('/') > -1 ? x.substring(x.lastIndexOf('/')+1) : x) );
			// using original 'theHREF' parameter
			// can grab the file name
			if (theHREF.lastIndexOf('/') > -1)  { paramVal = (theHREF.lastIndexOf('.') > -1 && theHREF.lastIndexOf('.') > theHREF.lastIndexOf('/')) ? theHREF.substring(theHREF.lastIndexOf('/')+1, theHREF.lastIndexOf('.')) : theHREF.substring(theHREF.lastIndexOf('/')+1); }
			else { paramVal = theHREF; }
			var prmoPage = pageParameterName + "=" + escape( paramVal );
			trackInfo = subDirectory + "&amp;" + prmoPage;
			}
		// if tracking directory and filename as one parameter
		// use 'theHREF' just grab file name and directory that contains it
		else 
			{ 
			if (x.lastIndexOf('/') > -1) { paramVal = (theHREF.lastIndexOf('.') > -1 && theHREF.lastIndexOf('.') > x.lastIndexOf('/')) ? theHREF.substring( x.substring(0,x.lastIndexOf('/')+1).length , theHREF.lastIndexOf('.')) : theHREF.substring( x.substring(0,x.lastIndexOf('/')+1).length); }
			else { paramVal = theHREF; }
			trackInfo = prmoParameterName + "="+ escape( paramVal );
			}
		var trackingNumber = trackingParameterName  + "=" + ranNum;
		theGIF = trackDIV1 + gif1 + "?" + trackInfo + whichPop + "&amp;" + trackingNumber + gif2 + trackDIV2;
		}
	//else { theGIF = gif1 +  gif2; }
	return theGIF;
	}

function parseQueryString(arg)
	{
	var _d = document.location.toString();
	if(_d.indexOf("?")>0)
		{
		var _e = _d.split("?")[1];
		var _parms = new Array();
		var _valus = new Array();
		// parameters must have a &
		var _f = _e.split("&");
		for(var i=0;i<_f.length;i++) 
			{
			if(_f[i].split("=")[0] == arg)
				{
		  		var qval = _f[i].split("=")[1];
		  		var qval_idx = qval.indexOf("#");
		  		if (qval_idx > -1)  { qval = qval.substring(0, qval_idx); }
				return unescape(qval.replace(/\+/," "));
				}
			}
		}
	return "";
	}

// The Central Randomizer 1.3 (C) 1997 by Paul Houle (paul@honeylocust.com)
// See:  http://www.honeylocust.com/javascript/randomizer.html
// real number: rnd();       integer: rand(someNumber)
rnd.today=new Date();
rnd.seed=rnd.today.getTime();
function rnd() { rnd.seed = (rnd.seed*9301+49297) % 233280; return rnd.seed/(233280.0); };
function rand(number) { return Math.floor(rnd()*number); }


function showDebugInfo(whichPop)
	{
	debugCanvas = "<div class='movieInfo'><textarea class='debug'>" + whichPop + "</textarea>"+closeWindow +"</div>";
	return debugCanvas;
	}
