// style sheet load
function loadCSS (typename, location_prefix) {
    var platform, browser;

    if (is_ie) {
	browser = 'ie';
    }
    else /* if (is_nav) */ {
	browser = 'nav';
    }

    if (is_mac) {
	platform = 'mac';
    }
    else /* if (is_win) */ {
	platform = 'win';
    }

    document.write('<link rel="stylesheet" type="text/css" href="' + location_prefix + 'css/' + typename + '_' + platform + '_' + browser + '.css">');
}

// pseudo-random pick of integer in range (0, max)
function randPick(max) {
    if (Math.random)
	return Math.round(Math.random() * (max-1));
    else {
	var now = new Date();
	return (now.getTime() / 1000) % max;
    }
}

function openBrWindow(theURL,winName,features) {
    window.open(theURL,winName,features);
}

// open centered window
function openCenteredWindow(url, window_name, width, height, features) {
	if (document.all)
        var xMax = screen.width, yMax = screen.height;
    else
        if (document.layers)
            var xMax = window.outerWidth, yMax = window.outerHeight;
        else
            var xMax = 640, yMax = 480;

    var xOffset = (xMax - width)/2;
	var yOffset = (yMax - height)/2 - 50;
	
	var feat = 'width=' + width + ',height=' + height + ',' + features + ', screenX=' + xOffset +
		',screenY=' + yOffset +
		',top=' + yOffset +
		',left='+ xOffset + '';
	
    window.open(url, window_name, feat);
}

// full screen
function fullScreen(theURL) {
	var options = 'scrollbars=yes';

	if (is_ie) {
		if (is_mac) {
			//options += ',height=' + window.screen.height + ',width=' + window.screen.width + ',left=0,top=0';
			openCenteredWindow(theURL, '', window.screen.width, window.screen.height,
				'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=auto,resizable=0,copyhistory=0');
			return;			
		}
		else {
			options += ',fullscreen=yes';
		}
	}
	else if (is_nav) {
		options += ',height=' + (window.screen.height - 55) + ',width=' + (window.screen.width - 10) + ',screenX=0,screenY=0';
	}
	window.open(theURL, '', options);
}

// image protection
function protect(e) {
	alert("Please see the Image Credits page for source information.");
	return(false);
}

// bind protect() to onmousedown for all images with the name "protect"	
function trap() {
	if (document.images) {
		for (i = 0; i < document.images.length; i++) {
			if (document.images[i].name == "protect") {
				document.images[i].onmousedown = protect;
			}
		}
	}
}

function preloadImages() {
    if (document.images) {
		var imgFiles = preloadImages.arguments;
		if (document.preloadArray == null) {
		    document.preloadArray = new Array();
		}

		var i = document.preloadArray.length;
		with (document) {
		    for (var j = 0; j < imgFiles.length; j++) {
				if (imgFiles[j].charAt(0) != "#") {
				    preloadArray[i] = new Image;
				    preloadArray[i++].src = imgFiles[j];
				}
	    	}
		}
    }
}

function swapImgRestore() {
    if (document.swapImgData != null) {
		for (var i = 0; i < (document.swapImgData.length-1); i += 2) {
		    document.swapImgData[i].src = document.swapImgData[i+1];
		}
    }
}

function swapImage() {
    var i, j = 0, objStr, obj;
    var swapArray = new Array;
    var oldArray=document.swapImgData;

    for (i = 0; i < (swapImage.arguments.length-2); i += 3) {
		objStr = swapImage.arguments[(navigator.appName == 'Netscape') ? i : i + 1];
		if ((objStr.indexOf('document.layers[') == 0 && document.layers == null) ||
	    	(objStr.indexOf('document.all[')    == 0 && document.all    == null)) {
	    	objStr = 'document' + objStr.substring(objStr.lastIndexOf('.'), objStr.length);
		}
		obj = eval(objStr);
		if (obj != null) {
		    swapArray[j++] = obj;
		    swapArray[j++] = (oldArray == null || oldArray[j-1] != obj) ? obj.src : oldArray[j];
		    obj.src = swapImage.arguments[i+2];
		}
    }
    document.swapImgData = swapArray; //used for restore
}

