
animationLock = false;
isIE = (navigator.userAgent.toLowerCase().indexOf("msie")!=-1);
stdBlockSize = ((navigator.userAgent.toLowerCase().indexOf("firefox")!=-1) || isIE)?30:10; //lower block size = more granular gradient, bigger strain on browser; chrome + safari can handle low numbers easily, keeping those consistent for now though
gradience = ((navigator.userAgent.toLowerCase().indexOf("firefox")!=-1) || isIE)?0.1:0.04; //lower gradience = more granular gradient, bigger strain on browser
gradientLength = 1/gradience; //should be integer, but does not have to be

/*
Explanation of the above:
- stdBlockSize regulates how wide (or tall, for vertical fades) each "chunk" is. The higher the number, the fewer chunks used for the animation, the lighter the load on the browser
- gradience regulates the opacity increase during each fade-in step. The higher the gradience, the fewer opacity steps, the lighter the load on the browser
- gradientLength determines how many gradient chunks are faded at one time, and indirectly the actual length of the gradient (which is stdBlockSize/gradience)
*/

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 forge_fadeState() { saronFadeDirection = rightToLeft; setClicks(0,1,1); setForgeBosses(); }
function saron_fadeState() { setClicks(1,0,1); setSaronBosses(); }
function reflection_fadeState() { saronFadeDirection = leftToRight; setClicks(1,1,0); setReflectionBosses(); }

function setClicks(forgeState,saronState,reflectionState)
{
	gId("forge_Click").onclick = (forgeState == 1)?function(){fadeStart("/shared/wow-com/images/underdev/patch3p3/bosstiary/en/forge.jpg",forgeFadeDirection,forge_fadeState)}:function(){};
	gId("saron_Click").onclick = (saronState == 1)?function(){fadeStart("/shared/wow-com/images/underdev/patch3p3/bosstiary/en/saron.jpg",saronFadeDirection,saron_fadeState)}:function(){};
	gId("reflection_Click").onclick = (reflectionState == 1)?function(){fadeStart("/shared/wow-com/images/underdev/patch3p3/bosstiary/en/reflection.jpg",reflectionFadeDirection,reflection_fadeState)}:function(){};
}

function setForgeBosses() { setBoss("bronjahm",413,308,false); setBoss("devourer",414,54,true); }
function setSaronBosses() { setBoss("ickrick",453,240,true); setBoss("garfrost",658,339,true); setBoss("tyranus",422,147,true); }
function setReflectionBosses() { setBoss("falmarv",327,476,false); setBoss("falmarv",409,393,false); setBoss("arthas",79,157,false); }

function setBoss(thisBoss,thisX,thisY,hasThumb)
{
	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(){setDungeonBoss(thisBoss,leftShow,thisY+10,hasThumb)};
	newBossElement.onmouseout = function(){hideDungeonBoss()};
	newBossElement.onclick = (hasThumb)?function(){hydraVision("/shared/wow-com/images/underdev/patch3p3/bosstiary/"+thisBoss+".jpg")}:function(){};
	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));}

forgeFadeDirection = leftToRight;
saronFadeDirection = rightToLeft;
reflectionFadeDirection = rightToLeft;

function fadeSomeWay(someDirection)
{
	if(backImage.complete)
	{
		numSegments = Math.ceil(backImage.width/stdBlockSize);
		for(var i=0;i<numSegments;i++)
		{
			someDirection(i);
		}
		faderArray = new Array();
		faderCounter = 0;
		ticks = 0;
		segmentOffset = 0;
		darthFader = window.setInterval("fadeSegments()",10);
	}
	else window.setTimeout("fadeSomeWay("+someDirection+")",50);
}

fadeSegments = (!isIE)?function()
{
	for(var i=0; i<=Math.min(gradientLength,segmentOffset); i++)
	{
		var currentSegment = gId(baseId+Math.min(eval(numSegments-1),eval(segmentOffset-i)));
		if(segmentOffset >= numSegments+gradientLength)
		{
			//terminate
			window.clearInterval(darthFader);
			targetElement.style.backgroundImage = "url("+backImage.src+")";
			targetElement.innerHTML = "";
			endstateFunction();
			gId("arrowHome").style.visibility = "visible";
			animationLock = false;
		}
		else
		{
			//increase opacity by gradience value
			currentSegment.style.opacity = eval(currentSegment.style.opacity)+gradience;
		}
	}
	segmentOffset++;
}:
function()
{
	for(var i=0; i<Math.min(gradientLength,segmentOffset); i++)
	{
		var currentSegment = gId(baseId+Math.min(eval(numSegments-1),eval(segmentOffset-i)));
		if(segmentOffset >= numSegments+gradientLength)
		{
			//terminate
			window.clearInterval(darthFader);
			targetElement.style.backgroundImage = "url("+backImage.src+")";
			targetElement.innerHTML = "";
			endstateFunction();
			gId("arrowHome").style.visibility = "visible";
			animationLock = false;
		}
		else
		{
			//increase opacity by gradience value
			currentSegment.className = 10+parseInt(currentSegment.className);
			currentSegment.style.filter = "alpha(opacity="+currentSegment.className+")";
		}
	}
	segmentOffset++;
}

function setDungeonBoss(thisBoss,thisLeft,thisTop,hasThumb)
{
	gId("loreBox").innerHTML = (hasThumb)? "<div class='lorethumb'><div><img src='/shared/wow-com/images/underdev/patch3p3/bosstiary/"+thisBoss+"-thumb.jpg'/></div></div>"+bossLore[thisBoss] : bossLore[thisBoss];
	gId("dungeonBoss").style.top = (thisTop+gId("dungeonBoss").offsetHeight<640)?thisTop+"px":640-gId("dungeonBoss").offsetHeight+"px";
	gId("dungeonBoss").style.left = thisLeft+"px";
	gId("dungeonBoss").style.visibility = "visible";
}

function hideDungeonBoss() { gId("dungeonBoss").style.visibility = "hidden"; }

bossLore = new Object();
bossLore["bronjahm"] = "<span>Bronjahm</span><b>Bronjahm</b> Also known as the Godfather of Souls, Bronjahm serves Arthas as the foreman of his mighty soul grinder engines. Bronjahm patrols the Forge of Souls to ensure that no interruptions befall the engines' operation.";
bossLore["devourer"] = "<span>Devourer of Souls</span><b>Devourer of Souls</b> As the chief operator of the Lich King's soul grinders, the creature called the Devourer dedicates himself to preventing souls from escaping the Lich King's dark machines.";
bossLore["ickrick"] = "<span>Ick and Krick</span><b>Ick and Krick</b> Astride Ick, an unusually large zombie, the devious gnome Krick supervises undead labor in the Pit of Saron.";
bossLore["garfrost"] = "<span>Forgemaster Garfrost</span><b>Forgemaster Garfrost</b> A master blacksmith and the overseer of the Scourge's cold forges, Garfrost infuses the blades of the Lich King's armies with the Old God Yogg-Saron's blood.";
bossLore["tyranus"] = "<span>Scourgelord Tyrannus</span><b>Scourgelord Tyrannus</b> A merciless and efficient slave master, Tyrannus watches over the Quarry of Tears as the Lich King's right hand. The blessings of Tyrannus' dark lord come in many forms, not the least of which is the scourgelord's frost wyrm, Rimefang.";
bossLore["falmarv"] = "<span>Falric and Marwyn</span><b>Falric and Marwyn</b> Arthas' most trusted captains during the Third War, Falric and Marwyn, were dragged into damnation with the prince, and the two played a large part in the destruction of Lordaeron. Now among the foremost of the Lich King's death knights, they serve as staunch defenders of their master's private chambers.";
bossLore["arthas"] = "<span>The Lich King</span><b>The Lich King</b> A godlike being formed from a fusion between the orc shaman Ner'zhul and the former prince, paladin, and death knight Arthas Menethil, the Lich King uses the Halls of Reflection as his private chambers and a refuge for his runeblade, Frostmourne.";
