var itemsArr = new Array();

function itemObj( id, name, img, price, saleprice ) {
	this.id = id.toLowerCase();
	this.name = name;
	this.img = img;
	this.price = price;
	this.saleprice = saleprice;
	itemsArr.push(this);
}

function drcImg( iObj ){
	if (iObj.img != "-@NULL@-") {
		document.write("<center><a href=\"" + iObj.id + ".html\"><img alt=\"" + iObj.name + "\" src=\"" + iObj.img + "\" /></a></center>");
	}
}

function drcInfo( iObj ){
	document.write("<div class=\"name\"><a href=\"" + iObj.id + ".html\">" + iObj.name + "</a></div>");
	if (iObj.price != "-@NULL@-") {
		document.write("<div class=\"price\">" + iObj.price + "</div>");
	}
	if (iObj.saleprice != "-@NULL@-") {
		document.write("<div class=\"sale-price\">" + iObj.saleprice + "</div>");
	}
}

function displayRandConts( num, iArr, cols ){
	if (iArr.length > 0) {
		num = (iArr.length < num)? iArr.length : num;
		cols = (cols > num)? num : cols;
		rows = Math.ceil(1.0 * num / cols);
		iArr = randArr(iArr, num);
		for (var i = 0; i < rows; i++) {
			var prevCells = i * cols;
			cols = ((prevCells + cols) > num)? num - prevCells : cols;
			document.write("<tr>");
			for (var g = 0; g < cols; g++) {
				var currItem = i * cols + g;
				document.write("<td class=\"img-cell\">");
				drcImg(iArr[currItem]);
				document.write("</td>");
				if (g < (cols - 1)) {
					document.write("<td class=\"table-spacer-vertical\" rowspan=\"2\"></td>");
				}
			}
			document.write("</tr><tr>")
			for (var g = 0; g < cols; g++) {
				var currItem = i * cols + g;
				document.write("<td>");
				drcInfo(iArr[currItem]);
				document.write("</td>");
			}
			document.write("</tr>");
			if (i < (rows - 1)) {
				document.write("<tr><td class=\"table-spacer-horizontal\" colspan=\"" + (cols * 2 - 1) + "\"></td></tr>");
			}
		}
	}
}

function randArr( iArr, num ) {
	var len = iArr.length;
	if (len > num) {
		if ((len / 2) > num) {
			var oArr = iArr;
			iArr = new Array();
			for (var i = 0, j = num; i < j; i++) {
				var ran = Math.floor(Math.random() * oArr.length);
				iArr.push(oArr[ran]);
				oArr.splice(ran,1);
			}
		} else {
			for (var i = 0, j = (len - num); i < j; i++) {
				var ran = Math.floor(Math.random() * iArr.length);
				iArr.splice(ran,1);
			}
		}
	}
	return iArr;
}
