// JavaScript Document

/*******************************
*
* SlidingMW.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 SlidingMW = Class.create();


SlidingMW.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(merch_window, start_position, end_position) {
		Element.addMethods(new DhtmlUtils());
		
		this.merchWindow = $(merch_window);
		this.startPos = start_position;
		this.endPos = end_position;
		
		this.slideTimer;
	},
	
	
	slideDown: function() {
		this.merchWindow.setStyle({left: this.startPos.x +"px", top: this.startPos.y + "px"});
		this.merchWindow.show();
		this.merchWindow.setVisible();
		this.runSlideDown();
	},
	
	
	runSlideDown: function () {
		var slideFunc = this.slideMWDown.bind(this);
		
		this.slideTimer = new PeriodicalExecuter(slideFunc, .12);
	},
	
	
	slideMWDown: function () {
		var targetY = this.endPos.y;
		var currentY = parseInt(this.merchWindow.getStyle('top'));
		var deltaY = Math.ceil((targetY - currentY) / 2);
		
		if ((targetY - currentY) <= 1)
		{
			this.slideTimer.stop();
			this.merchWindow.shiftTo(this.endPos.x, this.endPos.y);
		}
		else
		{
			this.merchWindow.shiftBy(0, deltaY);
		}
	},
	
	closeMW: function (){
		this.merchWindow.hide();
	}
}
