// Original:  Alan Chu 
// Web Site:  http://homepage.hkpeoples.net 
var agt=navigator.userAgent.toLowerCase();
//alert(agt);

// On IE5, these return 4, so use is_ie5up to detect IE5.
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

// Opera and WebTV spoof Navigator.  We do strict client
// detection. If you want to allow spoofing, take out the tests
// for opera and webtv.
var is_nav  = ((agt.indexOf('mozilla')!=-1)
            && (agt.indexOf('spoofer')==-1)
            && (agt.indexOf('compatible') == -1)
            && (agt.indexOf('opera')==-1)
            && (agt.indexOf('webtv')==-1));
var is_nav2 = (is_nav && (is_major == 2));
var is_nav3 = (is_nav && (is_major == 3));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav4up = (is_nav && (is_major >= 4));
var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)) );
var is_nav5 = (is_nav && (is_major == 5));
var is_nav5up = (is_nav && (is_major >= 5));

var is_ie   = (agt.indexOf("msie") != -1);
var is_ie3  = (is_ie && (is_major < 4));
var is_ie4  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")==-1) );
var is_ie4up = (is_ie  && (is_major >= 4));
var is_ie5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5up  = (is_ie  && !is_ie3 && !is_ie4);

var is_safari = (agt.indexOf("safari") != -1);
var is_opera = (agt.indexOf("opera") != -1);
var is_webtv = (agt.indexOf("webtv") != -1);

// KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
// or if this is the first browser window opened.  Thus the
// variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.
var is_aol   = (agt.indexOf("aol") != -1);
var is_aol3  = (is_aol && is_ie3);
var is_aol4  = (is_aol && is_ie4);

function fitWindowSize() {
	window.moveTo(0,0)
	window.focus();
	if (is_ie4up) {
		var width;
		var height;
		if (screen.height > (document.images[0].height + 90)) {
			height = (document.images[0].height) + 178;
		} else {
			height = (screen.height) - 100;	
		}
		if (screen.width > (document.images[0].width + 40)) {
			width = (document.images[0].width) + 32;
		} else {
			width = (screen.width) - 100;
		}
		window.resizeTo(width, height);
	} else if (is_safari) {
		var safari_w;
		var safari_h;
		if (self.screen.height > document.getElementById("pic").height + 55) {
			safari_h = document.getElementById("pic").height + 110;
		} else {
			safari_h = self.screen.height - 100;
		}
		if (self.screen.width > document.getElementById("pic").width + 35) {
			safari_w = document.getElementById("pic").width + 35;
		} else {
			safari_w = self.screen.width - 50;	
		}
		self.resizeTo(safari_w, safari_h);
	} else if (is_nav4up) {
		if (screen.height > document.getElementById("pic").height + 55) {
			window.innerHeight = document.getElementById("pic").height + 55;
		} else {
			window.innerHeight = screen.height - 100;
		}
		if (screen.width > document.getElementById("pic").width + 35) {
			window.innerWidth = document.getElementById("pic").width + 35;
		} else {
			window.innerWidth = screen.width - 50;
		}
	} else if (is_nav4) {
		if (screen.height > document.layers[0].document.images[0].height + 55) {
			window.innerHeight = document.layers[0].document.images[0].height + 55;
		} else {
			window.innerHeight = screen.height - 100;
		}
		if (screen.width > document.layers[0].document.images[0].width + 35) {
			window.innerWidth = document.layers[0].document.images[0].width + 35;
		} else {
			window.innerWidth = screen.width - 50;
		}
	}		
}
