
//displays main game table
function system(thumbnail, title, description, price, buyNowURL) {
	this.thumbnail = thumbnail
	this.title = title;
	this.description = description;
	this.price = price; //no dollar sign
	this.buyNowURL = buyNowURL; 
	
}


var leftIndex = 0;
var rightIndex; //starting point for right column of table
var foo; //constant for rightIndex so it doesn't get changed within the for loop


//calculate where to start the right column at
function calculateColumns(arrayName) {
	if(arrayName.length%2 == "0") {
		rightIndex = arrayName.length/2; //list is symmetrical
	} else {
		rightIndex = (Math.ceil(arrayName.length/2)); //game list is odd - left side will be one item longer
	}
	foo = rightIndex;	
}
	

function displaySystemTable(arrayName) {
	calculateColumns(arrayName);
	
	//set up overall width and force column widths
	document.write('<table width="800" border="0" cellspacing="0" cellpadding="0" align="center">');
	document.write('<tr>');
	document.write('<td width="375"><img src="shim.gif" width="375" height="1"></td>');
	document.write('<td width="50"><img src="shim.gif" width="50" height="1"></td>');
	document.write('<td width="375"><img src="shim.gif" width="375" height="1"></td>');
	document.write('</tr>');

	//write out each row
	for(leftIndex; leftIndex<foo; leftIndex++) {
		document.write('<tr>');
		document.write('<td valign="top" align="left" style="padding-top:5px;padding-bottom:15px;">' + writeSystem(arrayName[leftIndex]) + '</td>');
		document.write('<td>&nbsp;</td>');
		document.write('<td valign="top" align="left" style="padding-top:5px;padding-bottom:15px;">' + writeSystem(arrayName[rightIndex]) + '</td>');
		document.write('</tr>');
		rightIndex++
	}			
	document.write("</table>");
	
	//reset vars
	leftIndex=0;
	rightIndex=0;
	
}

var allSystems = "";

function writeSystem(system) {
	var returnString = "";
	if(system) {
		if(system.buyNowURL != "") {
			returnString = "<table border='0'><tr><td valign='top' width='150'><img src='" + system.thumbnail + "' align='right'></td><td><img src='images/shim.gif' width='10'></td><td align='left'><span style='color:#76b900;font-weight:bold'>" + system.title + "</span><br>" + system.description + "<br><span style='color:#76b900;font-weight:bold'>System Price: $" + system.price + "</span><br><br><a href='" + system.buyNowURL + "' name='&lid=pv_" + system.title.replace(/ /g,"_") + "' target='_new'><img src='images/buy_now.jpg' border='0'></a></td></tr></table>";
		    allSystems +=  "\n\n\n" + returnString;
		} else {
			returnString = "<table><tr><td valign='top' width='150'><img src='" + system.thumbnail + "' align='right'></td><td><img src='images/shim.gif' width='10'></td><td><span style='color:#76b900;font-weight:bold'>" + system.title + "</span><br>" + system.description + "<br><span style='color:#76b900;font-weight:bold'>Price: $" + system.price + "</span>";
		}
	} else { //no more items in array, create an empty cell so the table doesn't break 
		returnString = '&nbsp;';
	} 	
	return returnString;	
}



