// JavaScript Document

/*******************************
*
* SlidingElement.js
* 
* DHTML Sliding Merch Windows
* Ver = 1.0 - Utilizes prototype.js - /js/extern/prototype.js
*
* Dependent on DhtmlUtils instance being added to The prototypejs Element class via addMethods

* Author: John Hutcheson, control.option
*
*******************************/
var SlidingElement = Class.create();


SlidingElement.prototype = {

	//NavMenus Object Class Constructor
	
	// @param merch_window        DOM element id of element to slide
	// @param start_position      Hash style object {x:<value>, y:<value>} of start position
	// @param end_position        Hash style object {x:<value>, y:<value>} of end position
	initialize: function(element) {
		this.elem = $(element);
		this.startPos;
		this.endPos;
		this.slideTimer;
		this.isSliding = false;
		this.slideFunc = this.slideElem.bind(this)
	},
	
	
	slide: function(destination) {
		if (this.isSliding)
		{
			this.stopSlider();
		}
		this.endPos = destination;
		this.isSliding = true;
		this.slideTimer = new PeriodicalExecuter(this.slideFunc, .1);
	},
	
	
	slideElem: function () {
		var targetY = this.endPos.y;
		var currentY = parseInt(this.elem.getStyle('top'));
		
		var deltaY = Math.ceil((targetY - currentY) / 2);
		
		if (Math.abs(deltaY) <= 1)
		{
			this.slideTimer.stop();
			this.elem.shiftTo(this.endPos.x, this.endPos.y);
		}
		else
		{
			this.elem.shiftBy(0, deltaY);
		}
	},
	
	stopSlider: function() {
		this.slideTimer.stop();
		this.isSliding = false;
	},
	
	
	closeMW: function (){
		this.stopSlider();
		this.elem.hide();
	}
}