/** 
 * @fileoverview
 *
 * The rsow.mover library  
 *
 <pre>
		Copyright (c) 2000-2008 Palaquest Internet Solutions and Design
		Written by Jason "Palamedes" Ellis (palamedes at rocketmail.com)
		URL:  http://www.randomstringofwords.com/
		Version: 
		All rights reserved.

		Redistribution and use in source and binary froms, with or without
		modification, are permitted provided that the following conditions are met:
	
		- Redistributions of source code must retain the above copyright notice,
			this list of conditions and the following disclaimer.
		- Redistributions in binary form must reproduce the above copyright notice,
			this list of conditions and the following disclaimer in the
			documentation and/or other materials provided with the distribution.
		- Neither the name of Palaquest Internet Solutions & Design nor the names of its
			contributors may be used to endorse or promote products derived from
			this software without specific prior written permission.
 
		THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
		AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
		IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
		ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
		LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
		CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
		SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
		INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
		CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
		ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
		POSSIBILITY OF SUCH DAMAGE.
 </pre>
*/

if (typeof rsow == 'undefined') rsow = {};
if (typeof rsow.mover == 'undefined') {
	

//@TODO At somepoint I need to get horizontal movement in

	rsow.mover = function() {
		var a = arguments;
		this.element = (typeof a[0] == 'string')?$(a[0]):a[0];
		this.movement = {'top':[],'left':[]};
		this.queue = {'top':[],'left':[]};
		this.params = {};
		this.running = false;
	};
	rsow.mover.prototype = {};

	// Primary Veritcal Slider.  Called with an array of all the positions we want to stop at;
	// obj.verticalSlide([0,100,-40,0]);
	rsow.mover.prototype.verticalSlide = function() {
		var a = arguments;
		this.queue.top = a[0];
		if (!this.running) this.defineMovement();
	}

	rsow.mover.prototype.defineMovement = function () {
		if (typeof this.element != 'object') return false;
		this.running = true;

		// Define our TOP movements (Vertical)
		if (this.queue.top[0] != null) {
			var start = this.element.offsetTop;
			var current = this.element.offsetTop;
			var end = this.queue.top.shift();
			var c = 0;
			var m = start - end;
			if (start<end) {
				var l = 0;
				var breaker = 0;
				while (l < 100) {
					breaker++; if (breaker > 1000) break;
					c = current - start;
					l = (Math.abs(Math.round((c/m)*100)));
					s = Math.round(((Math.sin((l/100)*3.14))*10)+1);
					current = current + s;
					this.movement.top.push( current );
				}
			} else {
				var l = 100;
				var breaker = 0;
                while (l > 0) {
					breaker++; if (breaker > 1000) break;
                    c = current - end;
                    l = (Math.abs(Math.round((c/m)*100)));
                    s = Math.round(((Math.sin((l/100)*3.14))*10)+1);
                    current = current - s;
                    this.movement.top.push( current );
                }

			}
		}

		this.loop();
	}
	
	rsow.mover.prototype.loop = function() {
		// Do we have any TOP movement to make?
		if (this.movement.top[0] != null) {
			this.element.style.top = Number(this.movement.top.shift()) + 'px';
			var dis = this; setTimeout(function() { dis.loop.apply(dis); }, 10);

		// If we have no more positions for this iteration then stop
		} else {
			this.running = false;

			// Do we have any more iterations for top?
			if (this.queue.top[0] != null) this.defineMovement();
		}
	}

}

