var isfullscreen = false;
var previousXPosition = 0;
var previousYPosition = 0;
var previousWidth = 0;
var previousHeight = 0;
var isWin = (navigator.userAgent.indexOf('Win') != -1);
var isIE = (navigator.userAgent.indexOf('MSIE') != -1);
var isNS = (navigator.userAgent.indexOf('Mozilla') != -1);
var isMAC = (navigator.platform.indexOf('Mac') != -1);
var version = parseInt(navigator.appVersion);

function changebgColor(newcolor) {
	if(isWin && isIE) {
		document.bgColor="'#"+newcolor+"'";
	}
}

function fullscreen() {
	if(isfullscreen) {
		fullscreen_restore();
	} else {
		fullscreen_do();
	}
	isfullscreen = !isfullscreen;
}

function launch(url) {
	if(isfullscreen) {
		fullscreen_restore();
	}
	top.document.location.href=url;
}

function fullscreen_do() {
	if(isIE) {
		previousXPosition = top.window.screenLeft;
		previousYPosition = top.window.screenTop;
		previousWidth = top.window.document.body.clientWidth;
		previousHeight = top.window.document.body.clientHeight;
	} else if(self.outerWidth) {
		previousXPosition = self.screenX;
		previousYPosition = self.screenY;
		previousWidth = self.outerWidth;
		previousHeight = self.outerHeight;
	} else {
		previousXPosition = top.window.screenLeft;
		previousYPosition = top.window.screenTop;
		previousWidth = top.window.document.body.clientWidth;
		previousHeight = top.window.document.body.clientHeight;
	}
	if(isWin && isIE) {
		top.window.resizeTo(screen.width/2,screen.height/2);
		top.window.moveTo(0,0);
		var wleftdiff = top.window.screenLeft;
		var wrightdiff = (screen.width/2) - top.window.document.body.clientWidth - wleftdiff;
		var htopdiff = top.window.screenTop;
		var hbottomdiff = (screen.height/2) - top.window.document.body.clientHeight - htopdiff;
		var newXPosition = -wleftdiff;
		var newYPosition = -htopdiff;
		//var newWidth = screen.width+wleftdiff+wrightdiff;
		//var newHeight = screen.height+htopdiff+hbottomdiff;
		var newWidth = screen.width;
		var newHeight = screen.height;
		//alert("newWidth:"+newWidth+" && newHeight:"+newHeight+"   ");
		top.window.moveTo(0,0);
		top.window.resizeTo(newWidth,newHeight);
		previousXPosition -= wleftdiff;
		previousYPosition -= htopdiff;
		previousWidth += wleftdiff+wrightdiff;
		previousHeight += htopdiff+hbottomdiff;
	} else {
		deltaWidth = (isNS) ? ((isMAC) ? -10 : 0) : ((isMAC) ? -20 : -20);
		deltaHeight = (isNS) ? ((isMAC) ? -50 : 0) : ((isMAC) ? -5 : -70);
		deltaLeft = (isNS) ? ((isMAC) ? -6 : -6) : ((isMAC) ? -5 : -5);
		deltaTop = (isNS) ? ((isMAC) ? -30 : -30) : ((isMAC) ? -10 : -30);
		winWidth = screen.width + deltaWidth;
		winHeight = screen.height + deltaHeight;
		top.window.moveTo(0,0);
		top.window.resizeTo(winWidth,previousHeight);
		top.window.resizeTo(winWidth,winHeight);
	}	
}

function fullscreen_restore() {
	top.window.resizeTo(previousWidth,previousHeight);
	top.window.moveTo(previousXPosition,previousYPosition);
}

