function scrollArea() {
	this.imageArray = new Array();
	this.currentSpeed = 0;
}
scrollArea.prototype.draw = function() {
	this.myDiv = document.createElement("div");
	this.myDiv.setAttribute("class","scrollArea");	
	this.myDiv.setAttribute("className","scrollArea");	
	this.myDiv.style.width = contentWidth+"px";
	this.scrollDiv = document.createElement("div");
	this.scrollDiv.style.position = "absolute";
	this.scrollDiv.style.left = "-846px";
	this.scrollDiv.style.top = "-20px";
	this.myDiv.appendChild(this.scrollDiv);
	this.requestImages();
	return this.myDiv;
}
scrollArea.prototype.requestImages = function() {
	var myQuery = new dbQuery();
	myQuery.requestData("xml/images.xml",this,"loadImages");
}
scrollArea.prototype.loadImages = function(myQuery) {
	var myImages = myQuery.getRecords();
	var maxLeft = 0;
	var minLeft = 900000;
	for (var i=0;i<myImages.length;i++) {
		var newImage = new siteImage(myImages[i]);
		newImage.myIndex = i;
		this.scrollDiv.appendChild(newImage.draw());
		var imageLeft = newImage.myDiv.style.left;
		imageLeft = imageLeft.substr(0,imageLeft.length-2);
		if (imageLeft < minLeft) {
			minLeft = imageLeft;
		}
		var imageWidth = newImage.myImage.width;
		imageLeft = Number(imageLeft) + Number(imageWidth);
		if (imageLeft > maxLeft) {
			maxLeft = imageLeft;
		}

		this.imageArray.push(newImage);
	}
	//wrapLength = maxLeft - minLeft;
	// ebug(maxLeft+" "+minLeft);
}
scrollArea.prototype.startScroll = function(direction) {
	this.currentSpeed = scrollSpeed;
	clearInterval(scrollInt);
	scrollInt = setInterval("myPage.myScrollArea.scroll("+direction+")",10);
}
scrollArea.prototype.stopScroll = function(direction) {
	clearInterval(scrollInt);
	scrollInt = setInterval("myPage.myScrollArea.endScroll("+direction+")",10);
	// this.currentAcceleration = -1 * scrollAcceration * direction;
}
scrollArea.prototype.scroll = function(direction) {
	this.currentSpeed = this.currentSpeed + scrollAcceleration;
	if (this.currentSpeed > maxSpeed) {
		this.currentSpeed = maxSpeed;
	}
	var currentScrollLeft = this.scrollDiv.style.left;
	currentScrollLeft = currentScrollLeft.substr(0,currentScrollLeft.length - 2);
	var newScrollLeft  = (Number(currentScrollLeft) + Number(direction) * this.currentSpeed);
	this.scrollDiv.style.left = newScrollLeft+"px";
	this.checkWrap(direction,newScrollLeft);
}
scrollArea.prototype.checkWrap = function(direction,newScrollLeft) {	
	for (var i=0;i<this.imageArray.length;i++) {
		var myImage = this.imageArray[i];
		var currentLeft = myImage.myDiv.style.left;
		currentLeft = currentLeft.substr(0,currentLeft.length - 2);
		currentLeft = Number(currentLeft) + Number(newScrollLeft);
		if ((direction == -1) && (currentLeft + myImage.myImage.width < 0)) {
			newLeft = Number(currentLeft) + Number(wrapLength) - Number(newScrollLeft);
			myImage.myDiv.style.left = newLeft+"px";
		}
		else if ((direction == 1) && (currentLeft >contentWidth)) {
			newLeft = Number(currentLeft) - Number(wrapLength) - Number(newScrollLeft);
			myImage.myDiv.style.left = newLeft+"px";
		}
	}
}
scrollArea.prototype.endScroll = function(direction) {
	this.currentSpeed = this.currentSpeed - scrollAcceleration * 1.0 ;
	// ebug("end scroll "+direction+" "+this.currentSpeed);
	// if (this.currentSpeed * direction < 0) {
	if (bounce) { 
		if (this.currentSpeed < -10) {
			clearInterval(scrollInt);
			return;
		}
	}
	else {
		if (this.currentSpeed < 0) {
			clearInterval(scrollInt);
			return;
		}
	}
	var currentScrollLeft = this.scrollDiv.style.left;
	currentScrollLeft = currentScrollLeft.substr(0,currentScrollLeft.length - 2);
	var newScrollLeft  = (Number(currentScrollLeft) + Number(direction) * this.currentSpeed);
	this.scrollDiv.style.left = newScrollLeft+"px";
	this.checkWrap(direction,newScrollLeft);
}


