/*----------------------*script for scrolling text in a division*---------------------------*/
direction=0;
increment=2;
pause=0;
var timer;
var semaphore="none";
var align="left";

/**
* suggest at:	yogeshsarang@indiatimes.com
*/

/**
* Function to add content to the division for scrolling with given properties.
* It uses cliped division for scroller window & another layer to hold the large content.
* Parameter summary
*	objid				: type string.
*		Its id of the division which will be used to scroll the content.
*	listname			: type string.
*		Its variable name of the list or string which holds the content.
*	refstring			: type string.
*		In case of the list its the function that will be called with 
*		index of array item on clicking the item.
*	left				: type int.
*		Its left position of the scroller window.
*	width				: type int.
*		Its width of the scroller window.
*	height				: type int.
*		Its height of the scroller window.
*	bordercolor			: type string.
*		Its color of thin border of the scroller window.
*	fonttype			: type string.
*		Its font-family for text displayed in the scroller window.
*	fontcolor			: type string.
*		Its font-color for text displayed in the scroller window.
*	fontsize			: type string.
*		Its font-size for text displayed in the scroller window.
*/
function initiatescroller(objid,listname,refstring,
						left,top,width,height,bordercolor,
						fonttype,fontcolor,fontsize)
	{
		// create content in HTML that is to be scrolled.
		if(document.all || document.getElementById)
			content="<div id="+objid+"_content name="+objid+"_content style='visibility:show;position:absolute;left:0;top:0;width:"+((direction==0)?width:"auto")+"'>";
		else if(document.layers)
			content="<layer id="+objid+"_content name="+objid+"_content visibility=visible position=absolute left=0 top=0>";
		content+="<table cellpadding=0 cellspacing=1 width="+((direction==0)?width:"auto")+">";
		
		if(listname.length==0)
			content+="<tr><td>&nbsp;</td></tr>";
		else
		{	
			listobj=eval(listname);
			
			if(typeof listobj=="string")
				content+="<tr><td valign='top'><font face='"+fonttype+"' color='"+fontcolor+"' size="+fontsize+">"+listobj+"</font></td></tr>";
			else
			{	
				for(i=1; i<listobj.length; i++)
				{
					content+="<tr><td valign='middle' align='center'><a ";
					if(refstring.length>0)
						content+="href='javascript:"+refstring+"("+i+")'";
					content+=" id="+listname+"_"+i+" name="+listname+"_"+i+" style='font-family:"+fonttype+";color:"+fontcolor+";font-size:10pt'>"+listobj[i]+"</a></td></tr>";
				}
			}
		}

		content+="</table>";

		if(document.all || document.getElementById)
			content+="</div>";
		else if(document.layers)
			content+="</layer>";

		// this code is for adjusting the position of the division for different resolution.
		if(align=="center")
		{
			if(screen.width==1024)
			{
				top+=84;
				left+=112;
			}
			else if(screen.width==1280)
			{
				top+=212;
				left+=240;
			}
		}

		// set the position of division & set up clip settings.
		if(document.all)
		{
			obj=document.all[objid];
			obj.innerHTML=content;
			obj.style.visibility="visible";
			obj.style.posTop=top;
			obj.style.posLeft=left;
			obj.style.clip="rect("+0+" "+width+" "+height+" "+0+")";
		}
		else if(document.layers)
		{
			objns=document.layers[objid];
			objns.document.write(content);
			objns.document.close();
			objns.top=top;
			objns.left=left;
			objns.visibility="visible";
			objns.clip.left=0;
			objns.clip.right=width;
			objns.clip.top=0;
			objns.clip.bottom=height;
			
		}
		else if(document.getElementById)
		{	
			obj=document.getElementById(objid);
			obj.innerHTML=content;
			obj.style.visibility="show";
			obj.style.top=top;
			obj.style.left=left;
			obj.style.clip="rect("+0+" "+width+" "+height+" "+0+")";
		}
	}

/**
* Function to scroll content up.
* Parameter summary
*	upobj				: type string.
*		Its id of the division which will be used to scroll the content.
*	distance			: type int.
*		Its the distance by which the content will be scroller.
*/
function prescrollUp(upobj,distance)
	{
		// synchronization stuff to keep scrolling whatever user might do,
		// don't allow other scrolling action till this one is complete.
		if(semaphore=="up");
		else if(semaphore=="none")
			semaphore="up";
		else
			return;
		
		// scroll the content division not the placeholder division.
		if(document.all)
		{
			obj=document.all[upobj+"_content"];
			if(parseInt(document.all[upobj].currentStyle.clipBottom)<(obj.style.posTop+obj.clientHeight))
			{
				if(distance<=0)
					semaphore="none";
				else
				{
					obj.style.posTop-=increment;
					timer=setTimeout("prescrollUp('"+upobj+"',"+(distance-increment)+")",pause);
				}
			}
			else
				semaphore="none";
		}
		else if(document.layers)
		{
			obj=document.layers[upobj].document.layers[upobj+"_content"];
			if(document.layers[upobj].clip.bottom<(obj.top+obj.document.height))
			{
				if(distance<=0)
					semaphore="none";
				else
				{
					obj.top-=increment;
					timer=setTimeout("prescrollUp('"+upobj+"',"+(distance-increment)+")",pause)
				}
			}
			else
				semaphore="none";
		}
		else if(document.getElementById)
		{
			obj=document.getElementById(upobj);
			contentobj=document.getElementById(upobj+"_content");
			if(parseInt(obj.style.clip.substring(obj.style.clip.indexOf(" ",obj.style.clip.indexOf(" ")+1)+1,obj.style.clip.length))<(parseInt(contentobj.style.top)+contentobj.offsetHeight))
			{
				if(distance<=0)
					semaphore="none";
				else
				{
					contentobj.style.top=(parseInt(contentobj.style.top)-increment)+"pt";
					timer=setTimeout("prescrollUp('"+upobj+"',"+(distance-increment)+")",pause);
				}
			}
			else
				semaphore="none";
		}
	}

/**
* Function to scroll content down.
* Parameter summary
*	downobj				: type string.
*		Its id of the division which will be used to scroll the content.
*	distance			: type int.
*		Its the distance by which the content will be scroller.
*/
function prescrollDown(downobj,distance)
	{
		// synchronization stuff to keep scrolling whatever user might do,
		// don't allow other scrolling action till this one is complete.
		if(semaphore=="down");
		else if(semaphore=="none")
			semaphore="down";
		else
			return;

		// scroll the content division not the placeholder division.
		if(document.all)
		{
			obj=document.all[downobj+"_content"];
			if(obj.style.posTop<0)
			{
				if(distance<=0)
					semaphore="none";
				else
				{
					obj.style.posTop+=increment;
					timer=setTimeout("prescrollDown('"+downobj+"',"+(distance-increment)+")",pause);
				}
			}
			else
				semaphore="none";
		}
		else if(document.layers)
		{
			obj=document.layers[downobj].document.layers[downobj+"_content"];
			if(obj.top<0)
			{
				if(distance<=0)
					semaphore="none";
				else
				{
					obj.top+=increment;
					timer=setTimeout("prescrollDown('"+downobj+"',"+(distance-increment)+")",pause);
				}
			}
			else
				semaphore="none";
		}
		else if(document.getElementById)
		{
			obj=document.getElementById(downobj+"_content");
			if(parseInt(obj.style.top)<0)
			{
				if(distance<=0)
					semaphore="none";
				else
				{
					obj.style.top=(parseInt(obj.style.top)+increment)+"pt";
					timer=setTimeout("prescrollDown('"+downobj+"',"+(distance-increment)+")",pause);
				}
			}
			else
				semaphore="none";
		}
	}

/**
* Function to scroll content right.
* Parameter summary
*	rightobj				: type string.
*		Its id of the division which will be used to scroll the content.
*	distance			: type int.
*		Its the distance by which the content will be scroller.
*/
function prescrollRight(rightobj,distance)
	{
		// synchronization stuff to keep scrolling whatever user might do,
		// don't allow other scrolling action till this one is complete.
		if(semaphore=="left");
		else if(semaphore=="none")
			semaphore="left";
		else
			return;

		// scroll the content division not the placeholder division.
		if(document.all)
		{
			obj=document.all[rightobj+"_content"];
			if(obj.style.posLeft<0)
			{
				if(distance<=0)
					semaphore="none";
				else
				{
					obj.style.posLeft+=increment;
					timer=setTimeout("prescrollRight('"+rightobj+"',"+(distance-increment)+")",pause);
				}
			}
			else
				semaphore="none";
		}
		else if(document.layers)
		{
			obj=document.layers[rightobj].document.layers[rightobj+"_content"];
			if(obj.top<0)
			{
				if(distance<=0)
					semaphore="none";
				else
				{
					obj.top+=increment;
					timer=setTimeout("prescrollRight('"+rightobj+"',"+(distance-increment)+")",pause);
				}
			}
			else
				semaphore="none";
		}
		else if(document.getElementById)
		{
			obj=document.getElementById(rightobj+"_content");
			if(parseInt(obj.style.left)<0)
			{
				if(distance<=0)
					semaphore="none";
				else
				{
					obj.style.left=parseInt(obj.style.left)+increment;
					timer=setTimeout("prescrollRight('"+rightobj+"',"+(distance-increment)+")",pause);
				}
			}
			else
				semaphore="none";
		}
	}

/**
* Function to scroll content left.
* Parameter summary
*	leftobj				: type string.
*		Its id of the division which will be used to scroll the content.
*	distance			: type int.
*		Its the distance by which the content will be scroller.
*/
function prescrollLeft(leftobj,distance)
	{
		// synchronization stuff to keep scrolling whatever user might do,
		// don't allow other scrolling action till this one is complete.
		if(semaphore=="up");
		else if(semaphore=="none")
			semaphore="up";
		else
			return;
		
		// scroll the content division not the placeholder division.
		if(document.all)
		{
			obj=document.all[leftobj+"_content"];
			if(parseInt(document.all[leftobj].currentStyle.clipRight)<(obj.style.posLeft+obj.clientWidth))
			{
				if(distance<=0)
					semaphore="none";
				else
				{
					obj.style.posLeft-=increment;
					timer=setTimeout("prescrollLeft('"+leftobj+"',"+(distance-increment)+")",pause);
				}
			}
			else
				semaphore="none";
		}
		else if(document.layers)
		{
			obj=document.layers[leftobj].document.layers[leftobj+"_content"];
			if(document.layers[leftobj].clip.right<(obj.left+obj.document.width))
			{
				if(distance<=0)
					semaphore="none";
				else
				{
					obj.top-=increment;
					timer=setTimeout("prescrollLeft('"+leftobj+"',"+(distance-increment)+")",pause)
				}
			}
			else
				semaphore="none";
		}
		else if(document.getElementById)
		{
			obj=document.getElementById(leftobj);
			contentobj=document.getElementById(leftobj+"_content");
			if(parseInt(obj.style.clip.substring(obj.style.clip.indexOf(" ")+1,obj.style.clip.length))<(parseInt(contentobj.style.left)+contentobj.offsetWidth))
			{
				if(distance<=0)
					semaphore="none";
				else
				{
					contentobj.style.left=parseInt(contentobj.style.left)-increment;
					timer=setTimeout("prescrollLeft('"+leftobj+"',"+(distance-increment)+")",pause);
				}
			}
			else
				semaphore="none";
		}
	}
/*------------------------------End of File scroll.js--------------------------------------------*/
