// JavaScript Document
 function popUpFullScreen(URL){
    var width = screen.availWidth ? screen.availWidth : screen.width
    var height = screen.availHeight ? screen.availHeight : screen.height
    mywindow = window.open (
        URL,
        "",
        "top=0, \
        left=0, \
        width="+width+", \
        height="+height+", \
        location=no, \
        status=no, \
        scrollbars=no, \
        directories=no, \
        resizable=yes, \
        menubar=no, \
        toolbar=no, \
        fullscreen=yes"
    );
 } 
 
var userHeight = 768;
var userWidth = 1024;
var userX = 0;
var userY = 0;
var fullScreenMode = false;

function fullscreen() {
	
        //store the window size and location
	if (navigator.appName.indexOf("Microsoft")!=-1) {
		userWidth = document.body.offsetWidth;
		userHeight = document.body.offsetHeight + 145;
                userX = top.window.screenLeft;
                userY = top.window.screenTop - 120;

	} else {
		userWidth = top.window.outerWidth;
		userHeight = top.window.outerHeight;
                userX = top.window.screenX;
                userY = top.window.screenY;
	}
        
        // move the window to the far top left
	window.moveTo(0,0);
         
       
        
        //resize the window to full screen
	if(screen.availWidth) {
		if(document.all) {
			top.window.resizeTo(screen.availWidth,screen.availHeight);
		}
		else if (document.layers||document.getElementById) {
			if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth) {	
				top.window.outerHeight = screen.availHeight;
				top.window.outerWidth = screen.availWidth;
			}
		}
	} else if(screen.width) {
		window.resizeTo(screen.width,screen.height);
	}
	
	removeMenu();
        setTimeout('setFullScreenMode(true)', 500);
        
	
	//resizes IE browsers to full
	//max();
}

function setFullScreenMode(value) {
    fullScreenMode = value;
}

function max() {
	var obj = new ActiveXObject("Wscript.shell");
	obj.SendKeys("{F11}");
}

// returns the main menu
// and restores the screen to the origional size
function exitFullScreen() {
	restoreWindow();
	addMenu();
        fullScreenMode = false;
}

function resize(){
    if(fullScreenMode){
        fullScreenMode = false;
        document.body.onresize = "";
        addMenu();
    }
}

// removes the main menu and switches the fullscreen button
function removeMenu() {
	var mask = document.getElementsByName('menuMask');
	mask[0].style.display = "block";
	
	//switch button
	var fullScreenLink = document.getElementsByName('fullscreen');
        fade(0);
	fullScreenLink[0].innerHTML = "EXIT FULL SCREEN";
	fullScreenLink[0].href = "javascript:exitFullScreen();";
}

// returns to menu if the screen is not in full screen
// and restores the fullscreen button
function addMenu() {
	var mask = document.getElementsByName('menuMask');
	mask[0].style.display = "none";
	
	//switch button
	var fullScreenLink = document.getElementsByName('fullscreen');
        fade(0);
	fullScreenLink[0].innerHTML = "FULL SCREEN";
	fullScreenLink[0].href = "javascript:fullscreen();";
        
}

// restors the window to the origional size
function restoreWindow() {

        // resize
        top.window.resizeTo(userWidth,userHeight);
         
        //move
        window.moveTo(userX,userY);
}

//detect key events

function capturekey(e){
    var key=(typeof event!='undefined')?window.event.keyCode:e.keyCode;
    //alert('keycode : '+key);
    if((key == 27) && fullScreenMode){
        exitFullScreen();
    }
}
if(navigator.appName!= "Mozilla"){document.onkeyup=capturekey}
else{document.addEventListener("keypress",capturekey,true);}
if (document.layers) document.captureEvents(Event.KEYPRESS);



//fading
fades = new Array('#FFF', '#FFF', '#FFF', '#EEE', '#EEE', 
                  '#DDD', '#CCC', '#BBB', '#AAA', '#999', 
                  '#888', '#777')	
function fade(step){
	var fullScreenLink = document.getElementsByName('fullscreen');
        fullScreenLink[0].style.color = fades[step];
        fullScreenLink[0].onmouseover = function(){
            this.style.color = '#999';
            // kill current fade
            step = 11;
        }
        fullScreenLink[0].onmouseout = function(){
             this.style.color = '#777';
             step = 11;
        }
        if(step<11) setTimeout('fade('+(step+1)+')', 50);
}