//	Copyright © 2008 Orland Media Ltd


function detectEnvironment() {

	var platform;
	var browser;
	var version;
	
	version = parseInt	(navigator.appVersion);

	if	(navigator.userAgent.indexOf('Win') == -1) {
   	    platform = 'Macintosh';
	} else {
        platform = 'Windows';
	}

	if	(navigator.appName.indexOf('Netscape') == -1) {
        browser = 'IE';
	}	else	{
        browser = 'Netscape';
	}

}


function breakFrame(){
	if (self != top) top.location.replace(self.location);
}


function checkHomeFrame(domain_url){
	if (window.name!='main') top.location.replace("http://"+domain_url);
}


function framePage(thePage){
	if (window.name!='main') top.location.replace('index.html?'+thePage+'~main');
}


function openWindow(url, frame, id, width, height, location, centre) {
	
	if (!window[name] || window[name].closed){
	
		if (frame==null) frame = name;

		var props="width=" + width + ", height=" + height + ", scrollbars=0, toolbar=0, resizable=0";
		
		if (centre){
			var x = (screen.availWidth/2)-(width/2);
			var y = (screen.availHeight/2)-(height/2);
			props += ", top=" + y + ", left=" + x + ", screenX=" + x + ", screenbrowser=" + y;
		}
		
		window[name]=window.open(url,frame,props);
	
	} else {
	
		if(window[name].location.href.indexOf(url) == -1)
			window[name].location.replace(url);
  		window[name].focus();
		
	}
		
}



function openFullScreen(winId, url, resizable, chrome) {

	var platform;
	var browser;
	var width;
	var height;

	/**********************************
	SET DEFAULTS
	**********************************/

	//	note: must use 'typeof' to check undefined AND use string for "undefined" for mac ie	
	if(typeof(winId) == "undefined") winId = "siteWin";
	if(typeof(url) == "undefined") url = "about:blank";
	if(typeof(resizable) == "undefined") resizable = 1;
	if(typeof(chrome) == "undefined") chrome = true;
	if(!chrome) if (resizable) resizable = 0;
	
	
	/**********************************
	GET BROWSER
	**********************************/
	//	note: Apple's Safari identifies itself as 'Netscape'	
	navigator.userAgent.indexOf('Win') != -1 ? platform='windows' : platform = 'mac';
	navigator.appName.indexOf('Netscape') == -1 ? browser = 'ie' : browser = 'netscape';


	/**********************************
	SET WINDOW SIZE
	**********************************/
	width = window.screen.width;
	height = window.screen.height;

	//	tweak window for specific environment
	if (platform == "mac"){
		
		if(browser == "netscape"){
			height+=54;
		}
		
	} else {
		
		if(browser == "netscape"){
			height-=30;
		} else {
			height-=28;
			width+=1;
		}
		
	}		
	
	/**********************************
	SET PROPERTIES
	**********************************/
	
	//	always open the window with no chrome
	var props = "width=" + width + ", height=" + height + ", location=no, toolbar=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=" + resizable;
	
	//	tell supporting browsers to remove *everything*:
	if(chrome == false) props += " ,fullscreen=true";
	
	
	/**********************************
	OPEN WINDOW
	**********************************/
	window[winId] = window.open(url, winId, props);
	window[winId].focus();
	
	
	/**********************************
	CATER FOR MAC IE
	**********************************/
	window[winId].moveTo(0,0);
	window[winId].resizeTo(width, height);
	
	
}



function maximiseWindow() {
	self.parent.moveTo(0,0);
	self.parent.resizeTo(screen.availWidth, screen.availHeight);
}



function resize() {

	var currentWidth = browser == 'ie' ? document.body.clientWidth : self.parent.innerWidth;
	var currentHeight = browser == 'ie' ? document.body.clientHeight : self.parent.innerHeight;
	
	var resizing = false;
	
	if (currentWidth < (targetWidth-5)) {
		resizing = true;
		self.parent.resizeTo(currentWidth + speed);
	}
	
	if (currentHeight < (targetHeight-5)) {
		resizing = true;
		self.parent.resizeTo(currentHeight + speed);
	}			
	
	if (!resizing) {
		self.parent.resizeTo(targetWidth,targetHeight);
		clearInterval(self.parent.sizer);
	}
		
}
	
	
function maximiseWindow2() {
	
	self.parent.moveTo(0,0);
	alert("Beta 1 mode");
	
	browser = navigator.appName.indexOf('Microsoft') != -1 ? 'ie' : 'netscape';
	platform = navigator.platform.indexOf('Win') != -1 ? 'windows' : 'mac';	
	speed = 5;
	targetWidth = screen.availWidth;
	targetHeight = screen.availHeight;

	self.parent.sizer = setInterval("resize()",500);				

}