var frameNum = 0;
var numFrames = 10;
var placeholder = null;
var finalWindow = null;
var intervalId = null;
var direction = null;

var defaultCountdown = null;
var defaultNav = "";
var cacheImage = null;


getSilverlightVersion = function() {

var SLVersion;

try {  
       try {

            var control = new ActiveXObject('AgControl.AgControl');

            if (control.IsVersionSupported("3.0"))                
               SLVersion = 3;

            else

            if (control.IsVersionSupported("2.0"))               
               SLVersion = 2;

            else

               SLVersion = 1;           
            control = null;

      }

      catch (e) {      
                     var plugin = navigator.plugins["Silverlight Plug-In"];

                     if (plugin)

                     {         

                       if (plugin.description === "1.0.30226.2")             
                          SLVersion = 2;

                       else
                          SLVersion = parseInt(plugin.description[0]);

                      }

                      else
                         SLVersion = 0;

      }

}

catch (e) { 
      SLVersion = 0;

}
return SLVersion;

}




function cyclePopup(tagID)
{
	finalWindow = document.getElementById(tagID);
	placeholder = document.getElementById(tagID+"animation");

	finalWindow.style.left = getLeftPos(document.getElementById("globalWrapper")) + 300 + "px";
	if(finalWindow.style.visibility != "visible")
	{
		var divs = document.getElementById("rhsNav").getElementsByTagName("div");

		for (i=0; i < divs.length; i++)
		{
			if (divs[i].className=="popupWrapper")
			{
				divs[i].style.visibility = "hidden";
			}
		}
		direction = 1;
		placeholder.style.visibility = "visible";
		intervalId = setInterval("animate()", 10);
	}
	else
	{
		direction = 0;
		placeholder.style.visibility = "visible";
		finalWindow.style.visibility = "hidden";
		intervalId = setInterval("animate()", 10);
	}
}

function animate()
{
	if(direction == 0)
	{
		placeholder.style.width = 25 + (40 * (10 - frameNum)) + "px";
		placeholder.style.left = getLeftPos(document.getElementById("globalWrapper")) + 300 + (20 * frameNum) + "px";
		placeholder.style.height = 20 + (28 * (10 - frameNum)) + "px";
		placeholder.style.top = 210 + (14 * frameNum) + "px";
		if (++frameNum >= numFrames)
		{
			clearInterval(intervalId);
			frameNum = 0;
			placeholder.style.visibility = "hidden";
			finalWindow.style.visibility = "hidden";
			placeholder.style.width = "0px";
			placeholder.style.height = "0px";
			intervalId = null;
		}
	}
	else
	{
		placeholder.style.width = 25 + (40 * frameNum) + "px";
		placeholder.style.left = getLeftPos(document.getElementById("globalWrapper")) + 300 + (20 * (10 - frameNum)) + "px";
		placeholder.style.height = 20 + (28 * frameNum) + "px";
		placeholder.style.top = 210 + (14 * (10 - frameNum)) + "px";
		if (++frameNum >= numFrames)
		{
			clearInterval(intervalId);
			frameNum = 0;
			finalWindow.style.visibility = "visible";
			placeholder.style.visibility = "hidden";
			placeholder.style.width = "0px";
			placeholder.style.height = "0px";
			intervalId = null;
		}
	}
}

function displayPanels(panelCount)
{
	if(panelCount > 0)
	{
		var firstPanel = Math.floor((Math.random() * panelCount) + 1)

		document.getElementById("panelWrapper" + firstPanel).style.visibility = "visible";
		document.getElementById("panelWrapper" + firstPanel).style.position = "static";
		if(panelCount > 1)
		{
			var secondPanel = Math.floor((Math.random() * panelCount) + 1)

			if((firstPanel == secondPanel) && (firstPanel != panelCount))
			{
				secondPanel = panelCount;
			}
			else
			{
				if(firstPanel == secondPanel)
				{
					secondPanel = firstPanel - 1;
				}
			}

			document.getElementById("panelWrapper" + secondPanel).style.visibility = "visible";
			document.getElementById("panelWrapper" + secondPanel).style.position = "static";

			if(panelCount > 2)
			{
				var thirdPanel = Math.floor((Math.random() * panelCount) + 1)

				if((firstPanel == secondPanel) && (firstPanel == thirdPanel) && (firstPanel != panelCount) && (secondPanel != panelCount))
				{
					thirdPanel = panelCount;
				}
				else
				{
					thirdPanel = 1;
					found = false;
					for (i=1; i < panelCount; i++)
					{
						if((firstPanel != i) && (secondPanel != i) && (found == false))
						{
							thirdPanel = i;
							found = true;
						}
					}
				}

				document.getElementById("panelWrapper" + thirdPanel).style.visibility = "visible";
				document.getElementById("panelWrapper" + thirdPanel).style.position = "static";
			}
		}
	}
}
