var frameInfo = new Array(6);
for (i = 0; i < frameInfo.length; ++i)
	frameInfo[i] = new Array(6);

frameInfo[0][0] = 1050;
frameInfo[0][1] = 50;
frameInfo[0][2] = 100;
frameInfo[0][3] = 150;
frameInfo[0][4] = 200;
frameInfo[0][5] = 250;

frameInfo[1][0] = 900;
frameInfo[1][1] = 1080;
frameInfo[1][2] = 300;
frameInfo[1][3] = 330;
frameInfo[1][4] = 360;
frameInfo[1][5] = 390;

frameInfo[2][0] = 930;
frameInfo[2][1] = 420;
frameInfo[2][2] = 1110;
frameInfo[2][3] = 450;
frameInfo[2][4] = 480;
frameInfo[2][5] = 510;

frameInfo[3][0] = 960;
frameInfo[3][1] = 540;
frameInfo[3][2] = 570;
frameInfo[3][3] = 1140;
frameInfo[3][4] = 600;
frameInfo[3][5] = 630;

frameInfo[4][0] = 990;
frameInfo[4][1] = 660;
frameInfo[4][2] = 690;
frameInfo[4][3] = 720;
frameInfo[4][4] = 1170;
frameInfo[4][5] = 750;

frameInfo[5][0] = 1020;
frameInfo[5][1] = 780;
frameInfo[5][2] = 810;
frameInfo[5][3] = 840;
frameInfo[5][4] = 870;
frameInfo[5][5] = 1220;

var flashFrom;
var flashTo;
var flashMovie;

var TimeToFade = 750.0;
var ContentLayerId = "Main";
var MenuBarId = "MenuBar";
var TargetUrl;
var preloadImages = new Array("../images/Background0.png", "../images/Background1.png", "../images/Background2.png", "../images/Background3.png", "../images/Background4.png", "../images/Background5.png");
var preImages = new Array(preloadImages.length-1);
var preloadStatus = new Array(preloadImages.length-1);

var widgets = new Array();

function play()
{
  flashMovie = document.getElementById("flashMovie");
  
  setTimeout("scanFlashState()", 2000);
  
  var frame = (flashFrom == -1 && flashTo == -1) ? 3 : frameInfo[flashFrom][flashTo];
  
  flashMovie.GotoFrame(frame);
  document.getElementById("Bkg").style.backgroundImage = "url('')";
  flashMovie.Play();
}

function playFlash()
{
  //in case the slides didn't finish yet on slow computers
  var sidebar = document.getElementById("SideBar");
  if(sidebar != null)
    sidebar.style.display = "none";
  var main = document.getElementById("Main");
  if (main != null)
    main.style.display = "none";

  setTimeout("play()", 250);
  document.getElementById("FlashHolder").style.display = "block";
}

function navigate()
{
  window.location.href= TargetUrl;
}

function scanFlashState()
{
  var x = flashMovie.IsPlaying();
  if (x)
    setTimeout("scanFlashState()", 500);
  else
    navigate();
}

String.format = function(text)
{
  if ( arguments.length <= 1 )
  {
    return text;
  }
  var tokenCount = arguments.length - 2;
  for( var token = 0; token <= tokenCount; token++ )
  {
    text = text.replace( new RegExp( "\\{" + token + "\\}", "gi" ), arguments[ token + 1 ] );
  }
  return text;
};

function slide(id, dir, start, end)
{
  var div = document.getElementById(id);
	if (dir ==  "r" && parseInt(div.style.left) < end)
	{
			div.style.left = (parseInt(div.style.left) + 20) + "px";
			setTimeout('slide("' + id + '","' + dir + '",' + start + ',' + end + ')', 25);
	}
	if (dir ==  "l" && parseInt(div.style.left) > start) 
	{
			div.style.left = (parseInt(div.style.left) - 20) + "px";
			setTimeout('slide("' + id + '","' + dir + '",' + start + ',' + end + ')', 25);
	}
}

function slideIn(id, dir, start, end)
{
  var div = document.getElementById(id);
	if (dir ==  "d" && parseInt(div.style.top) < end)
	{
    div.style.top = (parseInt(div.style.top) + 10) + "px";
    setTimeout('slideIn("' + id + '","' + dir + '",' + start + ',' + end + ')', 25);
	}
	if (dir ==  "u" && parseInt(div.style.top) > start) 
	{
    div.style.top = (parseInt(div.style.top) - 10) + "px";
    setTimeout('slideIn("' + id + '","' + dir + '",' + start + ',' + end + ')', 25);
	}
}

function querySt(ji) 
{
  hu = window.location.search.substring(1);
  gy = hu.split("&");
  for (i=0;i<gy.length;i++) 
  {
    ft = gy[i].split("=");
    if (ft[0] == ji) 
    {
      return ft[1];
    }
  }
}

function nav(url, f, to)
{
  flashTo = to;
  document.getElementById(MenuBarId).style.display = "none";
  TargetUrl = url;
  var maincontent = document.getElementById("MainContent");
  setTimeout("slide('SideBar', 'l', -480, 0)", 1200);
  for (i = 0; i < widgets.length; i++)
    animatedcollapse.toggle(widgets[i]);
  if (maincontent != null)
  {
    animatedcollapse.toggle('Scroll');
    setTimeout("slideIn('MainContent', 'u', -100, 100)", 1200);
  }
  setTimeout("playFlash()", 2000);
}

function effects()
{
  if (querySt("effects") == 1)
  {
    slide('SideBar', 'r', -480, 0);
    if (document.getElementById("MainContent") != null)
    {
      slideIn("MainContent", 'd', -100, 100);
      setTimeout("animatedcollapse.toggle('Scroll')", 750);
    }
  }
  else
  {
    document.getElementById("SideBar").style.left = 0;
    var maincontent = document.getElementById("MainContent");
    if (maincontent != null)
      maincontent.style.top = "100px";
    var scroll = document.getElementById("Scroll");
    if (scroll != null)
      scroll.style.display = "block";
  }
  for (i = 0; i < widgets.length; i++)
  {
    animatedcollapse.toggle(widgets[i]);
  }
}

function init()
{
  TargetUrl = "welcome.php";
  flashFrom = -1;
  flashTo = -1;
  
  loadImages();
  //setTimeout("playFlash()", 500);
}

function loadImages() 
{ 
	for (i = 0; i < preloadImages.length; i++) 
	{ 
		preImages[i] = new Image();
		preImages[i].src = preloadImages[i];
		preloadStatus[i] = false;
	}
	checkLoad();
}

function checkLoad() 
{
  var waiting = false;
	for (i = 0; i <= preImages.length; i++) 
	{
    if(preloadStatus[i] == false)
    {
      waiting = true;
      if (preImages[i].complete)
      { 
        preloadStatus[i] = true;
        document.getElementById("preload" + i).style.backgroundColor = "#ACD037";
      }
		}
	}
	if (waiting)
    setTimeout("checkLoad()", 200); 
  else
  {
    document.getElementById("PreloadStatus").style.display = "none";
    playFlash(); 
  }
}


function enableMenuContainer()
{
	// This enables the enableMenuContainer (:hover) by adding it to the style. 
  	// this means the lower #MenuContainer etc. is NOT in the CSS style anymore.

	var styleNode = document.createElement('style');
	var def = '#MenuContainer:hover #MenuBar .MenuItem {  height: 200px; }';
	styleNode.setAttribute("type", "text/css");

	if (styleNode.styleSheet) 
	{   
	    // IE
	    styleNode.styleSheet.cssText = def;
	}
	 else 
	{
           // the world
	    var textNode = document.createTextNode(def);
	    styleNode.appendChild(textNode);
	}

	var headNode = document.getElementsByTagName('head')[0];
	headNode.appendChild(styleNode);
}

