
animationLock = false;
isIE = (navigator.userAgent.toLowerCase().indexOf("msie")!=-1);
stdBlockSize = (navigator.userAgent.toLowerCase().indexOf("firefox")!=-1)?100:10;
gradience = (navigator.userAgent.toLowerCase().indexOf("firefox")!=-1)?70:10;

k=0;

function gId(someId){return document.getElementById(someId);}

function fadeStart(targetImg,thisFadeFunction,thisEndState)
{
	if(!animationLock)
	{
		gId("arrowHome").style.visibility = "hidden";
		animationLock = true;
		targetElement = gId("myContainer1");
		backImage = new Image();
		backImage.src = targetImg;
		baseId = "element";
		endstateFunction = thisEndState;
		fadeSomeWay(thisFadeFunction);
	}
}

function outside_atrium() { setFader("bottomFader","siege.jpg",bottomToTop,atrium_outside,335,530); setFader("topFader","keepers.jpg",topToBottom,atrium_mainhall,340,5); setAntechamberBosses() }
function atrium_outside() { setFader("topFader","antechamber.jpg",topToBottom,outside_atrium,454,0); hideFader("bottomFader"); setSiegeBosses() }
function atrium_mainhall() { setFader("bottomFader","antechamber.jpg",bottomToTop,mainhall_atrium,478,555); setFader("topFader","spark.jpg",topToBottom,mainhall_spark,240,190); setFader("leftFader","descent.jpg",leftToRight,mainhall_descent,263,464); setKeepersBosses() }
function mainhall_atrium() { outside_atrium(); hideFader("leftFader") }
function mainhall_spark() { setFader("bottomFader","keepers.jpg",bottomToTop,spark_mainhall,400,520); hideFader("leftFader"); hideFader("topFader"); setSparkBosses() }
function mainhall_descent() { setFader("rightFader","keepers.jpg",rightToLeft,descent_mainhall,330,311+2); hideFader("leftFader"); hideFader("topFader"); hideFader("bottomFader"); setDescentBosses() }
function spark_mainhall() { atrium_mainhall(); }
function descent_mainhall() { atrium_mainhall(); hideFader("rightFader"); }

function setSiegeBosses() { setBoss("xt",471,81); setBoss("razor",528,163); setBoss("ignis",370,161); setBoss("flamo",477,245); }
function setAntechamberBosses() { setBoss("kologarn",359,69); setBoss("algalon",780,295); setBoss("council",140,366); }
function setKeepersBosses() { setBoss("aurayia",498,366); setBoss("hodir",656,411); setBoss("thoooor",708,310); setBoss("freya",519,140); }
function setSparkBosses() { setBoss("mimiron",422,260); }
function setDescentBosses() { setBoss("vezax",556,389); setBoss("yoggie",669,258); }

function setBoss(thisBoss,thisX,thisY)
{
	var newBossElement = document.createElement("div");
	newBossElement.className = "bossElement";
	newBossElement.style.left = (thisX>0)?thisX+"px":thisX+320+"px";
	var leftShow = (thisX+335>902)?thisX-350:thisX+60;
	newBossElement.style.top = thisY+"px";
	newBossElement.onmouseover = function(){setLolBoss(thisBoss,leftShow,thisY+10)};
	newBossElement.onmouseout = function(){hideLolBoss()};
	newBossElement.onclick = function(){hydraVision(thisBoss+".jpg")};
	targetElement.appendChild(newBossElement);
}

function setFader(thisFader,thisImage,thisFadeFunction,thisEndState,fLeft,fTop)
{
	var targetFader = gId(thisFader);
	targetFader.style.display = "block";
	targetFader.style.left = fLeft+"px";
	targetFader.style.top = fTop+"px";
	targetFader.onclick = function(){ fadeStart(thisImage,thisFadeFunction,thisEndState) }
}

function hideFader(thisFader) { gId(thisFader).style.display = "none"; }

function newSegment(thisWidth,thisHeight,bgLeft,bgTop,offsetTop,offsetLeft,thisID)
{
	var newElement = document.createElement("div");
	newElement.style.backgroundImage = "url("+backImage.src+")";
	newElement.style.backgroundPosition = bgLeft+"px "+bgTop+"px";
	newElement.style.height = thisHeight+"px";
	newElement.style.width = thisWidth+"px";
	newElement.style.opacity = "0";
	newElement.style.filter = "alpha(opacity=0)"
	newElement.className = "0";
	newElement.style.position = "absolute";
	newElement.style.top = offsetTop+"px";
	newElement.style.left = offsetLeft+"px";
	newElement.id = baseId+thisID;
	return newElement;
}

//thisWidth,thisHeight,bgLeft,bgTop,offsetTop,offsetLeft,thisID

function leftToRight(i) {targetElement.appendChild(newSegment(stdBlockSize,backImage.height,(-i*stdBlockSize),0,0,(i*stdBlockSize),i));}
function rightToLeft(i) {targetElement.appendChild(newSegment(stdBlockSize,backImage.height,(-backImage.width+i*stdBlockSize+stdBlockSize),0,0,(backImage.width-i*stdBlockSize-stdBlockSize),i));}
function topToBottom(i) {targetElement.appendChild(newSegment(backImage.width,stdBlockSize,0,(-i*stdBlockSize),(i*stdBlockSize),0,i));}
function bottomToTop(i) {targetElement.appendChild(newSegment(backImage.width,stdBlockSize,0,(-backImage.height+i*stdBlockSize+stdBlockSize),(backImage.height-i*stdBlockSize-stdBlockSize),0,i));}

function fadeSomeWay(someDirection)
{
	if(backImage.complete)
	{
		numSegments = Math.ceil(backImage.width/stdBlockSize);
		for(i=0;i<numSegments;i++)
		{
			someDirection(i);
		}
		faderArray = new Array();
		faderCounter = 0;
		for(j=0;j<numSegments;j++)
		{
			window.setTimeout("launchFade("+j+")",j*gradience);
		}
	}
	else window.setTimeout("fadeSomeWay("+someDirection+")",50);
}

function launchFade(thisElement)
{
	faderArray[faderCounter++] = window.setInterval("fadeSegment("+thisElement+")",10);
}

fadeSegment = (!isIE)?function(thisElement)
{
	var currentSegment = gId(baseId+thisElement);
	if(currentSegment.style.opacity >= 1)
	{
		window.clearInterval(faderArray[thisElement]);
		if(thisElement==numSegments-1)
		{
			targetElement.style.backgroundImage = "url("+backImage.src+")";
			targetElement.innerHTML = "";
			endstateFunction();
			gId("arrowHome").style.visibility = "visible";
			animationLock = false;
		}
	}
	else
	{
		currentSegment.style.opacity = eval(currentSegment.style.opacity)+0.04;
	}
}:
function(thisElement)
{
	var currentSegment = gId(baseId+thisElement);
	var ieOpacityCrutch = currentSegment.className;
	if(ieOpacityCrutch == "100")
	{
		window.clearInterval(faderArray[thisElement]);
		if(thisElement==numSegments-1)
		{
			targetElement.style.backgroundImage = "url("+backImage.src+")";
			targetElement.innerHTML = "";
			endstateFunction();
			gId("arrowHome").style.visibility = "visible";
			animationLock = false;
		}
	}
	else
	{
		currentSegment.className = 10+parseInt(currentSegment.className);
		currentSegment.style.filter = "alpha(opacity="+currentSegment.className+")";
	}
}

function setLolBoss(thisBoss,thisLeft,thisTop)
{
	gId("loreBox").innerHTML = "<div class='lolthumb'><div><img src='"+thisBoss+"-thumb.jpg'/></div></div>"+bossLol[thisBoss];
	gId("lolBoss").style.top = (thisTop+gId("lolBoss").offsetHeight<640)?thisTop+"px":640-gId("lolBoss").offsetHeight+"px";
	gId("lolBoss").style.left = thisLeft+"px";
	gId("lolBoss").style.visibility = "visible";
}

function hideLolBoss() { gId("lolBoss").style.visibility = "hidden"; }

bossLol = new Object();
bossLol["xt"] = "<span>XT-002 Deconstructor</span><b>XT-002 Deconstructor</b> Mimiron engineered this clockwork giant, who dominates the scrapyard area in Ulduar. XT-002 considers himself to be his inventor's son, causing the machine to behave like a young boy.";
bossLol["razor"] = "<span>Razorscale</span><b>Razorscale</b> Previously known as Veranus, this creature was captured by Loken and twisted into a vicious weapon. Under Loken's orders, Ignis the Furnace Master fused iron plates onto Razorscale's scales to enhance her deadly strikes.";
bossLol["ignis"] = "<span>Ignis the Furnace Master</span><b>Ignis the Furnace Master</b> Like the other titan creations in Ulduar, Ignis now serves the Old God Yogg-Saron. This imposing fire giant toils over the Colossal Forge, creating the iron armies that will conquer Azeroth in Yogg-Saron's name.";
bossLol["flamo"] = "<span>Flame Leviathan</span><b>Flame Leviathan</b> This massive armored tank guards the courtyard entrance in Ulduar. The watcher Mimiron constructed the Flame Leviathan as part of his V0-L7R-0N weapons platform.";
bossLol["kologarn"] = "<span>Kologarn</span><b>Kologarn</b> Loken requisitioned ignis the Furnace Master to create this towering giant as a guard for the Shattered Walkway. His oversized proportions, including a pair of massive arms, allow Kologarn to easily crush any intruders who attempt to reach the inner sanctum.";
bossLol["algalon"] = "<span>Algalon the Observer</span><b>Algalon the Observer</b> Loken's death triggered a failsafe mechanism warning the titans that Azeroth had lost its foremost guardian. Algalon the Observer has been sent to examine the situation and, if necessary, transmit a reply-code that will restructure the entire world, wiping out all of its current inhabitants.";
bossLol["council"] = "<span>The Assembly of Iron</span><b>The Assembly of Iron</b> The iron armies are led by three fearsome generals, each representing a different race. These leaders are known as Stormcaller Brundir, Runemaster Molgeim, and Steelbreaker.";
bossLol["aurayia"] = "<span>Auriaya</span><b>Auriaya</b> Ulduar's archivist patrols the Observation Ring accompanied by ferocious cats. Years of solitude have weighed heavily on Auriaya, and the Old God's growing power seems to have destroyed the last shreds of her sanity.";
bossLol["hodir"] = "<span>Hodir</span><b>Hodir</b> The giant Hodir once presided over the Temple of Winter, lending his guidance to the frost giants in the Storm Peaks. Now the watcher dwells in an ice cave in the Halls of Winter, forced to serve the will of Yogg-Saron.";
bossLol["thoooor"] = "<span>Thorim</span><b>Thorim</b> For many years Thorim believed that the ice giants had murdered his beloved wife, Sif, not realizing that his brother, Loken, was truly responsible. When Thorim learned the truth, Loken ensnared him and brought him to Ulduar.";
bossLol["freya"] = "<span>Freya</span><b>Freya</b> The watcher Freya was formerly a protector of all living things, aided by three stoic elders. Though her conservatory remains lush and verdant, she has also succumbed to the Old God's maddening presence.";
bossLol["mimiron"] = "<span>Mimiron</span><b>Mimiron</b> A brilliant inventor, Mimiron has been responsible for several of the most advanced mechanisms on Azeroth. But ever since he was subjected to Loken's disturbed influence, this watcher of Ulduar has only constructed war machines.";
bossLol["vezax"] = "<span>General Vezax</span><b>General Vezax</b> Strange creatures known as faceless ones lurk in the depths of Ulduar. One of their mightiest commanders, General Vezax, guards the twisted passages leading to the Prison of Yogg-Saron.";
bossLol["yoggie"] = "<span>Yogg-Saron</span><b>Yogg-Saron</b> Long ago the titans imprisoned Yogg-Saron deep within Ulduar to save Azeroth from the Old God's destructive power. But after years of plotting, Yogg-Saron has succeeded in corrupting its guards, and now the monstrous creature is finally breaking free.";
