/**
* Version1.1:	It has got special border feature.
				Improvised on algorithm.
				Added functionality for netscape 6.
*/

/**
* suggest at:	yogeshsarang@indiatimes.com
*/

/**
* object implementation for holding menu positions.
*
* Name		:	ABCD.
* Date		:	Friday,July 26,2002.
* Author	:	Yogesh Sarang.
* Company	:	Infoseek India Pvt. Ltd.
*
* Method Summary
*	Parameterized Constructor	: no return.
*		Parameter summary
*			name				: type string.
*				Its name of the object in which ABCD is instanciated.
*			cells				: type int.
*				Its the number of cells to be shown at a time in scroller.
*		Asigns default values to member veriables.
*	getFiller				: return string.
*		It creates table structure for ABCD scroller.
*	fillABCD				: no return.
*		It replaces all the previous elements by new ones.
*	scrollLeft				: no return.
*		It uses timer to repetitively call itself 
*		& everytime scrolls by specific amount to left.
*	scrollRight				: no return.
*		It uses timer to repetitively call itself 
*		& everytime scrolls by specific amount to right.
*	Create					: no return.
*		It creates scroller divisions or layers in DHTML.
* Variable Summary
*	name					: type string.
*		Its name of object in which ABCD is instanciated.
*	semaphore				: type string.
*		Its used for synchronization purpose.
*	pause					: type int.
*		Its	the time between two calls to scrolling routine.
*	increment				: type int.
*		Its the amount by which each cell will be scrolled.
*/
function ABCD(name,cells)
{
	this.semaphore="none";
	this.pause=0;
	this.increment=2;
	this.timer=null;
	
	this.name=name;

	this.cellWidth=0;
	this.currentPos=0;
	this.cellCount=cells;

	this.Element=new Array();

	this.getFiller=getfiller;
	this.fillABCD=fillABCD;
	
	this.scrollLeft=scrollleft;
	this.scrollRight=scrollright;

	this.Create=createABCD;
}

/**
* Impementation of Create for object ABCD.
* Parameter summary
*	left				: type int.
*		Its left position of scroller.
*	top					: type int.
*		Its top position of scroller.
*	width				: type int.
*		Its width of scroller.
*/
function createABCD(left,top,width)
{
	// calculate width of each cell.
	this.cellWidth=Math.round(width/this.cellCount);

	// if no elements are given fill default elements of A to Z.
	if(this.Element.length==0)
	{
		this.Element[0]="A";this.Element[1]="B";this.Element[2]="C";this.Element[3]="D";
		this.Element[4]="E";this.Element[5]="F";this.Element[6]="G";this.Element[7]="H";
		this.Element[8]="I";this.Element[9]="J";this.Element[10]="K";this.Element[11]="L";
		this.Element[12]="M";this.Element[13]="N";this.Element[14]="O";this.Element[15]="P";
		this.Element[16]="Q";this.Element[17]="R";this.Element[18]="S";this.Element[19]="T";
		this.Element[20]="U";this.Element[21]="V";this.Element[22]="W";this.Element[23]="X";
		this.Element[24]="Y";this.Element[25]="Z";
	}

	document.write("<STYLE>a.abcd {font-size:8pt; color:#000000; font-family:verdana,arial; text-decoration:none;} </STYLE>");

	// create DHTML objects for actually displaying scroller.
	if(document.all || document.getElementById)
	// for ie you will get scroller for large list, making page look big at width,
	// so get only cells that are visible & one extra for smooth scrolling.
		document.write("<div id='ABDC_"+this.name+"_frame' name='ABDC_"+this.name+"_frame' style='left:"+left+";top:"+top+";position:absolute;clip:rect(0 "+(this.cellWidth*this.cellCount+1)+" 60 0)'><div id='ABCD_"+this.name+"_doc' name='ABCD_"+this.name+"_doc' style='position:absolute;left:1;top:0;width:"+this.cellWidth*(this.cellCount+1)+";height:22;background-color:#000000'>"+this.getFiller(0,this.cellCount+1)+"</div></div>");
	else if(document.layers)
	// for ns you won't get the scroller, so fill whole of the content.
		document.write("<layer id='ABDC_"+this.name+"_frame' name='ABDC_"+this.name+"_frame' left="+left+" top="+top+" position=absolute clip=0,0,"+(this.cellWidth*this.cellCount+1)+",24><layer id='ABCD_"+this.name+"_doc' name='ABCD_"+this.name+"_doc' bgcolor=#000000 height=22>"+this.getFiller(0,this.Element.length)+"</layer></layer>");
}

/**
* Impementation of getFiller for object ABCD.
* Parameter summary
*	start				: type int.
*		Its starting index in Element array.
*	end					: type int.
*		Its last index in Element array.
*/
function getfiller(start,end)
{
	// for thin border you need one pixel lesser in width.
	width=this.cellWidth-1;
	
	// fill the string with HTML code for table holding all the specified elements.
	var filler="<table cellspacing=1 cellpadding=0 border=0 width="+this.cellWidth*(end-start)+" height=100% bgcolor=#000000><tr>";
	for(z=start; z<end; z++)
	{
		filler+="<td align='center' valign='middle' bgcolor=#EEEEEE width="+width+" height=100%><a name="+this.name+"_"+z+" id="+this.name+"_"+z;
		if((typeof this.refString=="string")&&(this.refString.length>0))
			filler+=" class='abcd' href='#' onclick='javascript:"+this.refString+"("+z+");return false;'";
		filler+=">"+this.Element[z]+"</a></td>";
	}
	filler+="</tr></table>";

	return filler;
}

/**
* Impementation of fillABCD for object ABCD.
* Parameter summary
*	start				: type int.
*		Its starting index in Element array.
*/
function fillABCD(start)
{
	if(document.all)
		//for(i=0; i<this.cellCount+1; i++)
		//	document.all[this.name+"_"+i].innerHTML=this.Element[start+i];
		document.all["ABCD_"+this.name+"_doc"].innerHTML=this.getFiller(start,start+this.cellCount+1);
	else if(document.getElementById)
		//for(i=0; i<this.cellCount+1; i++)
		//	document.getElementById(this.name+"_"+i).innerHTML=this.Element[start+i];
		document.getElementById("ABCD_"+this.name+"_doc").innerHTML=this.getFiller(start,start+this.cellCount+1);
}

function scrollleft(scrollCells,scrollAmount)
{
	if(document.layers)
	{
		if(scrollAmount==null)
		{
			if((this.currentPos+this.cellCount+scrollCells) >= this.Element.length)
				scrollCells=this.Element.length-this.currentPos-this.cellCount;
			if(scrollCells>0)
				this.scrollLeft(scrollCells,this.cellWidth*scrollCells);
		}
		else if(scrollAmount>0)
		{
			divobj=document.layers["ABDC_"+this.name+"_frame"].document.layers["ABCD_"+this.name+"_doc"].left-=this.increment;
			this.timer=setTimeout(this.name+".scrollLeft("+scrollCells+","+(scrollAmount-this.increment)+")",this.pause);
		}
		else
			this.currentPos+=scrollCells;
	}
	else if(document.all)
	{
		if(scrollAmount>0)
		{
			document.all["ABCD_"+this.name+"_doc"].style.posLeft-=this.increment;
			this.timer=setTimeout(this.name+".scrollLeft("+scrollCells+","+(scrollAmount-this.increment)+")",this.pause);
		}
		else if(scrollCells>0)
		{
			if((scrollAmount==null)&&((this.currentPos+this.cellCount+scrollCells)>=this.Element.length))
				scrollCells=this.Element.length-this.currentPos-this.cellCount;
			
			if(scrollCells>0)
			{
				document.all["ABCD_"+this.name+"_doc"].style.posLeft=1;
				
				this.fillABCD(this.currentPos);

				// increment currentPos by one that is one cell will be scrolled
				this.currentPos++;

				this.scrollLeft(scrollCells-1,this.cellWidth-1);
			}
		}
	}
	else if(document.getElementById)
	{
		obj=document.getElementById("ABCD_"+this.name+"_doc");
		if(scrollAmount>0)
		{
			obj.style.left=(parseInt(obj.style.left)-this.increment)+"px";
			this.timer=setTimeout(this.name+".scrollLeft("+scrollCells+","+(scrollAmount-this.increment)+")",this.pause);
		}
		else if(scrollCells>0)
		{
			if((scrollAmount==null)&&((this.currentPos+this.cellCount+scrollCells)>=this.Element.length))
				scrollCells=this.Element.length-this.currentPos-this.cellCount;
			
			if(scrollCells>0)
			{
				obj.style.left="0px";

				this.fillABCD(this.currentPos);

				// increment currentPos by one that is one cell will be scrolled
				this.currentPos++;

				this.scrollLeft(scrollCells-1,this.cellWidth);
			}
		}
	}
}

function scrollright(scrollCells,scrollAmount)
{
	if(document.layers)
	{
		if(scrollAmount==null)
		{
			if((this.currentPos-scrollCells)<0)
				scrollCells=this.currentPos;
			if(scrollCells>0)
				this.scrollRight(scrollCells,this.cellWidth*scrollCells);
		}
		else if(scrollAmount>0)
		{
			document.layers["ABDC_"+this.name+"_frame"].document.layers["ABCD_"+this.name+"_doc"].left+=this.increment;
			this.timer=setTimeout(this.name+".scrollRight("+scrollCells+","+(scrollAmount-this.increment)+")",this.pause);
		}
		else
			this.currentPos-=scrollCells;
	}
	else if(document.all)
	{
		if(scrollAmount>0)
		{
			document.all["ABCD_"+this.name+"_doc"].style.posLeft+=this.increment;
			this.timer=setTimeout(this.name+".scrollRight("+scrollCells+","+(scrollAmount-this.increment)+")",this.pause);
		}
		else if(scrollCells>0)
		{
			if((scrollAmount==null)&&((this.currentPos-scrollCells)<0))
				scrollCells=this.currentPos;
			if(scrollCells>0)
			{
				document.all["ABCD_"+this.name+"_doc"].style.posLeft=(this.cellWidth-1)*(-1);

				this.fillABCD(this.currentPos-1);

				// increment currentPos by one that is one cell will be scrolled
				this.currentPos--;

				this.scrollRight(scrollCells-1,this.cellWidth);
			}
		}
	}
	else if(document.getElementById)
	{
		obj=document.getElementById("ABCD_"+this.name+"_doc");
		if(scrollAmount>0)
		{
			obj.style.left=(parseInt(obj.style.left)+this.increment)+"px";;
			this.timer=setTimeout(this.name+".scrollRight("+scrollCells+","+(scrollAmount-this.increment)+")",this.pause);
		}
		else if(scrollCells>0)
		{
			if((scrollAmount==null)&&((this.currentPos-scrollCells)<0))
				scrollCells=this.currentPos;
			if(scrollCells>0)
			{
				obj.style.left=this.cellWidth*(-1)+"px";
				
				this.fillABCD(this.currentPos-1);

				// increment currentPos by one that is one cell will be scrolled
				this.currentPos--;

				this.scrollRight(scrollCells-1,this.cellWidth);
			}
		}
	}
}
