scrollboxObjects = {};

function scrollboxObject(divId,iniX,iniY){
	this.id=divId;
	scrollboxObjects[this.id]=this;
	this.animString="scrollboxObjects."+this.id;
	this.load(divId,iniX,iniY);
};


scrollboxObject.prototype.load=function(divId,iniX,iniY){
	if(!document.getElementById)return;
	var scrollingDiv;

	this.scrollingDiv=document.getElementById(divId);
	
	this.scrollingDiv.style.top=this.y=iniY;
	this.scrollingDiv.style.left=this.x=iniX;
	
	this.ready=true;
};


scrollboxObject.slideDur = 500; // duration of glide

scrollboxObject.scrollBy = function(divId, x, y, dur, hideWhenStop) {
	if ( scrollboxObjects[divId] ) scrollboxObjects[divId].glideBy(x, y, dur, hideWhenStop);
}


scrollboxObject.prototype.glideBy = function(dx, dy, dur, hideWhenStop) {
  if ( !document.getElementById || this.isMoving ) return;
  this.slideDur = dur || scrollboxObject.slideDur;
  this.destX = this.destY = this.distX = this.distY = 0;
  this.startX = this.x; this.startY = this.y;
  
  this.distY = dy;
  this.distX = dx;
  
  this.destX = this.startX + this.distX; 
  this.destY = this.startY + this.distY;
  
  this.hideWhenStop = hideWhenStop ;
  
  this.isMoving = true;
  this.per = Math.PI/(2 * this.slideDur);
  this.slideStart = (new Date()).getTime();
  this.aniTimer = setInterval(this.animString + ".doSlide()",10);
}

scrollboxObject.prototype.doSlide = function() {
	var elapsed = (new Date()).getTime() - this.slideStart;
	if (elapsed < this.slideDur) {
		var x = this.startX + this.distX * Math.sin(this.per*elapsed);
		var y = this.startY + this.distY * Math.sin(this.per*elapsed);
    this.shiftTo(this.scrollingDiv, x, y); 
	} else {
    clearInterval(this.aniTimer); this.isMoving = false;
	this.shiftTo(this.scrollingDiv, this.destX, this.destY);
		if (this.hideWhenStop){
			this.scrollingDiv.style.visibility="hidden";
		}
	}
}

scrollboxObject.prototype.shiftTo=function(scrollingDiv,x,y){
	if(!scrollingDiv.style)return;
	scrollingDiv.style.left=(this.x=x)+"px";
	scrollingDiv.style.top=(this.y=y)+"px";
};

function initboxSlideshow(itemWidth) {
	if(document.getElementById){
		slideShowList = document.getElementById('slideshowList');
		slideShowItems = 0 ;
		currentItem = 1;
		slideShowChildNodes = slideShowList.childNodes ;
		for (i=0; i<slideShowChildNodes.length; i++){
			if (slideShowChildNodes[i].nodeName == "LI") slideShowItems++ ;
		}
		
		slideLeftButVar=document.getElementById('leftArrow');
		slideRightButVar=document.getElementById('rightArrow');
		slideLeftButVar.style.display = "none" ;
		
		if (slideShowItems > 3){
			
			slideRightButVar.style.display = "block" ;
		}
		else
		{
			slideRightButVar.style.display = "none" ;
		}
		
		var slideShow = new scrollboxObject('slideshow', 0, 0);
		
		liWidth = itemWidth;
		
		
	} 	
}


currentItem = 1 ;
function boxslider(direction){
	
	if(!scrollboxObjects['slideshow'].isMoving){
		tempItem = currentItem + direction ;
		if (tempItem > 0 && tempItem <= slideShowItems - 2) {
			if (tempItem == 1){
				slideLeftButVar.style.display = "none" ;	
			} else {
				slideLeftButVar.style.display = "block" ;
			}
			if (tempItem == slideShowItems - 2){
				slideRightButVar.style.display = "none" ;
			} else {
				slideRightButVar.style.display = "block" ;
			}
			scrollboxObject.scrollBy('slideshow',-1*direction*liWidth,0);
			currentItem += direction;
		}
	}
}

