/** Written by Pamela Ueckerman 2007 - NOT part of Scriptaculous**/

/** Generic method for allowing a sliding / scrolling window of content. */

Slideshow = Class.create();
Slideshow.prototype = {
	initialize: function(objId, parentId, x, y, duration, maxWidth, maxHeight) {
	
	
		var obj = document.getElementById(objId);
		var parent = document.getElementById(parentId);
	
		var objLeft = obj.offsetLeft;
		var objWidth = parent.offsetWidth;
		var maxScrollX = (!maxWidth && maxWidth != -1)? parent.scrollWidth : maxWidth;
					
		var objTop = obj.offsetTop;
		var objHeight = parent.offsetHeight;
		var maxScrollY = (!maxHeight && maxHeight != -1)? parent.scrollHeight : maxHeight;
	
		var xDist = 0;
		var yDist = 0;
	
		if (x != 0) {
			
			if(x > 0) {
				if (objLeft < 0 && x <= -objLeft) {
					xDist = x;
				} else if (objLeft < 0 && x > -objLeft) {
					xDist = -objLeft;
				} else {
					xDist = 0;
				}		
			} else {
				if (objWidth + -objLeft < maxScrollX && -x <= maxScrollX - (objWidth + -objLeft)) {
					xDist = x;
				} else if (objWidth + -objLeft < maxScrollX && -x > maxScrollX - (objWidth + -objLeft)) {
					xDist = -(maxScrollX - (objWidth + -objLeft));
				} else {
					xDist = 0;
				}		
			}
		
		}
		
		if (y != 0) {
			
			if(y > 0) {
				if (objTop < 0 && y <= -objTop) {
					yDist = y;
				} else if (objTop < 0 && y > -objTop) {
					yDist = -objTop;
				} else {
					yDist = 0;
				}		
			} else {
				if (objHeight + -objTop < maxScrollY && -y <= maxScrollY - (objHeight + -objTop)) {
					yDist = y;
				} else if (objHeight  + -objTop < maxScrollY && -y > maxScrollY - (objHeight + -objTop)) {
					yDist = -(maxScrollY - (objHeight + -objTop));
				} else {
					yDist = 0;
				}	
			}
		}	
		
		new Effect.Move(objId, { x: xDist, y: yDist, duration: duration,  transition: Effect.Transitions.slowstop, mode: 'relative'});
	}
}