  g_bFooter = true;
  
	function pageload(hash) {
    hash == "" ? arena.loadContent("homeContent") : arena.loadContent(hash);
    
    switch (hash) {
      case "nukeContent":
        g_bFooter = false;
        startCircle();
        if (get("theFooter").style.display == "none") {
          get("theFooter").style.display = "";
        }
      break;
      
      default:
        clearTimeout(g_circle);
        if (g_bFooter == false) {
          g_bFooter = true;
          startFooter();
        }
      break;
    }
	}
	
	$(document).ready(function(){
		// Initialize history plugin.
		// The callback is called at once by present location.hash. 
		$.historyInit(pageload);
		
		// set onlick event for buttons
		$("a[rel='history']").click(function(){
			// 
			var hash = this.href;
			hash = hash.replace(/^.*#/, '');
			// moves to a new page. 
			// pageload is called at once. 
			$.historyLoad(hash);
			return false;
		});
	});


function addLink(contentID) {
  dhtmlHistory.add(contentID);
}


function fade1() {
	$("#bgfooter").fadeOut(3000);
	$("#bgfooter2").fadeIn(3000);
}

function fade2() {
	$("#bgfooter2").fadeOut(3000);
	$("#bgfooter3").fadeIn(3000);
}

function fade3() {
	$("#bgfooter3").fadeOut(3000);
	$("#bgfooter2").fadeIn(3000);
}

function fade4() {
	$("#bgfooter2").fadeOut(3000);
	$("#bgfooter").fadeIn(3000);
}


function startFooter() {
  if (g_bFooter) {
  	$("#theFooter").fadeIn(3000);
  	fade1();
  	setTimeout(fade2, 3050);
  	setTimeout(fade3, 6100);
  	setTimeout(fade4, 9150);
  	setTimeout(startFooter, 12200);
  }
}

function fadeStar1() {
	$("#star2").fadeIn(10000);
}
function fadeStar2() {
	$("#star2").fadeOut(10000);
}
function fadeStar3() {
	$("#star1").fadeIn(10000);
}
function fadeStar4() {
	$("star1").fadeOut(10000);
}
function startStar() {
	setTimeout(fadeStar1, 25100);
	setTimeout(fadeStar2, 37000);
	setTimeout(startStar, 47100);	
}


function fadeInAll() {
	$("#welcomeArea").fadeOut(3000);
	get("ytapiplayer").innerHTML += "<object width='1' height='1' id='musicplayer'><param name='movie' value='http://www.youtube.com/v/4ShVQiPmEfA&hl=en&fs=1&autoplay=1'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed id='musicplayer' src='http://www.youtube.com/v/4ShVQiPmEfA&hl=en&fs=1&autoplay=1&enablejsapi=1&playerapiid=movie' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='1' height='1' ></embed></object>";

	startFooter();
//	setTimeout(fadeStar3, 30000);
//	setTimeout(startStar, 45000);
	$("#aliveContent").fadeOut(4000);
	$("#headstrap").fadeIn(4000);
	$("#headerImg2").fadeIn(4000);
	$("#contentBox").fadeIn(4000);
		setTimeout(function() { bl.start("headerImg2b", true, 60000); }, 5000);
}

function BrokenLight() {
	var that = this;
	var g_imgID1 = null;
	
	this.start = function(imgID, bRepeatForever, repeatTimer) {
		g_imgID = imgID;
		
		setTimeout(show, 100);
		setTimeout(hide, 250);
		setTimeout(show, 200);
		setTimeout(hide, 250);
		setTimeout(show, 320);
		setTimeout(hide, 400);
		setTimeout(show, 450);
		setTimeout(hide, 750);
		setTimeout(show, 850);
		setTimeout(hide, 950);
		setTimeout(show, 1000);
		setTimeout(hide, 1100);
		setTimeout(fadeIn, 1500);

		//hack: bl.start(), if you know how to call itself within itself here without referring to the instantiated class name, plesae let me know
		bRepeatForever ? setTimeout(function() { bl.start(imgID, true, repeatTimer); }, repeatTimer) : null;
	};
	
	function show() {
		$("#" + g_imgID).show();
	}
	
	function hide() {
		$("#" + g_imgID).hide();
	}
	
	function fadeIn() {
		$("#" + g_imgID).fadeIn(1000);
	}
}
var bl = new BrokenLight();

ytplayer = null;

function onYouTubePlayerReady(playerId) {
	ytplayer = document.getElementById("myytplayer");
}

function stopVideo() {
	get("ytapiplayer").innerHTML = "";
}

function load(index) {
	document.getElementById("bgfooter").src = "images/footer" + index + ".jpg";
}

function clearType(area) {
	get(area).innerHTML = "";	
}

function HumanTyper() {
	var that = this;
	
	this.type = function(txt, outputArea, callback, callbackTimer, bClear, clearTimer) {
		var interval = 1000;
		var output = "";
		var randomnumber = 0;
		
		for (var i = 0; i < txt.length; i++) {
			output += txt.charAt(i);
			setTimeout("ht.writeText('" + output + "', '" + outputArea + "')", interval);
			randomnumber = Math.floor(Math.random()*11)
			interval += randomnumber*80;
		}
		
		bClear ? setTimeout("clearType('" + outputArea + "')", (interval + clearTimer)) : null;
		callback ? setTimeout(callback, (interval+clearTimer+callbackTimer)) : null;
	};
	
	this.writeText = function(output, area) {
		document.getElementById(area).innerHTML = output;
	};
}

var ht = new HumanTyper();

function get(eltID) {
	return document.getElementById(eltID);
}

function Arena() {
	var that=this;
	var currentLoaded = "homeContent";
	
	this.loadContent = function(name) {
		handleDisplay(name);
		handleLoadMethod(name);
		document.forms["form"]["textfield"].focus();
	}
	
	function handleLoadMethod(name) {
		switch(name) {
			case "serviceContent":
				for (var i = 0; i < 13; i++) {
					$("#port" + (i+1)).show();
				}
			break;
			
			default:
			break;
		}
	}
	
	function handleDisplay(name) {
    $("#" + currentLoaded).hide();
		$("#" + name).fadeIn();
		currentLoaded = name;
	}
		
}

var arena = new Arena();


function centerElement(objID) {
	var windowHeight = getBrowserHeight();
	var windowWidth = getBrowserWidth();

	positionit(objID, ((windowWidth / 2)-(get(objID).offsetWidth/2)), ((windowHeight/2)-(get(objID).offsetHeight/2)) )	
}

function positionit(objID, addLeft, addTop) {
	if (addLeft == null) addLeft = 0;
	if (addTop == null) addTop = 0;
	
	var crossobj=get(objID);
	var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body
	var dsocleft=document.all? iebody.scrollLeft : pageXOffset
	var dsoctop=document.all? iebody.scrollTop : pageYOffset

	if (document.all||get){
		if (crossobj) {
			crossobj.style.left=parseInt(dsocleft)+addLeft+"px"
			crossobj.style.top=dsoctop+addTop+"px"
		}
	} 
}

function getBrowserHeight() {
	if (!document.all) {
		return window.innerHeight;	
    } else {
		return document.body.clientHeight;
    } 
}

function getBrowserWidth() {
	if (!document.all) {
	    return window.innerWidth;
    } else {
	    return document.body.clientWidth;
    } 
}
	

function init() {
	var windowWidth = getBrowserWidth();
	if (windowWidth <= 1100) {
		get("theFooter").style.bottom = "-75px";
		get("bgfooter").style.bottom = "-75px";
		get("bgfooter2").style.bottom = "-75px";
		get("bgfooter3").style.bottom = "-75px";
		get("star1").style.top = "100px";
		get("star2").style.top = "100px";
	}
	
	get("welcomeArea").style.width = windowWidth;
	$("#welcomeText").fadeIn(1000);
	ht.type("hello friend", "aliveContent", fadeInAll, 500, null, null);
//	setTimeout(ghostText, 60000);

/*
    $.blockUI.defaults.fadeOut = 0;
    loadContent(currentContent);

		$.blockUI({
		css: { 
    		top:  (jQuery(window).height() - 500) /2 + 'px', 
            left: (jQuery(window).width() - 500) /2 + 'px', 
            width: '500px',
            height:'50px',
			textAlign: 'left'
		},
		message: "Loading all images - Will take a few minutes"
  	});

*/
    var html = "";
    for (var i = 0; i < 360; i++) {
      html += "<img src='images/laboratory/nuke/smallcircle/smallcircleAngle." + i + ".png'>";
    }

    html += "<img src='images/laboratory/nuke/smallcircle/smallcircleAngle.360.png' onload='startCircleOK();'>";
    get("imageLoad").innerHTML = html;
}

var aGhostStrings = new Array();
	aGhostStrings[0] = "can anybody see this";
	aGhostStrings[1] = "i need help";
	aGhostStrings[2] = "can somebody help me...";
	aGhostStrings[3] = "help me";
	
var aGhostFontSize = new Array();
	aGhostFontSize[0] = "18";
	aGhostFontSize[1] = "14";
	aGhostFontSize[2] = "16";
	
function theGhost() {
	get("ytapiplayer").innerHTML = "<object width='1' height='1' id='musicplayer'><param name='movie' value='http://www.youtube.com/watch?v=ptZ7KV5h-f0&autoplay=1'></param><param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param><embed id='musicplayer' src='http://www.youtube.com/watch?v=ptZ7KV5h-f0&autoplay=1&enablejsapi=1&playerapiid=movie' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='1' height='1' ></embed></object>";
	$("#theGhostLnk").fadeOut(5000);
	g_bGhostText = false;
	setTimeout(theGhost2, 10000);
}

function theGhost2() {
	get("ghostExplodeArea").innerHTML = "<img id='theHorror' src='images/horror.jpg' style='position:absolute;z-index:1000;left:200px;top:0;display:none;'>";
	get("ghostText1").style.top = "400px";
	get("ghostText1").style.left = "250px";
	get("ghostText1").style.fontSize = "80px";
	get("ghostText1").style.fontWeight = "bold";
	
	ht.type("HELP ME", "ghostText1", null, null, true, 5000);
	setTimeout(theGhost3, 20000);
}

function theGhost3() {
	horror1();
	setTimeout(horror2, 100);
	setTimeout(horror1, 150);
	setTimeout(horror2, 200);
	setTimeout(horror1, 250);
	setTimeout(horror2, 3000);
}

function horror1() {
	$("#theHorror").show();
}
function horror2() {
	$("#theHorror").hide();
}



var g_bGhostText = true;
function ghostText() {
	if (g_bGhostText) {
		randomNumber = Math.floor(Math.random()*aGhostStrings.length);
		randomFontSize = Math.floor(Math.random()*aGhostFontSize.length);
	
		do {
			randomTop = Math.floor(Math.random()*getBrowserHeight());
		} while (randomTop >= (getBrowserHeight()-200));
		
		do {
			randomLeft = Math.floor(Math.random()*getBrowserWidth());
		} while (randomLeft >= (getBrowserWidth()-200));
		
		randomClearTimer = Math.floor(Math.random()*4000);
	
		do {
			randomCallbackTimer = Math.floor(Math.random()*30000);
		} while (randomCallbackTimer <= 10000);
		
		
	//	get("ghostText1").style.top = randomTop + "px";
	//	get("ghostText1").style.left = randomLeft + "px";
		get("ghostText1").style.top = "100px";
		get("ghostText1").style.left = "650px";
		get("ghostText1").style.fontSize = aGhostFontSize[randomFontSize] + "px";
		ht.type(aGhostStrings[randomNumber], "ghostText1", ghostText, randomCallbackTimer, true, randomClearTimer);
	}
}

function ghostTextExplode() {
	for (var i = 0; i < 5; i++) {
		randomNumber = Math.floor(Math.random()*aGhostStrings.length);
		randomFontSize = Math.floor(Math.random()*aGhostFontSize.length);
	
		do {
			randomTop = Math.floor(Math.random()*getBrowserHeight());
		} while (randomTop >= (getBrowserHeight()-200));
		
		do {
			randomLeft = Math.floor(Math.random()*getBrowserWidth());
		} while (randomLeft >= (getBrowserWidth()-200));
		
		randomClearTimer = Math.floor(Math.random()*4000);
	
		do {
			randomCallbackTimer = Math.floor(Math.random()*30000);
		} while (randomCallbackTimer <= 10000);
		
	
		var tempDiv = "<div id='ghostExplode" + i + "' style='color:#760000;font-size:" + randomFontSize + "px;z-index:50;position:absolute;top:" + randomTop + "px;left:600px;'></div>";
		get("ghostExplodeArea").innerHTML += tempDiv;	
		ht.type(aGhostStrings[randomNumber], "ghostExplode"+i, null, null, true, randomClearTimer);
	}
}












    var g_savedX1 = null
    var g_savedY1 = null;
    var g_loopTime = 0;

    var g_savedX2 = null
    var g_savedY2 = null;
    var g_loopTime2 = 0;

    var g_savedX3 = null
    var g_savedY3 = null;
    var g_loopTime3 = 0;

    var g_savedX4 = null
    var g_savedY4 = null;
    var g_loopTime4 = 0;

    var g_degree1 = 45;

    g_circle = null;
    function startCircle() {
      if (g_startCircleOK) {
  //      $.unblockUI();
  
        if (g_loopTime == 0) {
          var rand_no = Math.random()*10;
          if (rand_no < 5) {
            x = 1;
          } else {
            x = -1;
          }
          
          
          var rand_no = Math.random()*10;
          if (rand_no < 5) {
            y = +1;
          } else {
            y = -1;
          }
          
          g_savedX1 = x;
          g_savedY1 = y;
        }
  
        if (g_loopTime == 20) {
          g_loopTime = 0;
        } else {
          g_loopTime++;
        }
  
        systemOperation.moveBigCircle(g_savedX1, g_savedY1);
        
        if (g_loopTime2 == 0) {
          var rand_no = Math.random()*10;
          if (rand_no < 5) {
            x = 1;
          } else {
            x = -1;
          }
          
          var rand_no = Math.random()*10;
          if (rand_no < 5) {
            y = +1;
          } else {
            y = -1;
          }
          
          g_savedX2 = x;
          g_savedY2 = y;
        }
  
        if (g_loopTime2 == 15) {
          g_loopTime2 = 0;
        } else {
          g_loopTime2++;
        }
  
  
        g_degree1+=2;
        if (g_degree1 >= 360) {
          g_degree1 = 0;
        }
  
  
        systemOperation.moveSmallCircle(g_savedX2, g_savedY2, g_degree1);
      } 

      g_circle = setTimeout(startCircle, 100);
    }

  g_startCircleOK = false;  
  function startCircleOK() {
    g_startCircleOK = true;
  }
