document.write("<style>\
html,body{overflow:hidden}\
#home #str-container{\
min-height:none;\
overflow:hidden;\
}\
\
#home #str-contents{\
height:100%;\
}\
\
#home #str-footer-container{\
z-index:16384;\
}\
\
#home #slideshow_home{\
position:relative;\
width:100%;\
height:100%;\
overflow:hidden;\
visibility:hidden;\
}\
\
#home #slideshow_home ul,\
#home #slideshow_home ul li,\
#home #slideshow_home ul li a{\
display:block;\
position:absolute;\
top:0;\
left:0;\
width:100%;\
height:100%;\
}\
\
#home #slideshow_home li .slidemaximage{\
position:relative;\
display:block;\
width:100%;\
height:100%;\
}\
</style>");

$(function()
{
	/* *********************************************************************** *
	 * Constants
	 * *********************************************************************** */
	
	var /** @type number */
	    DURATION = 2000,
			/** @type number */
	    INTERVAL = 4000;
	
	/* *********************************************************************** *
	 * Fields
	 * *********************************************************************** */
	
	var /** @type HTMLElement */
	    slideshow,
			/** @type HTMLElement */
			header,
			/** @type HTMLElement */
			title,
			/** @type HTMLElement */
			footer,
			/** @type NodeList */
	    slides,
			/** @type number */
	    index,
			/** @type jQuery */
			animator,
			/** @type number */
			aspectRatio,
			/** @type jQuery */
			shade;
	
	/* *********************************************************************** *
	 * Functions
	 * *********************************************************************** */
	
	/**
	 * @returns {number} 
	 */
	function getNextIndex()
	{
		return (slides.length >= 0)
			? (index + 1 < slides.length) ? index + 1 : 0
			: -1;
	}
	
	/**
	 * @returns {number} 
	 */
	function getPreviousIndex()
	{
		return (slides.length >= 0)
			? (index > 0) ? index - 1 : slides.length - 1
			: -1;
	}
	
	/**
	 * @param {HTMLElement} e 
	 * @returns {Function} 
	 */
	function getAnimateStepFunction(e)
	{
		if (/(?:\s|^)([\w$]+)\(([^)]*)\)/.test(e.className))
		{
			var name = RegExp.$1 + "_animation",
			    func = eval("typeof " + name + "==\"function\"?" + name + ":null"),
			    args = RegExp.$2.split(/\s*,\s*/),
					startOpacity;
			
			if (typeof func != "function")
				return null;
			
			startOpacity = Number(args.shift());
			
			if (isNaN(startOpacity) || startOpacity < 0 || startOpacity > 1)
				startOpacity = 1;
			
			args.unshift(Number.NaN);
			
			return function(now, fx)
			{
				$(slides[getPreviousIndex()]).css("opacity", 1 - now);
				
				$(slides[index]).css(
				{
					opacity : startOpacity + (1 - startOpacity) * now,
					width : slides[index].parentNode.offsetWidth + "px",
					height : slides[index].parentNode.offsetHeight + "px"
				});
				
				args[0] = now;
				func.apply(null, args);
			};
		}
		
		return null;
	}
	
	/**
	 * @param {number} i 
	 */
	function orderAsToHighest(i)
	{
		var j, v = slides.length, n = i;
		
		if (i < slides.length)
		{
			for (; i < slides.length; i++, v--)
				slides[i].style.zIndex = v;
			
			for (j = 0; j < n; j++)
				slides[j].style.zIndex = n - j;
		}
	}
	
	/**
	 *
	 */
	function animateOne()
	{
		window.setTimeout(function()
		{
			var stepFunction = getAnimateStepFunction(
				slides[index].getElementsByTagName("IMG").item(0));
			
			$(slides[index]).css(
			{
				width   : "100%",
				height  : "100%",
				top     : "auto",
				right   : "auto",
				bottom  : "auto",
				left    : "auto",
				opacity : 1
			});
			
			if (stepFunction == null)
				animateCompleteCallback();
			
			else
				animator.animate({ time : 1 },
				{
					duration : DURATION,
					step : stepFunction,
					complete : animateCompleteCallback
				});
			
		}, INTERVAL);
	}
	
	/* *********************************************************************** *
	 * Callbacks
	 * *********************************************************************** */
	
	/**
	 * @param {number} i 
	 * @returns {boolean} 
	 */
	function imageFilter(i)
	{
		return !this.complete;
	}
	
	/**
	 *
	 */
	function animateCompleteCallback()
	{
		animator.css("time", 0);
		
		orderAsToHighest(index);
		
		index = getNextIndex();
		
		animateOne();
	}
	
	/**
	 * @param {Event} event 
	 */
	function windowResize(event)
	{
		var vh = $(window).height();
		
		header.parentNode.style.height = vh + "px";
		
		title.parentNode.style.height =
			vh - header.offsetHeight - footer.offsetHeight + "px";
		
		title.style.top = slideshow.offsetHeight / 2 - title.offsetHeight / 2 + "px";
		
		$(slides).each(function(i, e)
		{
			e.style.width = e.parentNode.offsetWidth + "px";
			e.style.height = e.parentNode.offsetHeight + "px";
		});
		
	}
	
	/* *********************************************************************** *
	 * Animation Functions
	 * *********************************************************************** */
	 
	/**
	 * @param {number} now 
	 */
	function fade_animation(now)
	{
	}
	 
	/**
	 * @param {number} now 
	 * @param {string} ratio 
	 * @param {string} dir 
	 */
	function pan_animation(now, ratio, dir)
	{
		ratio = Number(ratio);
		
		var p, e = slides[index];
		
		if (typeof dir == "string")
		{
			switch (dir.toLowerCase())
			{
				case "left":
				case "right":
					e.style[dir] = -1 * (1 - now) * e.offsetWidth * ratio + "px";
					break;
					
				case "top":
				case "bottom":
					e.style[dir] = -1 * (1 - now) * e.offsetHeight * ratio + "px";
					break;
					
				default:
					break;
			}
		}
	}
	
	/**
	 * @param {number} now 
	 * @param {string} ratio 
	 * @param {string} origin 
	 */
	function zoom_animation(now, ratio, origin)
	{
		ratio = Number(ratio);
		
		var e = slides[index],
		    zoom = ratio + (1 - ratio) * now;
		
		e.style.width = slideshow.offsetWidth * zoom + "px";
		e.style.height = slideshow.offsetHeight * zoom + "px";
		
		if (now == 0 && typeof origin == "string")
		{
			$(origin.split(/\s*-\s*/)).each(function(i, o)
			{
				switch (o.toLowerCase())
				{
					case "top":
						e.style.top = "0";
						e.style.bottom = "auto";
						break;
						
					case "bottom":
						e.style.top = "auto";
						e.style.bottom = "0";
						break;
						
					case "left":
						e.style.left = "0";
						e.style.right = "auto";
						break;
						
					case "right":
						e.style.left = "auto";
						e.style.right = "0";
						break;
						
					default:
				}
			});
		}
	}
	
	/* *********************************************************************** *
	 * Entry Point
	 * *********************************************************************** */
	
	header = document.getElementById("str-header-container");
	title = document.getElementById("home-main-container");
	footer = document.getElementById("str-footer-container");
	slideshow = document.getElementById("slideshow_home");
	slides = $("> :first-child > li", slideshow).get();
	
	if (0 == slides.length)
		return;
	
	shade = $(slideshow.parentNode.appendChild(document.createElement("ANONYM")));
	
	shade.css({
		position : "absolute",
		zIndex : 1024,
		width : slideshow.offsetWidth + "px",
		height : slideshow.offsetHeight + "px",
		top : slideshow.offsetTop + "px",
		left : slideshow.offsetLeft + "px",
		backgroundColor : "white",
		opacity : 1
	});
	
	(function()
	{
		if (0 != $("img", slideshow).filter(imageFilter).length)
		{
			window.setTimeout(arguments.callee, 0);
			return;
		}
		
		index = 1;
		animator = $(document.createElement("ANIMATOR"));
		
		animator.css("time", 0);
		
		orderAsToHighest(0);
		
		slideshow.style.visibility = "visible";
		$(slides).not(":first").css("opacity", 0);
		$(window).resize(windowResize).resize();
		
		shade.animate({ opacity : 0 },
			{
				duration : 2000,
				step : function(now, fx)
				{
					this.style.width = slideshow.offsetWidth + "px";
					this.style.height = slideshow.offsetHeight + "px";
				},
				complete : function()
				{
					this.parentNode.removeChild(this);
					animateOne();
				}
			}
		);
		
	})();
});
