// =======================================
// Simple Slide Show Gallery (horizontal) 
// Author: Justin bryant
// Date: 10/15/2010
// =======================================
function GalleryObject(eleName, img_width, canvas_width, step, auto, auto_step) { this.eleName = eleName;this.ele = null;this.width = img_width;this.canvas_width = canvas_width;this.step = step;this.end = (0 - (img_width - (Math.floor(canvas_width / step) * step)));this.auto = auto;this.autoStep = auto_step * 1000;this.bgPosX = 0;this.momentum = 20;step < 100 ? this.momentumStep = 1 : this.momentumStep = Math.floor(step / 500);this.maxMomentum = this.momentumStep * 5;this.moving = false;}
GalleryObject.prototype.init = function() {this.ele = document.getElementById(this.eleName);if(this.auto) {var galleryObj = this;setTimeout(function(){galleryObj.autoSlide()}, galleryObj.autoStep);}}
GalleryObject.prototype.reset = function() {this.bgPosX = 0;this.momentum = 20;this.moving = false;};
GalleryObject.prototype.autoSlide = function() {var galleryObj = this;if(galleryObj.bgPosX <= -1000)setTimeout(function(){ galleryObj.reset() }, 1500);this.scrollRight();setTimeout(function(){ galleryObj.autoSlide() }, galleryObj.autoStep);};
GalleryObject.prototype.move = function(dir) {if(this.moving)return false;else this.moving = true;if(dir == "prev" && this.bgPosX < 0)this.scrollLeft();else if(dir == "next" && this.bgPosX > this.end)this.scrollRight();else this.moving = false;}
GalleryObject.prototype.scrollRight = function() {var NEWbgPosX = this.bgPosX - this.step;if(this.bgPosX < this.end)this.bgPosX = this.end;this.slideGallery(this.bgPosX, NEWbgPosX);};
GalleryObject.prototype.scrollLeft = function() {var NEWbgPosX = this.bgPosX + this.step;if(this.bgPosX > 0)this.bgPosX = 0;this.slideGallery(this.bgPosX, NEWbgPosX);};
GalleryObject.prototype.slideGallery = function(from, to) {var galleryObj = this;if(from == to) {this.bgPosX = to;this.moving = false;return false;}if(from < to) {from = from + this.momentum;if(from >= to)from = to;}if(from > to) {from = from - this.momentum;if(from <= to)from = to;}this.ele.style.backgroundPosition = from + "px 0px";setTimeout(function(){galleryObj.slideGallery(from, to)}, 10);}

