// JavaScript Document
/*Start Modifiable*/
//Currently script shows the follwing contents ("Name","Image","Price","Saleprice") add and remove as required 
//For any extra contents You will have to add thsoe properties
//If you have image seperator then assign it to variable bgColImag and bgRowImage
var showContents = new Array("Image","Name","Price","Saleprice");
var regpriceTxt = "Price";
var salepriceTxt = "Sale Price";
var showSeperatorRow = true;
var showSeperatorColumn = false;
var seperatorRowBgColor = "#ffffff";
var seperatorColBgColor = "#ffffff";
/*End Modifiable*/
//Dont Modify the code below unless needed
var uniquearr = new Array();
var y,z;
var duplicate=false;
var namecell, pricecell, salepricecell, imgcell;
var itemsArr = new Array();

function seperatorRow( totalColSpan )
{
	if ( showSeperatorRow )
		document.write( '<div class="bestseller-separator"></div>' );
}

/*
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 )
{
	this.id                   = id.toLowerCase();
	this.name                 = name;
	this.img                  = img;
	this.price                = price;
	this.saleprice            = saleprice;
	itemsArr[itemsArr.length] = this;
}

function writeName( obj, colWidth )
{
	if ( obj.name != '-@NULL@-' )
		document.write( '<a href="' + obj.id + '.html"><img src="/lib/yhst-93621452108554/arrow.gif" class="bestseller-arrow" /></a><div class="bestseller-name"><a href="' + obj.id + '.html">' + obj.name + '</a></div>' );
}

function writeImage( obj )
{
	var image;
	if ( obj.img != '-@NULL@-' )
		image = '<a href="' + obj.id + '.html"><img alt="'+obj.name+'" src="' + obj.img + '" class="bestseller-image" /></a>';
	else
		image = '<div class="bestseller-image-placeholder"></div>';
	document.write( image );
}

function writePrice( obj )
{
	if ( obj.price != '-@NULL@-' )
		document.write( '<div class="bestseller-price"><strong>' + regpriceTxt + ':</strong> ' + obj.price + '</div>' );
}

function writeSaleprice( obj )
{
	if( obj.saleprice != '-@NULL@-' )
		document.write( '<div class="bestseller-saleprice"><strong>' + salepriceTxt + ':</strong> ' + obj.saleprice + '</div>' );
}

function showTable( request, arrayName, colWidth, startPos, endPos )
{
	//for( a = startPos; a <= endPos; a++ )
	//{
		a = startPos;
		if ( a >= uniquearr.length )
			request = 'NA';
		switch(request){
			case 'Name':
				writeName( arrayName[ uniquearr[a] - 1 ], colWidth );
				break;
			case 'Image':
				writeImage( arrayName[ uniquearr[a] - 1 ], colWidth );
				break;
			case 'Price':
				writePrice( arrayName[ uniquearr[a] - 1 ], colWidth );
				break;
			case 'Saleprice':
				writeSaleprice( arrayName[ uniquearr[a] - 1 ], colWidth );
				break;
		//}
		if ( showSeperatorColumn && a != endPos && request == showContents[0] )
			seperatorColumn( showContents.length );
	}
}

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++;
		}
	}
	totalRows = Math.ceil( showtotal / colperrow );
	endPos    = -1;
	colWidth  = Math.ceil( 100 / colperrow );
	for ( i = 0; i < totalRows; i++ )
	{
		document.write( '<div class="bestseller-item">' );
		startPos = endPos + 1;
		endPos   = endPos + colperrow;
		for( j = 0; j < showContents.length; j++ )
			showTable( showContents[j], arrayName, colWidth, startPos, endPos );
		document.write( '<div class="clear"></div></div>' );
		if ( ( i + 1 ) < totalRows )
			seperatorRow();
	}
}
