﻿/// <reference path="jquery.js"/>
var imgExt = ($.browser.msie && $.browser.version <= 6) ? "gif" : "png";
var preloadImg = new Image;
var preloadTxt = new Image;

function xfade(image, sleep, duration, callback)
{
	if (preloadImg.src != image) preloadImg.src = image;
	if (preloadImg.complete)
	{
		setTimeout(function()
		{
			$("#mainImg,#mainText").fadeOut(duration, function()
			{
				$("#overlayImg").css({ backgroundImage: "url(" + image + ")" }).fadeIn(duration, function()
				{
					$("#mainImg").css({ backgroundImage: "url(" + image + ")" }).show().ready(function()
					{
						if (typeof callback == "undefined") callback = function() { };
						$("#mainText,#overlayImg").hide().ready(callback);
					});
				});
			});
		}, sleep);
	}
	else
	{
		setTimeout("xfade('" + image + "', " + Math.max(sleep - 100, 0) + ", " + (duration) + ", " + callback + ")", 100);
	}
}
function textFadeIn(image, sleep, duration, callback)
{
	if (preloadTxt.src != image) preloadTxt.src = image;
	if (preloadTxt.complete)
	{
		setTimeout(function()
		{
			$("#overlayText").css({ backgroundImage: "url(" + image + ")" }).fadeIn(duration, function()
			{
				$("#mainText").css({ backgroundImage: "url(" + image + ")" }).show().ready(function()
				{
					if (typeof callback == "undefined") callback = function() { };
					$("#overlayText").hide().ready(callback);
				});
			});
		}, sleep);
	}
	else
	{
		setTimeout("textFadeIn('" + image + "', " + Math.max(sleep - 100, 0) + ", " + (duration) + ", " + callback + ")", 100);
	}
}

function fadeInParagraphs(timeBetween, duration)
{
	$(".fadein").each(function(index)
	{
		var o = $(this);
		setTimeout(function()
		{
			o.css({ opacity: 0 }).stop().fadeTo(duration, 1); // The opacity-zero-thing is an IE-fix...
		}, 50 + timeBetween * index);
	});
}
