/* -------------------------------------------------- */
/* A javascript slider by Michael Morris              */
/*                                                    */
/* Modifications & Yahoo Template Stardardization     */
/* by Agatka Chmelar                                  */
/*                                                    */
/* Requires Prototype.js & Scriptaculous.js (Effects) */
/* -------------------------------------------------- */


var Slider = Class.create({

	offsetLeft: 0,
	lWidth: 0,
	rWidth: 0,
	moving: false,
	lens: null,
	reel: null,

	initialize: function(lens, reel){
		this.lens = $(lens);
		this.reel = $(reel);
  
		this.lWidth = this.lens.getWidth();
		this.rWidth = this.reel.getWidth();
	},

	move: function(dist) {
		if (!this.moving){
			if ((this.rWidth + this.offsetLeft) <= this.lWidth){
//				new Effect.Move('reel', { x: 0, y: 0, mode: 'absolute', beforeStart: this.moveStart.bind(this), afterFinish: this.moveEnd.bind(this) });
			}else{
				new Effect.Move('reel', { x: dist, y: 0, mode: 'relative', duration: 1, beforeStart: this.moveStart.bind(this), afterFinish: this.moveEnd.bind(this) });
			}
		}
	},

	moveBack: function(dist) {
		if (!this.moving)
			if (this.offsetLeft != 0)
				new Effect.Move('reel', { x: dist, y: 0, mode: 'relative', beforeStart: this.moveStart.bind(this), afterFinish: this.moveEnd.bind(this) });
	},

	moveStart: function() {
		this.moving = true;
	},

	moveEnd: function() {
		this.moving = false;
		this.offsetLeft = this.reel.positionedOffset().left;
		this.rWidth = this.reel.getWidth();
		this.lWidth = this.lens.getWidth();
		if ((this.rWidth + this.offsetLeft) <= this.lWidth){
			document.getElementById("productSlider-rightArrow").style.opacity = .5;
			document.getElementById("productSlider-rightArrow").style.filter = "alpha(opacity=50)";
		} else {
			document.getElementById("productSlider-rightArrow").style.opacity = 1;
			document.getElementById("productSlider-rightArrow").style.filter = "alpha(opacity=100)";
		}
		if (this.offsetLeft != 0){
			document.getElementById("productSlider-leftArrow").style.opacity = 1;
			document.getElementById("productSlider-leftArrow").style.filter = "alpha(opacity=100)";
		} else {
			document.getElementById("productSlider-leftArrow").style.opacity = .5;
			document.getElementById("productSlider-leftArrow").style.filter = "alpha(opacity=50)";
		}
	}

});

