var totalTime=0;

function doFade(fadeObj,cssID,dur,pauseTime,end)
{
/*
 * EFFECTS: Fades cssID in and out using dur for the length of the fades, pausing for
 * 			pause microseconds and restoring cssID to hidden in end microseconds.
 *
 *
 */
	fadeObj = new Fx.Style(cssID,'opacity',
		{duration: dur,transition: Fx.Transitions.quartOut}
		);

		fadeObj.start.pass([0,1], fadeObj).delay(pauseTime+totalTime);
		fadeObj.start.pass([1,0], fadeObj).delay(end-dur+totalTime);
		
		totalTime=end-dur+totalTime;
}

function doFadeQuote(fadeObj,fadeObj2,sildeObj,cssID,dur,pauseTime,end,direct)
{
/*
 * EFFECTS: Fades cssID in and out using dur for the length of the fades, pausing for
 * 			pause microseconds and restoring cssID to hidden in end microseconds.
 *
 *
 */
	
	var authorID = (cssID+"Author");
	var slideEnd = 0;
	
	fadeObj = new Fx.Style(cssID,'opacity',
		{duration: dur,transition: Fx.Transitions.quartOut}
		);

	fadeObj2 = new Fx.Style(authorID,'opacity',
		{duration: dur,transition: Fx.Transitions.quartOut}
		);

	slideObj = new Fx.Style(authorID,'margin-left',
		{duration: end*3,transition: Fx.Transitions.quartOut}
		);

		slideBegin	= $(authorID).getStyle("margin-left");
		if (direct=="left")	{ slideEnd = parseFloat($(cssID).getStyle("margin-left"));}
		else		{ slideEnd = parseFloat($(cssID).getStyle("margin-left"))+getIDWidth(cssID)-getIDWidth(authorID);}
		
		fadeObj.start.pass([0,1], fadeObj).delay(pauseTime+totalTime);
		fadeObj.start.pass([1,0], fadeObj).delay(end-dur+totalTime);
		fadeObj.start.pass([0,1], fadeObj2).delay(pauseTime+totalTime);
		fadeObj.start.pass([1,0], fadeObj2).delay(end-dur+totalTime);
		fadeObj.start.pass([slideBegin,slideEnd], slideObj).delay(pauseTime+totalTime);

		
		totalTime=end-dur+totalTime;
}

function setLocFromCenter(modID,xVal,yVal,bounded)
/*
 *	EFFECTS: Sets modID's location to xVal from center & yVal from center. 
 *			 bounded prevents settings < 0 or > Width/Height.
 */
{
	$(modID).setStyle("margin-left",leftFromCenter(modID,xVal,bounded).toString()+"px");	
	$(modID).setStyle("margin-top",topFromCenter(modID,yVal,bounded).toString()+"px");	
}

function getIDWidth(modID)
{
	return parseFloat($(modID).getStyle('width'));
}

function getIDHeight(modID)
{
	return parseFloat($(modID).getStyle('height'));
}

function getIDLeft(modID)
{
	return parseFloat($(modID).getStyle('margin-left'));
}

function getIDTop(modID)
{
	return parseFloat($(modID).getStyle('margin-top'));
}

function getIDTopFromCenter(modID)
{
	return (parseFloat($(modID).getStyle('margin-top')) - (Window.getHeight()/2));
}

function getIDLeftFromCenter(modID)
{
	return (parseFloat($(modID).getStyle('margin-left')) - (Window.getWidth()/2));
}

function topFromCenter(modID,yVal,bounded)
/*
 * Returns absolute top value yVal from center of window.
 * Bounded is true by default.
 * 
 */
{
	var centerHeight=Window.getHeight()/2;
	var modHeight = getIDHeight(modID);
	var newTop = -1;
	if (bounded != false) bounded = true;
	
	if (bounded==true)
	{
		if ((centerHeight+yVal) < 0) newTop = 0;
		else if ((centerHeight+yVal+modHeight) > (Window.getHeight())) newTop=(Window.getHeight()-20-modHeight); 
		else newTop = centerHeight+yVal;
	}
	else newTop	= centerHeight+yVal;
	
	return newTop;
}

function leftFromCenter(modID,xVal,bounded)
/*
 * Returns absolute left value xVal from center of window
 * Bounded is true by default.
 * 
 */
{
	var centerWidth=Window.getWidth()/2;
	var modWidth = getIDWidth(modID);
	var newLeft = -1;
	if (bounded != false) bounded = true;
	
	if (bounded==true)
	{
		if ((centerWidth+xVal) < 0){ newLeft = 0;}
		else if ((centerWidth+xVal+modWidth) > (Window.getWidth())) {newLeft=(Window.getWidth()-20-modWidth);}
		else {newLeft = centerWidth+xVal;}
	}
	else newLeft = centerWidth+xVal;

	return newLeft;
}


function getCenterWidth(obj)
{
	return (-(getIDWidth(obj)/2));
}

function getCenterHeight(obj)
{
	return (-(getIDHeight(obj)/2));
}


var titleFade,enterFade;
function doEnter()
{
/*
 * EFFECTS: Fades cssID in and out using dur for the length of the fades, pausing for
 * 			pause microseconds and restoring cssID to hidden in end microseconds.
 *
 *
 */
	enterFade = new Fx.Style("enter",'opacity',
		{duration: 1500,transition: Fx.Transitions.quartOut}
		);
	titleFade = new Fx.Style("mainTitle",'opacity',
		{duration: 1500,transition: Fx.Transitions.quartOut}
		);


		enterFade.start.pass([0,1], enterFade).delay(1600+totalTime);
		titleFade.start.pass([0,1], titleFade).delay(600+totalTime);
}

function doFadeNoOut(fadeObj,cssID,dur,pauseTime)
{
/*
 * EFFECTS: Fades cssID in and out using dur for the length of the fades, pausing for
 * 			pause microseconds and restoring cssID to hidden in end microseconds.
 *
 *
 */
	fadeObj = new Fx.Style(cssID,'opacity',
		{duration: dur,transition: Fx.Transitions.quartOut}
		);

		fadeObj.start.pass([0,1], fadeObj).delay(pauseTime+totalTime);

}


/* Browser Detection Script from http://www.quirksmode.org/js/detect.html */

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

/* End Browser Detection Script */

/* Begin Location Setting */
setLocFromCenter("skipIntro",9000,9000,true);
setLocFromCenter("BrowserWarning",-9000,9000,true);

setLocFromCenter("quote1",100,-300,true);
setLocFromCenter("quote1Author",getIDLeftFromCenter("quote1")+getIDWidth("quote1")-getIDWidth("quote1Author"),getIDTopFromCenter("quote1")+getIDHeight("quote1")+7,true);

setLocFromCenter("quote2",-400,50,true);
setLocFromCenter("quote2Author",getIDLeftFromCenter("quote2"),getIDTopFromCenter("quote2")+getIDHeight("quote2")+7,true);

setLocFromCenter("quote3",-350,-200,true);
setLocFromCenter("quote3Author",getIDLeftFromCenter("quote3")+getIDWidth("quote3")-getIDWidth("quote3Author"),getIDTopFromCenter("quote3")+getIDHeight("quote3")+7,true);


setLocFromCenter("mainTitle",-9000,-9000,true);
setLocFromCenter("enter",-(getIDWidth("enter")/2),-(getIDHeight("enter")/2),true)
/* End Location Setting */


/* Begin Effects Setting/Timeline */
var BrowserWarning;
if  (	((BrowserDetect.browser == "Safari") && ((BrowserDetect.version == "an unknown version") || (BrowserDetect.version < 511)))
			||
			((BrowserDetect.browser == "Konqueror") && (BrowserDetect.version <= 3.3))
		)
doFadeNoOut(BrowserWarning,"BrowserWarning",200,0);


var skipIntro;
doFadeNoOut(skipIntro,"skipIntro",500,0);

var quote1a,quote1b,quote1s;
doFadeQuote(quote1a,quote1b,quote1s,"quote1",1500,0,18000,"left");

var quote2a,quote2b,quote2s;
doFadeQuote(quote2a,quote2b,quote2s,"quote2",1500,600,12000,"right");

var quote3a,quote3b,quote3s;
doFadeQuote(quote3a,quote3b,quote3s,"quote3",1500,600,16000,"left");

doEnter();
/* End Effects */
