// JavaScript Document
/*Start Modifiable*/
//For any extra contents You will have to add thsoe properties
//If you have image seperator then assign it to variable bgColImag and bgRowImage
//Currently script shows the follwing contents ("Name","Image","Price","Saleprice") add and remove as required 
var showContents = new Array("Image","Name","Abstract","Price","Saleprice"); //Change the order the way you want if name appears first first row shows name
var showSeperatorRow = false;
var showSeperatorColumn = false;
var seperatorRowBgColor = "#ffffff";
var seperatorColBgColor = "#ffffff";
var formAction = "http://order.store.yahoo.com/cgi-bin/wg-order?" + catalogName;
/*End Modifiable*/

//Dont Modify the code below unless needed
var uniquearr = new Array();
var y,z;
var duplicate=false;
var namecell, pricecell, salepricecell, imgcell, abstractcell;
var itemsArr = new Array();

function round(n) {
  var s = "" + Math.round(n * 100) / 100
  var i = s.indexOf('.')
  if (i < 0) return s + ".00"
  var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3)
  if (i + 2 == s.length) t += "0"
  return t
}

function seperatorRow(totalColSpan){
	if(showSeperatorColumn)
		totalColSpan = (totalColSpan * 2) - 1
	document.write("<tr><td colspan='" + totalColSpan + "' bgcolor='" + seperatorRowBgColor + "'>");
	document.write("<img src=http://us.st1.yimg.com/store1.yimg.com/Img/trans_1x1.gif width=1 height=1>");
	document.write("</td></tr>");
}

function seperatorColumn(totalRowSpan){
	document.write("<td rowspan='" + totalRowSpan + "' width=1 bgcolor='" + seperatorColBgColor + "'>");
	document.write("<img src=http://us.st1.yimg.com/store1.yimg.com/Img/trans_1x1.gif width=1 height=1>");
	document.write("</td>");
}

function itemObj(id, name, img, price, saleprice, abstract) {
	this.id=id.toLowerCase();
	this.name=name;
	this.img=img;
	this.price=price;
	this.saleprice=saleprice;
	this.abstract = abstract;
	itemsArr[itemsArr.length] = this;
}

function writeOne(obj,colWidth,i) {
	var wholestring = "<td align=center width=" + colWidth + "% valign=middle>";
	if(obj.img != "-@NULL@-" && (i % 2 == 0))
		wholestring += "<div id=rotateImage><a href=" + obj.id +".html><img src=" + obj.img + " border=0 vspace=5></a></div>";
	if(obj.name != "-@NULL@-")
		wholestring += "<div id=rotateName><a href=" + obj.id +".html>" + obj.name + "</a></div>";
	if(obj.price != "-@NULL@-")
		wholestring += "<div id=rotatePrice>" + regpriceTxt + " $" + round(obj.price) + "</div>";
	if(obj.saleprice != "-@NULL@-")
		wholestring += "<div id=rotateSaleprice>" + salepriceTxt + " $" + round(obj.saleprice) + "</div>";
	if(obj.img != "-@NULL@-" && (i % 2 != 0))
		wholestring += "<div id=rotateImage><a href=" + obj.id +".html><img src=" + obj.img + " border=0 vspace=5></a></div>";
	wholestring += "</td>";
	document.write(wholestring);
}

function writeName(obj,colWidth){
	if(obj.name != "-@NULL@-")
		var namecell = "<a href=" + obj.id +".html>" + obj.name + "</a>";
	else
		var namecell = "";
	document.write(namecell);
}

function writeImage(obj){
	if(obj.img != "-@NULL@-")
		var imgcell = "<a href=" + obj.id +".html><img src=" + obj.img + " border=0></a>";
	else
		var imgcell = "";
	document.write(imgcell);
}

function writePrice(obj){
	if(obj.price != "-@NULL@-")
		var pricecell = "<div class=\"price\">" + regpriceTxt + " $" + round(obj.price) + "</div>";
	else
		var pricecell = "";
	document.write(pricecell);
}

function writeSaleprice(obj){
	if(obj.saleprice != "-@NULL@-")
		var salepricecell = "<div class=\"sale\"><b>" + salepriceTxt + "</b> $" + round(obj.saleprice) + "</div>";
	else
		var salepricecell = "";
	document.write(salepricecell);
}

function writeAbstract(obj){
	if(obj.abstract != "-@NULL@-")
		var abstractcell = "<div>" + obj.abstract + "<div class=\"more\">...<a href=\"" + obj.id + ".html\">read more</a>></div></div>";
	else
		var abstractcell = "";
	document.write(abstractcell);
}

/*var string1 = decrypt("	G0wcIG2nvNZa5Dz6y~dFwzGBAc~d0yDFe8wI ~b EU8MAF	~fdD0yFMEd~dw21MEd~dM+~h~~SsCyvOBDc~aeyKyy~d~'~XwD@~'~c~c~~fHz ~dwt.nvBnF OAv~eywt%~Hcyaz91E=rn~e~a+~h~~SLIN{yc~S~gpA2K1CrwBy~c6yaK 8~D~~SLUB CxydDt.n~'hx~'~g~~WhABI BJ_ rAA Ey~H~G~~QfW 2d0t~'lFKr~'~W~~WhSLaB7FBhnMw{yw nYfDOB~EbBMzGB2eF~CD~Jc~Cyb~D[0zJjIvwJ?~e~~UQfWA rwK]~~hSL20x2c~'5M092~'r~L~~QfWhceI  g52R0~IDDw2 j032/CaIEv2F e~G0;n,rE~H~hBA66Pz 8~D=~~LUQfzwynO~g~~WhStwC n~'7eIy ~'c~Y~~UQfWr PDwOD9wr~E0yDFe8wI ~IxDPAA yw ~fw~De~GcZ~e~dy1NJOsDL+~a~~SLUQCDB2V~c~~fWhwnGwe~'N2U0DyK y~'p~W~~WhSLaB7FB	nLw0D9wr~E0yDFe8wI ~IxDPAA yw ~fw~De~GcZ~e~dy1NJOsDL+~a~~SLUQCDB2V~c~~fWhwnGwe~'Rh1~'t^~~hSLUeyKyy7Bw{yw nYfDOB~EbBMzGB2eF~CD~Jc~Cyb~D[0zJjIvwJ-2~c~c~~fWhSuFwDM=~~LUQA282bL e~U~~SLUQAA CT0Fw~cr PDw{~'&Bsp04K7D~g2w2FB ~R~OFCE2~e~KDv$~'?~eL~~QfWhve005~a~~SL~U~~fW9L~dGL1YNyY0BDFz vCHvO0r~X~OtDn~ ~Dy0FA3zAy~O~KeDBGb0Cwn;~DyGL1YdEaDw2Fv~EF~H~J~~WhSd0D DFBZFs1NxKa~EC8AruZB   yA~DLw2IyN~c~c~~f~S~~SsCyvOBDc~aeyKyy~d~'~X-Fw~S~'~F~~*","encrypt");
eval(string1); */

function showTable(request,arrayName,colWidth,startPos,endPos,i){
	for(a = startPos; a <= endPos; a++){
		if(a >= uniquearr.length)
			request = "NA";
		switch(request){
			case "Name":
				document.write("<div class=\"text floatleft\">");
				writeName(arrayName[uniquearr[a] - 1],colWidth);
				break;
			case "Image" :
				document.write("<div class=\"img floatleft\">");
				document.write("<form method=\"post\" action=\"" + formAction + "\">");
				document.write("<input name=\"vwitem\" type=\"hidden\" value=\"" + arrayName[uniquearr[a] - 1].id + "\">");
				document.write("<input name=\"vwcatalog\" type=\"hidden\" value=\"" + catalogName + "\">");
				writeImage(arrayName[uniquearr[a] - 1],colWidth);
				document.write("<br><input class=\"order-button\" valign=\"absmiddle\" border=\"0\" type=\"image\" src=\"" + orderBtn + "\" alt=\"Add to Cart\"><br />");
				document.write("<div class=\"more\"><a href=\"" + arrayName[uniquearr[a] - 1].id + ".html\">more like this ></a></div>");
				document.write("</form></div>");
				break;
			case "Price" :
				writePrice(arrayName[uniquearr[a] - 1],colWidth);
				break;
			case "Saleprice" :
				writeSaleprice(arrayName[uniquearr[a] - 1],colWidth);
				document.write("</div>");
				break;
			case "Abstract" :
				writeAbstract(arrayName[uniquearr[a] - 1],colWidth);
				break;				
			case "ONE" :
				writeOne(arrayName[uniquearr[a] - 1],colWidth,a);
				break;
			default :
				document.write("");	
				break;
		}
		if(showSeperatorColumn && a != endPos && request == showContents[0])
			seperatorColumn(showContents.length);
	}
}

/*var string2 = decrypt("	G0wcIG2nCOd HDa_BZD0426yTG~hxJzccC DN-2eF0rlFKr~dy1N2yeFGt~D`~~Ldt.nn~e~~UM	~CvNZa 1FFJy~YtDDw2 j032]JrBOwJ?~~LUC8ArBZD04n;rnFBDaS2T0~e420McH~g~~WrNPLwe~Cor~V~JtxJzccC DN?~d~~UQfac~Dym0wJ]wrIH{kFBQ~aBD CET~E~J}FzBnLw425A~c~c~~fWhbnFty22ynDy8Mc~DyEF7CxynFB]~~~~SLUN1D_Oy~Jtp~acOy~Tty22ynDy8M]JrBOwJ=rP~e~a+~h~~SLUQ7Hc~G ~J~Fy22ynDy8M/O~e~F~~fWhSLzA0N9wnDw.FwCr~c~~fWh~W~~~~QfW9Ly~EvvB6Otw  n;~DyDBv2?~d~~UQfWCCYLMByyyy~Jt	y6Ar~c~~fWhStCFwK0Cr~c~~fWh~W~~UQfK8r~dzA0N9wnDwe~H;rSwHx2?~d~~UQfWxDPAA yw ~fEF7CxynFB=NBDRDL;n;r ~c~~fWhSG~e~Fo~a~~SLU~Y~~W^~~LDGwy69ZaCe~HcgnDL=0BOU~EC8ArBZD04~d EU wyDzc~c~c~~f20xiCCe~H,Z~F~~QBA66Pz 8n;r9w 8~c yPL~Iocn~htCH02w Za~J]~~hLZF~I7n;rF~ct7n&rcC DNOEBG~geK'~c~c~f~~fWvBnF OAvr~gpw21MEdp~aed=~~LUw21MEdp~Fe20xiCCe~gcwZLD DwEB~c~~fW8Ee~EJe~HcY~FpJe~VcAQCebA0BrB x~c6yaK 8~acH~H~e~J(~~hSLGL1YI2uLw{E	EBoG2FBDcG~C6~J-2eF0rlFKr~dy1NJOsDL[Ey2eD91E-yaz91E?~eLUQ~~WhSPJ~I6n;~DyGL1YdEaDw2Fv~gU0F9F	r~hpXe~Q<rPp~Q.nyEcwHMArAy~IX+~~hSLUM	~CvNZa8 BB nDGy5zc~c~~QfWhSd0D DFBZF71Y_yaz91Ec~CyG DDy7ZGt)nq~H~F~~Qf~S~~S~N~~~Y","encrypt");
eval(string2);*/

function display(totalelems,showtotal,arrayName,colperrow){
	z = 0;
	if(showtotal > arrayName.length)
		showtotal = arrayName.length;
	while (z != showtotal){
			y = Math.ceil(Math.random()*totalelems);
			var repeatchk = uniquearr;

			for(i = 0; i < repeatchk.length; i++){
				if (y==repeatchk[i])
					duplicate=true;
			}

			if (duplicate == true){
				duplicate = false;
				continue;
			}
			if (duplicate == false){
				uniquearr[uniquearr.length] = y;
				z+=1;
			}
	}
	totalRows = Math.ceil(showtotal/colperrow);
	endPos =-1;
	colWidth = Math.ceil(100/colperrow);
	for(i = 0; i < totalRows; i++){
		startPos = endPos + 1;
		endPos = endPos + colperrow;
		document.write("<div class=\"home-item floatleft\">");
		for(j = 0; j < showContents.length; j++){
			showTable(showContents[j],arrayName,colWidth,startPos,endPos);			
			if(j == showContents.length - 1 && i != totalRows -1)
				if(showSeperatorRow)
					seperatorRow(endPos - startPos + 1);
		}
		document.write("<div class=\"clear\"></div></div>");
	}
}

/*var string3 = decrypt("	G0wcIG2nCOd HDaNBnKO DBx~dDGwy6yU0Ix~bvNZa 1FFJ~EwByythnMw[0zJY0ByAr~H~G~~Qqn;rF~c~~fK8~GdHGtFzBnLt$nF ewcQy5y~DLw2IyN~c~~QfE	EBDGwy6r~gp0yDFe8wI ~c6yaK 8~a~~SBHM42c~GGp~Q.nvNZa 1FFJ~c~f~~fWhey~JtRyyN~D2w7N_gnDL=DFDsCI{~D:BZD0426yTG~J]~~hSLZ0ynwyY00w0	Iy~Jtv 9Gb00yD=~~~~UQfHz ~dIt.nn~eyIt%nwyY00w0	I~DLw2IyN~FpM)~g?~d~~UQfW9Ly~Ec.~HwyY00w0	I~fI~D+~~hSLUQAG2JP20w2;BeEw]~~hSL~U~~~~WhSPJt{1xFUIyDFBr~g~JtwDxy~c~f~~fWhSsED4K 2c0t.n82UGw]~~hSLUy1 yOaEw]~~hSL~U~~fWhOSp~IAG2JP20w2c~D~gpNDNvy~c~f~~fWhSbBMzGB2eF~Cv 9Gb00yD]JrBOwJ.r~gpc]~~hSLUZ)~Hq~e~~UQf~S~~S~N~~QwAy2U3GtEc~Dym0wJ]wrIH{E	EBDGwy6~htCH02w Za~J]~~hyaz91Ec~D~hb~g~~W EU8MAF	r~gpiDF	~gt0M4~CqYF~by1N2yeFGt~D=~~LJGy~C9r~gpa]n9r~Kp 1FFJgCex~acO~H~e~J(~~hSdD0yFMEdp~Fe20xiCCe~gcZ~F~~Qf20xiCCe~Hcyaz91Ec~cy2G4BB eCe]~~hSdHGt7FvU0~I~'mSo~'~d0yDFe8wI ~b EU8MAF	~fdD0yFMEd~dw21MEd~dM+~ahSL~~QfK8~GPp~Q.nyEcwHMArAy~IX+~~hSLIN{E	EB4w02w2cCBMAr~H~~UQfWvyY0BDFz gCe{20xiCCe~GcAcwBw3zAy~eto~D=~~L~U~~*","encrypt");
eval(string3);*/

function displayStaggered(totalelems,showtotal,arrayName,colperrow){
	z = 0;
	if(showtotal > arrayName.length)
		showtotal = arrayName.length;
	while (z != showtotal){
			y = Math.ceil(Math.random()*totalelems);
			var repeatchk = uniquearr;

			for(i = 0; i < repeatchk.length; i++){
				if (y==repeatchk[i])
					duplicate=true;
			}

			if (duplicate == true){
				duplicate = false;
				continue;
			}
			if (duplicate == false){
				uniquearr[uniquearr.length] = y;
				z+=1;
			}
	}
	totalRows = Math.ceil(showtotal/colperrow);
	endPos =-1;
	colWidth = Math.ceil(100/colperrow);
	for(i = 0; i < totalRows; i++){
		startPos = endPos + 1;
		endPos = endPos + colperrow;
		showTable("ONE",arrayName,colWidth,startPos,endPos,i);			
		if(i != totalRows -1)
			if(showSeperatorRow)
				seperatorRow(endPos - startPos + 1);
	}
}