var maxW = screen.width;
var maxH = screen.height;
var NS4 = (document.layers); // NS4 CSS sucks ass
var WIN = navigator.userAgent.indexOf("Win") >= 0 ;
var Mac = navigator.userAgent.indexOf("Mac") >= 0 ;
var Opera = navigator.userAgent.indexOf("Opera") >= 0 ;
var iCab = navigator.userAgent.indexOf("iCab") >= 0 ;
var Mozilla = navigator.userAgent.indexOf("Mozilla") >= 0 ;
var Problematic = (NS4 && Mac) || iCab || (Opera && !Mac) ;

if( WIN ) { maxH -= 80; } // attempt to compensate for start bar, chrome
if(NS4){ // Fix resize bug definitively
    origWidth=innerWidth; origHeight=innerHeight;
    onResize=function(){ if(innerWidth!=origWidth||innerHeight!=origHeight)location.reload(); }
}
var W; 
var fancyWindows; 

function setupCheckbox() {
	fancyWindows = getCookie('fancy_hedge_windows');
	if( fancyWindows == null ) fancyWindows = ! Problematic;
	toggleWindows( fancyWindows > 0 ? 1 : 0 );
}

function getCookie(name) {
	var re = new RegExp(name + "=([^;]+)");
	var value = re.exec(document.cookie);
	return (value != null) ? unescape(value[1]) : null;
}


function setCookie(name, value) { // use: setCookie("name", value);
	var today = new Date();
	var expiry = new Date(today.getTime()+28*86400000); // plus 28 days
	document.cookie=name + "=" + escape(value) + "; EXPIRES=" + expiry.toGMTString()
}


function toggleWindows(state) {
	if( state && NS4 && Mac) alert("The fancy windows can be really slow in Mac Netscape.\nPlease, be patient.\nThanks.");
	fancyWindows = state;
	setCookie('fancy_hedge_windows', fancyWindows ? 1 : 0);
	document.myForm.fancyWindows.checked = state;
	if( W && typeof(W.close) == "function") W.close();
}

function showMovie(where,what,wide,tall) {
	window.status = "Loading " + unescape(what) + "...";
	W = open( where, "aVeryStylishHedgePhoto",
		"toolbar=0,location=0,directories=0,status=0," + 
		"menubar=0,scrollbars=0,resizable=1," +
		"height=" + tall + ",width=" + wide );
	W.moveTo(0,0);
	if( typeof(W.resizeTo) != "undefined") { W.resizeTo(wide,tall); }
	window.status = "Done: " + unescape(what);
	return false;
}

function showPic(where,what,wide,tall) {
	if( !fancyWindows ) return true;
	if( WIN ) tall += 64;
	if( Mozilla ) tall -= 16;
	window.status = "Loading...";
	Wscale = ( wide > maxW ) ? (maxW/wide) : 1 ;
	Hscale = ( tall > maxH ) ? (maxH/tall) : 1 ; 
	scale = (Wscale < Hscale) ? Wscale : Hscale ;
	W = open( "show.html?"+where+'&'+what, "aVeryStylishHedgePhoto",
		"toolbar=0,location=0,directories=0,status=0," + 
		"menubar=0,scrollbars=0,resizable=1," +
		"height=" + tall*scale + ",width=" + wide*scale );
	W.moveTo(0,0);
	if( typeof(W.resizeTo) != "undefined") W.resizeTo(wide*scale,tall*scale);
	window.status = unescape(what);
	return false;
}


