
var total_width = 0;
var hasWidthChecked = false;

function autoscroll(e)
  { 
	  var mousx = 0;
	  var mousy = 0;
	  var doid=this.id;
	  var dobj=document.getElementById(doid);
	  if (!e) var e = window.event;
	  if (e.pageX || e.pageY)
	  {
		  mousx = e.pageX;
	  	  mousy = e.pageY;
	  }
	  else if (e.clientX || e.clientY)
	  {
	   mousx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
	   mousy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	  }
	 var offx = offy = 0;
	 while(dobj) // calculate the actual x&y offsets of the element to be scrollled
	 {
		 offx+=dobj.offsetLeft;
		 offy+=dobj.offsetTop;
		 dobj=dobj.offsetParent;
	 }
	 relx=mousx-offx; // Relative mouse positions wrt the element
	 rely=mousy-offy;
	 dobj=document.getElementById(doid);
	 var margn=dobj.offsetWidth/10;
	 if(relx<margn) relx=margn;
	 
	 if(relx > (dobj.offsetWidth-margn)) relx=dobj.offsetWidth-margn;
	 
	 dobj.finy=parseInt(( dobj.scrollHeight - dobj.offsetHeight ) * (rely-margn) / (dobj.offsetHeight-2*margn));
	 dobj.finx=parseInt(( dobj.scrollWidth - dobj.offsetWidth ) * (relx-margn) / (dobj.offsetWidth-2*margn));
	 if(!dobj.speedy && !dobj.speedx) // If not already scrolling
	 { 
		 dobj.speedy=0;
		 dobj.speedx=0;
		 scrollToFin(doid);
	 }
 }
 function scrollToFin (oid)
 { 
 	obj=document.getElementById(oid);
 	
 	if(!hasWidthChecked){
 		
 		apparel_count = $('#'+oid+' .product_list li').length;
	 	total_width = apparel_count*250;
	 	hasWidthChecked = true;
	 	
	 	product_list = $('#'+oid+' .product_list');
	 	product_list[0].style.width = total_width+"px";
	 	}
	 	
	 
	 obj.speedy=((obj.finy-obj.scrollTop)/8+obj.speedy)/4; // it tries to bring speed gradually to (distance/4) ......
	 //obj.speedx=((obj.finx-obj.scrollLeft)/8+obj.speedx)/4;
	 obj.speedx=((obj.finx-obj.scrollLeft)/8+obj.speedx)/4;
	 if(Math.abs(obj.scrollTop-obj.finy) < 1 )
	 {
		 obj.scrollTop=obj.finy;
		 obj.speedy=null;
	 }
	 else obj.scrollTop+=parseFloat(obj.speedy);
	 if(Math.abs(obj.scrollLeft-obj.finx) < 1 )
	 {
		 obj.scrollLeft=obj.finx;
		 obj.speedx=null;
	 }
	 else obj.scrollLeft+=parseFloat(obj.speedx);
	 if(obj.scrollTop!=obj.finy || obj.scrollLeft!=obj.finx)
	 {
		 setTimeout("scrollToFin('"+oid+"')",18);
	 }
	 else
	 {
		 obj.speedy=null;
		 obj.speedx=null;
	}  
 }