/** Written by Pamela Ueckerman 2007 - NOT part of Scriptaculous**/
function showPhoto(type, itemId) {
	var width = document.getElementById(type+"-img-"+itemId).width;
	var height = document.getElementById(type+"-img-"+itemId).height;

	new WebSplash.Appear(type+'-photo-'+itemId, width, height, false);
}

var WebSplash = { 
	resize: function (id, width, height) {
		var splash = document.getElementById(id);
		//reset the position
		splash.style.left = 0 + "px";
		splash.style.top = 0 + "px";
		
		splash.style.width = width + "px";
		splash.style.height = height + "px";
	},
	
	center: function(id, width, height) {
 		var splash = document.getElementById(id);
		if (width != -1) {
			splash.style.left = (((this.getPageWidth(width) - width) /2 ) + 16) + "px";
		}
		if (height != -1) {
			splash.style.top = (((this.getPageHeight(height) - height) /2) + 25) + "px";
		}
	},
	
	moveOut: function(x, y) {
		new Effect.Move(id, {x: x, y: y, duration: 2});
		setTimeout("new Effect.Fade(id)", 1000);
	}, 
	
	getPageWidth: function(width) {
		if( window.innerWidth) { // Firefox 
			return innerWidth;
		}
		else if( document.body.scrollWidth) // all but Explorer Mac
		{
			return document.body.scrollWidth;
		}
		else // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		{ 
			return document.body.offsetWidth; 
		}
		
		return pageWidth;
	},
	
	getPageHeight: function(height) {
		if( window.innerHeight) { // Firefox 
			return window.innerHeight;
		}
		else if( document.body.scrollHeight) // all but Explorer Mac
		{
			return document.body.scrollHeight;
		}
		else // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		{ 
			return document.body.offsetHeight; 
		}
			
		return pageHeight;			
	}
};

WebSplash.Appear = Class.create();
WebSplash.Appear.prototype = {
	initialize: function (id, width, height, disappearByDefault) {	
		WebSplash.resize(id, width, height);
		WebSplash.center(id, width, height);
		
		if (!disappearByDefault) {
			var splash = document.getElementById(id);
			splash.innerHTML += "<div id='SplashClose'><a href='javascript:void(0)' onclick='new Effect.Fade(\""+id+"\"); $(\"mask\").toggle();'>&gt; close image</a></div>";	
		}
		$("mask").toggle();	
		new Effect.Appear(id);
		if (disappearByDefault) {
			setTimeout("new Effect.Fade(id); $(\"mask\").toggle();", 6000);
		}
	}
}

WebSplash.Puff = Class.create();
WebSplash.Puff.prototype = {
	initialize: function (id, width, height, disappearByDefault) {	
		WebSplash.resize(id, width, height);
		WebSplash.center(id, width, height);
		
		if (!disappearByDefault) {
			var splash = document.getElementById(id);
			splash.innerHTML += "<div id='SplashClose'><a href='javascript:void(0)' onclick='new Effect.Puff(\""+id+"\", {scaleFromCentre: true})'>&gt; close image</a></div>";	
		}
		
		new Effect.Appear(id);
		if (disappearByDefault) {
			setTimeout("new Effect.Puff(id, {scaleFromCentre: true})", 6000);
		}
		
	}
}

WebSplash.Drop = Class.create();
WebSplash.Drop.prototype = {
	initialize: function (id, width, height, disappearByDefault) {	
		WebSplash.resize(id, width, height);
		WebSplash.center(id, width, -1);
		
		if (!disappearByDefault) {
			var splash = document.getElementById(id);
			splash.innerHTML += "<div id='SplashClose'><a href='javascript:void(0)' onclick='new WebSplash.moveOut(0, " + height + ")'>&gt; close image</a></div>";	
		}
		
		var dist = (WebSplash.getPageHeight() - height) / 2;
		new Effect.Appear(id);
		new Effect.Move(id, {x: 0, y: dist, duration: 2});
		if (disappearByDefault) {
			setTimeout("new WebSplash.moveOut(0, " + height + ")", 6000);
		}
	
	}
}

WebSplash.Slide = Class.create();
WebSplash.Slide.prototype = {
	initialize: function (id, width, height, disappearByDefault) {	
		WebSplash.resize(id, width, height);
		WebSplash.center(id, -1, height);
		
		if (!disappearByDefault) {
			var splash = document.getElementById(id);
			splash.innerHTML += "<div id='SplashClose'><a href='javascript:void(0)' onclick='new WebSplash.moveOut(" + height + ",0)'>&gt; close image</a></div>";	
		}
		
		new Effect.Appear(id);
		var dist = (WebSplash.getPageWidth() - width) / 2;
		new Effect.Move(id, {x: dist, y: 0, duration: 2});
		if (disappearByDefault) {
			setTimeout("new WebSplash.moveOut(" + height + ",0)", 6000);
		}
	
	}
}


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

WebSplash.Slideshow = Class.create();
WebSplash.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'});
	}
}