// (c) Antiques Atlas, David Barton

var      uppp = Array (4,8,13,18,26,34,48,61,66,50,39,29,23,12,4,2,1,1);
var shortuppp = Array (4,8,10,12,14,19,31,42,45,42,28,19, 12, 4, 2, 1, 1, 1);
var prefixlab = Array("","c","c","c","c"); // div prefix id
var cat = Array("all","Furniture","Clock-Timepiece","Ceramics","Silver");
var uppi = Array(0,0,0,0,0);
var recentprevblock = Array(0,0,0,0,0);
var recentcurrentblock= Array(1,1,1,1,1); 
var recentnextblock= Array(2,2,2,2,2);
var recenttopurl = Array(0,0,0,0,0);
var recentboturl = Array(0,0,0,0,0);
var totalscroll = Array(0,0,0,0,0);
var inittopval = Array(0,0,0,0,0);
var divheight = Array(440,295,295,295,295);

var PreImage2=new Image();
PreImage2.src="/images/nbuttonhi.jpg";

var PreImage3=new Image();

PreImage3.src="/images/nbbuttonhi.jpg";

var th=0;

function crequest(el,direction,durl,prefix,toptime)
{ 

    var cxhr; 
    try {  cxhr = new ActiveXObject('Msxml2.XMLHTTP');   }
    catch (e) 
    {
        try {   cxhr = new ActiveXObject('Microsoft.XMLHTTP');    }
        catch (e2) 
        {
          try {  cxhr = new XMLHttpRequest();     }
          catch (e3) {  cxhr = false;   }
        }
     }
 
    cxhr.onreadystatechange  = function()
    { 
    	
         if(cxhr.readyState  == 4)
         {
              if(cxhr.status  == 200) 
              {
          
				          var SplitResult = cxhr.responseText.split("|");
     				     
     				      document.getElementById(el).innerHTML=SplitResult[0];
     				      
     				      th = SplitResult[3]
     				       
     				      
									recentboturl[prefix] = SplitResult[1];
									recenttopurl[prefix]  = SplitResult[2];
									totalscroll[prefix]=0;
									yy=1;
									inittopval[prefix] = document.getElementById(prefixlab[prefix]+'recentinnerwotsit').style.top.replace("px","");
									inittopval[prefix] = inittopval[prefix].replace("pt","");

									document.getElementById(prefixlab[prefix]+'recentstatus').innerHTML="&nbsp;";
									
									cdoscroll(direction,prefix,toptime);

              }
              else 
              {
              //   document.ajax.dyn="Error code " + cxhr.status;
            //  alert ("cccc"+ cxhr.status);
               }
                 
         }
  
       
    }; 

   cxhr.open("GET", "/antiques/do_recent_items.php?fromtime="+durl+"&dir="+direction+"&cat="+cat[prefix]+"&toptime="+toptime+"&h="+th,  true); 
   cxhr.send(null); 
    
} 


function cdoscroll(direction,prefix,toptime)
{

  yy = uppp[uppi[prefix]];
  if (divheight[prefix]==295)
  {
  	yy = shortuppp[uppi[prefix]];
  }
  
  totalscroll[prefix] += yy;

  amount=divheight[prefix];

if (uppi[prefix]<17)

{
  	uppi[prefix]++;
  	
 	 topval = document.getElementById(prefixlab[prefix]+'recentinnerwotsit').style.top.replace("px","");
 	 topval = topval.replace("pt","");
 	 
 	 
 	 if (direction==1)
 	 {
  		document.getElementById(prefixlab[prefix]+'recentinnerwotsit').style.top =  (parseInt(topval) - yy) + "px";
	 }
	 else
	 {
			document.getElementById(prefixlab[prefix]+'recentinnerwotsit').style.top =  (parseInt(topval) + yy) + "px";
			
	 }
  
   setTimeout('cdoscroll('+direction+',\''+prefix+'\' ,'+toptime+'    );',75);
}
else
	{
		uppi[prefix] = 0;
			if (direction==1)
 			{	
				document.getElementById(prefixlab[prefix]+'recentinnerwotsit').style.top =  (parseInt(inittopval[prefix]) - amount) + "px";
			}
			else
			{
				document.getElementById(prefixlab[prefix]+'recentinnerwotsit').style.top =  (parseInt(inittopval[prefix]) + amount) +  "px";
			}
	
			if (direction==1)
			{
							
					if (document.getElementById(prefixlab[prefix]+'rx'+recentnextblock[prefix]))
					{
					divh=divheight[prefix];
						document.getElementById(prefixlab[prefix]+'recentinnerwotsit').removeChild(document.getElementById(prefixlab[prefix]+'rx'+recentnextblock[prefix]));
						var topval = document.getElementById(prefixlab[prefix]+'recentinnerwotsit').style.top.replace("px","");
						topval = topval.replace("pt","");
						document.getElementById(prefixlab[prefix]+'recentinnerwotsit').style.top = (parseInt(topval) + divh) + "px";
						caddElement(recentnextblock[prefix],prefix);
					}
}
else
{
	//remove lastblock
	if (document.getElementById(prefixlab[prefix]+'rx'+recentprevblock[prefix]))
	{

		divh=divheight[prefix];
		document.getElementById(prefixlab[prefix]+'recentinnerwotsit').removeChild(document.getElementById(prefixlab[prefix]+'rx'+recentprevblock[prefix]));
		caddElementBefore(recentprevblock[prefix],recentcurrentblock[prefix],prefix);
		var topval = document.getElementById(prefixlab[prefix]+'recentinnerwotsit').style.top.replace("px","");
		topval = topval.replace("pt","");
		document.getElementById(prefixlab[prefix]+'recentinnerwotsit').style.top = (parseInt(topval) - divh) + "px";
	}
}	

if (recenttopurl[prefix]!="-")
{
document.getElementById(prefixlab[prefix]+'recenttoptop').innerHTML="<a  id=\"nrolloverb\" href=\"javascript:cmoveit(-1,'"+recenttopurl[prefix]+"',"+prefix+","+toptime+");\"><span>scroll up<\/span><\/a>";
}
document.getElementById(prefixlab[prefix]+'recentbotbot').innerHTML="<a  id=\"nrollover\" href=\"javascript:cmoveit(1,'"+recentboturl[prefix]+"',"+prefix+","+toptime+");\"><span>scroll down<\/span><\/a>";

}

}


function caddElement(n,prefix) 
{

  var newdiv = document.createElement('div');
  
  var divIdName = prefixlab[prefix]+'rx'+n;
  newdiv.setAttribute('id',divIdName);
  newdiv.setAttribute('style','height:'+divheight[prefix]+'px;');
  document.getElementById(prefixlab[prefix]+'recentinnerwotsit').appendChild(newdiv);
  document.getElementById(divIdName).style.height = divheight[prefix]; //ie
}

function caddElementBefore(n,node,prefix) 
{
  var newdiv = document.createElement('div');
  var divIdName = prefixlab[prefix]+'rx'+n;
  newdiv.setAttribute('id',divIdName);
  newdiv.setAttribute('style','height:'+divheight[prefix]+'px;');
  document.getElementById(prefixlab[prefix]+'recentinnerwotsit').insertBefore(newdiv,document.getElementById(prefixlab[prefix]+'rx'+node));
  document.getElementById(divIdName).style.height = divheight[prefix]; //ie
}


function cmoveit(direction,durl,prefix,toptime)
{


recentcurrentblock[prefix] += direction;
if (recentcurrentblock[prefix]<0) recentcurrentblock[prefix]=2;
recentcurrentblock[prefix] %=3;

recentprevblock[prefix]+=direction;
if (recentprevblock[prefix]<0) recentprevblock[prefix]=2;
recentprevblock[prefix] %=3;

recentnextblock[prefix]+=direction;
if (recentnextblock[prefix]<0) recentnextblock[prefix]=2;
recentnextblock[prefix] %=3;

if (direction==-1)
{
document.getElementById(prefixlab[prefix]+'recenttoptop').innerHTML="<div id=\"ndisb\"><span> scroll up </span></div>";
}
else
	{
document.getElementById(prefixlab[prefix]+'recentbotbot').innerHTML="<div id=\"ndis\"><span> scroll down </span></div>";

}
document.getElementById(prefixlab[prefix]+'recentstatus').innerHTML="<img src=\"/images/loading.gif\" alt=\"loading\"/>";

pageTracker._trackEvent('Stock Scroller', 'Click for More', cat[prefix]);

crequest(prefixlab[prefix]+'rx'+recentcurrentblock[prefix],direction,durl, prefix,toptime); 

}
