var gameTitle = '';
var gameAuthor = '';
var gameDescription = '';
var gameWidth = 0;
var gameHeight = 0;
var gameLink = '';
var gameID = 0;
var bgcolor = "#000000";
var version = '0';
var marginDifference = 30;
var showComments = false;
var allowScriptAccess = "sameDomain";
var gameHost = '';

function setGameVars(theGameID) {
	switch(theGameID) {
		case 1:
		case "1":
			gameTitle = 'The Desert Obelisk';
			gameAuthor = 'Cirr';
			gameDescription = 'A small robot and a floating fish happen upon an ancient empty stone obelisk in the middle of a desert. The two decide to see if they can make it do something.';
			gameLink = '';
			gameWidth = 600;
			gameHeight = 500;
			allowScriptAccess = "sameDomain";
			gameHost = 'thedesertobelisk';
			bgcolor = "#000000";
			version = '1';
			break;
		case 2:
		case "2":
			gameTitle = 'Doggnation';
			gameAuthor = 'Bart Bonte';
			gameDescription = 'Once upon a time there was a peaceful nation of \'doggs\'. They were living in a small castle that could use a little upgrade. Will you help these doggs to upgrade their castle?';
			gameLink = 'http://www.bontegames.com';
			gameWidth = 700;
			gameHeight = 460;
			allowScriptAccess = "sameDomain";
			gameHost = 'doggnation';
			bgcolor = "#000000";
			version = '1';
			break;
		case 3:
		case "3":
			gameTitle = 'Gride';
			gameAuthor = 'ooPixel<br />(Jussi Kari, Marko Taali)';
			gameDescription = 'Select your upgrades timely and be the king of the hill.';
			gameLink = 'http://www.oopixel.com';
			gameWidth = 640;
			gameHeight = 360;
			allowScriptAccess = "always";
			gameHost = 'gride';
			bgcolor = "#000000";
			version = '2';
			break;
		case 4:
		case "4":
			gameTitle = 'Unit 149';
			gameAuthor = 'Hurgle Studios';
			gameDescription = 'A futuristic survival-shooter with an upgradable hero... and upgrading foes.';
			gameLink = 'http://hurgle.com';
			gameWidth = 500;
			gameHeight = 500;
			allowScriptAccess = "sameDomain";
			gameHost = 'unit149';
			bgcolor = "#000000";
			version = '1';
			break;
		case 5:
		case "5":
			gameTitle = 'The Last Canopy';
			gameAuthor = 'Easy Only! Games<br />feat. Aidi and Dzaid';
			gameDescription = 'In this unique shooter, a baby bird falls from the last standing tree on Earth. Battle against the human race by absorbing their attacks to make them your own, all while carrying the poor birdie back to her nest.';
			gameLink = 'http://www.easyonlygames.com';
			gameWidth = 640;
			gameHeight = 480;
			allowScriptAccess = "sameDomain";
			gameHost = 'thelastcanopy';
			bgcolor = "#FFFFFF";
			version = '3';
			break;
		case 6:
		case "6":
			gameTitle = 'Tricked Out Trailer';
			gameAuthor = 'Jorge Goyco';
			gameDescription = 'Make enough money to buy upgrades for your trailer by going to work at the beer factory, pawning something, playing poker, shooting beers or scratch-and-win cards.';
			gameLink = 'http://www.goycodesign.com/games.htm';
			gameWidth = 550;
			gameHeight = 400;
			allowScriptAccess = "sameDomain";
			gameHost = 'trickedouttrailer';
			bgcolor = "#000000";
			version = '2';
			break;
		case 7:
		case "7":
			gameTitle = 'Up Bug';
			gameAuthor = 'Jorge Goyco';
			gameDescription = 'The MechaBug Company needs you to test pilot their new equipment. Successfully gather fuel and avoid damaging the ship to be upgraded to a higher clearance machine.';
			gameLink = 'http://www.goycodesign.com/games.htm';
			gameWidth = 300;
			gameHeight = 300;
			allowScriptAccess = "sameDomain";
			gameHost = 'upbug';
			bgcolor = "#FFFFFF";
			version = '2';
			break;
		case 8:
		case "8":
			gameTitle = 'Terra Defense';
			gameAuthor = 'Justin Poel';
			gameDescription = 'Save the Earth from an onslaught of asteroids!  Collect raw material to upgrade your gun and save the planet from certain destruction.';
			gameLink = 'http://www.doubleedgegames.com';
			gameWidth = 600;
			gameHeight = 500;
			allowScriptAccess = "sameDomain";
			gameHost = 'terradefense';
			bgcolor = "#000000";
			version = '1';
			break;
		case 9:
		case "9":
			gameTitle = 'MECI';
			gameAuthor = 'drMikey';
			gameDescription = 'The MECI system has pulled you out of cryo-sleep early, requesting an urgent upgrade to a deep space asteroid mining platform. Your rover will need upgrades to complete the mission, but nothing too serious, right?';
			gameLink = 'http://www.drmikey.com';
			gameWidth = 700;
			gameHeight = 400;
			allowScriptAccess = "sameDomain";
			gameHost = 'meci';
			bgcolor = "#000000";
			version = '1';
			break;
		case 10:
		case "10":
			gameTitle = 'Pieces';
			gameAuthor = 'SoybeanSoft';
			gameDescription = 'Proo crashed lands on a strange place and needs to get home. But she lost her memory and all the skills she once knew. Guide her by exploring this strange place to recollect pieces of her memory and spacecraft.';
			gameLink = '';
			gameWidth = 510;
			gameHeight = 480;
			allowScriptAccess = "sameDomain";
			gameHost = 'pieces';
			bgcolor = "#000000";
			version = '5';
			break;
		case 11:
		case "11":
			gameTitle = 'Numbers Reaction 2';
			gameAuthor = 'Freebreakgames.com';
			gameDescription = 'An action packed puzzle to start chain reactions and explode as many bubbles as possible. Many levels of complexity that need to be figured out to choose the bubble that will bring you victory and eternal glory.';
			gameLink = 'http://freebreakgames.com';
			gameWidth = 700;
			gameHeight = 500;
			allowScriptAccess = "sameDomain";
			gameHost = 'numbersreaction2';
			bgcolor = "#000000";
			version = '1';
			break;
		case 12:
		case "12":
			gameTitle = 'BFD<br />(Bovine Flatulent Defense)';
			gameAuthor = 'Dan Black';
			gameDescription = 'You play as a dairy farmer at a time when aliens are invading, and officials have found that the only thing effective in killing them is the raw materials of cow fart.';
			gameLink = '';
			gameWidth = 700;
			gameHeight = 500;
			allowScriptAccess = "sameDomain";
			gameHost = 'bfd';
			bgcolor = "#000000";
			version = '3';
			break;
		case 13:
		case "13":
			gameTitle = 'Pen Fight';
			gameAuthor = 'Kunal';
			gameDescription = 'Knock the other pens off the table. Up to 3 AI opponents can be added. Last pen standing wins the round. Upgrade your power, or length at the end of each round.';
			gameLink = 'http://www.freewebs.com/kunaljoshi';
			gameWidth = 650;
			gameHeight = 550;
			allowScriptAccess = "sameDomain";
			gameHost = 'penfight';
			bgcolor = "#000000";
			version = '2';
			break;
		case 14:
		case "14":
			gameTitle = 'Neo Tower Defense';
			gameAuthor = 'Justin Nelson';
			gameDescription = 'Neo Tower Defence is a tower defence game loosely based off the space sim Allegiance. It features a wide variety of towers and support buildings along with a complex research system.';
			gameLink = '';
			gameWidth = 700;
			gameHeight = 500;
			allowScriptAccess = "sameDomain";
			gameHost = 'neotowerdefense';
			bgcolor = "#000000";
			version = '2';
			break;
		case 15:
		case "15":
			gameTitle = 'Super Energy Apocalypse';
			gameAuthor = 'Lars A. Doucet';
			gameDescription = 'The world is in ruins. Rebuild civilization with sustainable energy choices, then fight off the rampaging zombie alien hordes.';
			gameLink = 'http://www.fadupinator.com';
			gameWidth = 800;
			gameHeight = 600;
			allowScriptAccess = "sameDomain";
			gameHost = 'superenergyapocalypse';
			bgcolor = "#000000";
			version = '5';
			break;
		case 16:
		case "16":
			gameTitle = 'Orbash';
			gameAuthor = 'Wylie Conlon';
			gameDescription = 'Defend yourself from the enemies that are trying to shrink you. Get the highest score possible through strategic upgrades! Mouse to move, click to pause. Defend the gray orb at all costs.';
			gameLink = '';
			gameWidth = 515;
			gameHeight = 515;
			allowScriptAccess = "sameDomain";
			gameHost = 'orbash';
			bgcolor = "#000000";
			version = '2';
			break;
		case 17:
		case "17":
			gameTitle = 'dRive';
			gameAuthor = 'Twig Games';
			gameDescription = 'Create your own glitch music in this experimental dodging game. Collect points to upgrade your tracks and control up to three ships at once!';
			gameLink = 'http://www.twiggames.com';
			gameWidth = 500;
			gameHeight = 500;
			allowScriptAccess = "sameDomain";
			gameHost = 'drive';
			bgcolor = "#CCCCCC";
			version = '2';
			break;
		case 18:
		case "18":
			gameTitle = 'M.I.L.O.';
			gameAuthor = 'Studio Cypher';
			gameDescription = 'Guide M.I.L.O. through a dangerous factory as he attempts to discover his creator\'s birthday surprise...';
			gameLink = 'http://www.studiocypher.com';
			gameWidth = 760;
			gameHeight = 480;
			allowScriptAccess = "sameDomain";
			gameHost = 'milo';
			bgcolor = "#000000";
			version = '1';
			break;
		case 19:
		case "19":
			gameTitle = 'GearUP!';
			gameAuthor = 'Zack Hicks';
			gameDescription = 'Upgrade your offense and defense as a gear while your enemies upgrade themselves to fight you!';
			gameLink = 'http://zackhix.net';
			gameWidth = 700;
			gameHeight = 400;
			allowScriptAccess = "sameDomain";
			gameHost = 'gearup';
			bgcolor = "#41372E";
			version = '2';
			break;
		case 20:
		case "20":
			gameTitle = 'R.O.B.O.T.<br />Relatively Obedient Being Of Thought';
			gameAuthor = 'Marauder Interactive';
			gameDescription = 'KX-3700 robots have been decommissioned and are marked for termination. All of your brethren have fallen and you are the last one. You\'re programmed to survive, and to fight till the very end.';
			gameLink = '';
			gameWidth = 800;
			gameHeight = 600;
			allowScriptAccess = "sameDomain";
			gameHost = 'robot';
			bgcolor = "#000000";
			version = '3';
			break;
		case 21:
		case "21":
			gameTitle = 'Robert Plank';
			gameAuthor = 'Team Doli';
			gameDescription = 'Join Robert Plank as he makes his way across surreal terrains collecting cubes to upgrade to new levels. Make use of special items to reach hard to reach places and knock out pesky enemies.';
			gameLink = 'http://www.aquigriffin.com';
			gameWidth = 640;
			gameHeight = 480;
			allowScriptAccess = "sameDomain";
			gameHost = 'robertplank';
			bgcolor = "#000000";
			version = '3';
			break;
		default: 
			gameLink = '';
			gameWidth = 550;
			gameHeight = 400;
	}
}

function loadGame(theGameID) {
	$("div#game-floater").width(gameWidth).height(gameHeight+25);
	if(gameLink != '')
		linkstr='<a href="'+gameLink+'" target="_blank">'+gameAuthor.replace('<br />', ' ')+'</a>';
	else linkstr = gameAuthor.replace('<br />', ' ');
	$("div.game-header").html('<h3>"'+gameTitle.replace('<br />', ' ')+'" by '+linkstr+'</h3>').width(gameWidth).fadeIn("slow");
	$("div.game-control").css({"margin-left":(gameWidth-26)+"px"});
	$("div.game-control").fadeIn("slow");
	$("div.game-inner")[0].innerHTML = getFlashObject(theGameID);
}

function unloadGame() {
	$("div.game-header").fadeOut("fast");
	$("div.game-control").fadeOut("fast");
	$("div.game-inner")[0].innerHTML = " ";
}

function setGameInfo(theGameID) {
	idStr = (theGameID < 10)? "0"+theGameID:theGameID;
	linkStr = (gameLink == '')? '':'<img alt="save swf icon" class="bullet-icon" src="images/house.png" width="16" height="16" /><a href="'+gameLink+'" target="_blank">Visit authors\' website</a>';
	hostStr = (gameHost == '')? '':'<br /><img alt="save swf icon" class="bullet-icon" src="images/disk.png" width="16" height="16" /><a href="downloads/download.php?filename='+gameHost+'" target="download" onclick="OpenJBWindow(\'\',\'download\',550,400)">Host this game on your site</a>';
	// add the link for Audience prize voting
	//voteStr = '<form action="https://www.paypal.com/cgi-bin/webscr" method="post"><input type="hidden" name="cmd" value="_xclick"><input type="hidden" name="business" value="paypal@casualgameplay.com"><input type="hidden" name="item_name" value="JIG Casual Gameplay Design Competition #5 (&quot;'+gameTitle.replace('<br />', ' ')+'&quot;)"><input type="hidden" name="item_number" value="'+idStr+'CGDC5"><input type="hidden" name="no_shipping" value="1"><input type="hidden" name="return" value="http://jayisgames.com/cgdc5"><input type="hidden" name="cancel_return" value="http://jayisgames.com/cgdc5"><input type="hidden" name="cn" value="Thank you for voting! =)"><input type="hidden" name="currency_code" value="USD"><input type="hidden" name="tax" value="0"><input type="hidden" name="lc" value="US"><input type="hidden" name="bn" value="PP-DonationsBF"><input type="image" class="vote-img" src="images/vote.png" border="0" name="submit" alt="Make payments with PayPal - it\'s fast, free and secure!"><img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"></form>';
	voteStr="";
	outstr = '<div id="info-right"><img alt="'+gameTitle+'" name="'+gameTitle+'" id="screenshot" src="images/game'+theGameID+'_lg.png" width="200" height="200" />';
	outstr += '<img alt="Play this game" src="images/playbutton.png" id="playbtn" width="202" height="70" /></div>';
	outstr += '<div id="info-left"><span class="game-title">'+gameTitle+'</span><br />by <span class="game-author">'+gameAuthor+'</span><br /><span class="game-description">'+gameDescription+'</span><br /><span class="game-link">'+linkStr+'<br /><img alt="save swf icon" class="bullet-icon" src="images/email.png" width="16" height="16" /><a href="tellafriendform.php?gameID='+gameID+'" target="page" onclick="OpenJBWindow(\'\',\'page\',550,400)">Send this game to a friend</a>'+hostStr+voteStr+'</span></div>';
	$("div#rightpanel")[0].innerHTML = outstr;
	$("#comments-frame").attr("src","cgdc5_"+idStr+"_comments.php");
	$("#comments-frame").fadeIn();
	setPlayButtonEvents();
}

function setPlayButtonEvents() {
	$("img#playbtn").click(function() {
		playGame();
	});
	$("img#playbtn").mouseover(function() {
		$(this).css({"cursor":"pointer"});
	});
	$("img#playbtn").mouseout(function() {
		$(this).css({"cursor":"auto"});
	});
}

function playGame() {
	divheight = gameHeight + marginDifference;
	$("div#game-container").animate({ 
        height: divheight+"px"
      }, 1000,
		 'easeOutBounce',
 		 function() {loadGame(gameID);}
	);
	return false;
}
function cgdc5close() {
	flash = (navigator.appName.indexOf("Microsoft") != -1) ? window['game'] : document['game'];
	flash.answer();
	unloadGame();
	animateClose();
}

function cgdc5open() {
	flash = (navigator.appName.indexOf("Microsoft") != -1) ? window['cgdc5_sponsors'] : document['cgdc5_sponsors'];
	flash.answer();
	$("#sponsor-intro").hide();
	$("#leftpanel").fadeIn();
	if(directPlay) {
		iconClick($("img.selected"));
	} else $("#rightpanel").fadeIn();

}

function animateClose() {
	divheight = 0;
	$("div#game-container").animate({ 
        height: divheight+"px"
      }, 1000,
		 'easeOutBounce'
	);
}

function closeGame() {
	unloadGame();
	animateClose();
	return false;
}

function showGameInfo() {
	setGameVars(gameID);
	setGameInfo(gameID);
	$("#rightpanel").fadeIn();
	if(directPlay) {
		playGame();
		directPlay = false;
	}
}

function getFlashObject(gameID) {
	return AC_FL_RunContent(
			'ver', version,
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
			'width', gameWidth,
			'height', gameHeight,
			'src', 'http://cgdc5.fizzlebot.com/game'+gameID,
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'window',
			'devicefont', 'false',
			'id', 'game',
			'bgcolor', bgcolor,
			'name', 'game',
			'menu', 'false',
			'allowFullScreen', 'true',
			'allowScriptAccess', allowScriptAccess,
			'movie', 'http://cgdc5.fizzlebot.com/game'+gameID,
			'salign', ''
			); //end AC code
}
function iconClick(me) {
	id=$(me).attr("alt").substr($(me).attr("alt").lastIndexOf(" ")+1);
	if(id != gameID) {
		if(!showComments) {
			$("#rightpanel").fadeOut("fast");
			$("#floatingdiv-bottom").animate({ 
		        height: "750px"
		      }, 1000,
				 'easeOutBounce',
				showGameInfo
			);
			$("#leftpanel").animate({ 
		        height: "690px"
		      }, 1000,
				 'easeOutBounce'
			);
		}
		$("img.selected").removeClass("selected");
		$(me).addClass("selected");
		gameID = id;
		if(showComments) showGameInfo();
		else showComments = true;
	}
}
function OpenJBWindow(theURL,winName,theWidth,theHeight) {
	if(theWidth > screen.width || theHeight > (screen.height-25)) {
		OpenJFSWindow(theURL,winName);
	} else {
		window.open(theURL,winName,'width='+theWidth+',height='+theHeight+',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,top='+((screen.height/2)-(theHeight/2))+',left='+((screen.width/2)-(theWidth/2))+'');
	}
}
function OpenJFSWindow(theURL,winName) {
	var x=Math.min(screen.width,1200);
	var y=Math.min(screen.height-25,840);
	window.open(theURL,winName,'width='+x+',height='+y+',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,top=0,left=0');
}
$(document).ready(function(){
	var quirksMode = (top == self);
	if (!quirksMode) top.location.href = 'http://jayisgames.com/cgdc5';
	$("#comments-frame").hide();
	$("img.gamebtn").click(function() {
		iconClick(this);
		return false;
	});
	$("#closebtn").hover(
		function() {
		  $(this).addClass("closebtn-over");
		},
		function() {
		  $(this).removeClass("closebtn-over");
		}
	);
	$("#closebtn").click(function() {
		if(confirm("Are you sure you want to quit?")) closeGame();
		return false;
	});
});
