// Common.js
// ---------
// Created: 12/28/98 by Jeremy Henrickson
// Copyright 1998, 1999 by Reactivity, Inc.  All rights reserved.
//
// This file contains common helper functions for writing cross-platform JavaScript.
var gBrowserIsNav, gBrowserIsIE, gBrowserIsMac
var gBrowserVersion						
var gBrowserCollText = ""				// collection tag (NN = "", IE = "all.")
var gBrowserStyleText = ""				// collection tag (NN = "", IE = ".style")
var	gBrowserStylePrefix = ""			// same as gBrowserStyleText, without any trailing period

// ------ Initialization routine -----
gBrowserVersion = parseInt(navigator.appVersion)
if(gBrowserVersion >= 3) {
	gBrowserIsNav = false;
	gBrowserIsIE = false;
	
	gBrowserIsMac = (navigator.appVersion.indexOf("Mac") >= 0);
	if(navigator.appName == "Netscape") {
		gBrowserIsNav = true
		gBrowserStyleText = "."
	} else if(navigator.appName == "Microsoft Internet Explorer") {
		gBrowserIsIE = true
		gBrowserCollText = "all."
		gBrowserStyleText = ".style."
		gBrowserStylePrefix = ".style"
	}
}

// getObj
// ------
// Returns an object in the document's root level collection.

function getObj(inName) {
	var theStr = "document." + gBrowserCollText + inName
	return eval(theStr)
}
// setObjProperty
// --------------
// Sets an arbitrary property of an object.

function setObjProperty(inObjName, inProperty, inValue) {
	var theValue
	if(typeof inValue == "string") {
		theValue = "'" + inValue + "'"
	} else {
		theValue = inValue
	}
	eval("document." + gBrowserCollText + inObjName + "." + inProperty + " = " + theValue)
}
// getStyle
// --------
// Returns the value of a style tag in the document's root level collection.

function getStyle(inObjName, inStyleTag) {
	return eval("document." + gBrowserCollText + inObjName + gBrowserStyleText + inStyleTag)
}
// setStyle
// --------
// Sets the value of a style element on an object in the document

function setStyle(inObjName, inStyleTag, inValue) {
	var theValue
	if(typeof inValue == "string") {
		theValue = "'" + inValue + "'"
	} else {
		theValue = inValue
	}
	eval("document." + gBrowserCollText + inObjName + gBrowserStyleText + inStyleTag + " = " + theValue)
}

// getStyleObject
// --------------
// Gets the style object of the object with the name passed in.

function getStyleObject(inObjName) {
	var theObj = getObj(inObjName)
	return eval("document." + gBrowserCollText + inObjName + gBrowserStylePrefix)
}

// ------------- POSITIONING --------------

// getObjectLeft, getObjectTop
// ---------------------------
// Returns the left and top of a given object.

function getObjectLeft(inObjName) {
	var theObj = getStyleObject(inObjName)
	if(gBrowserIsNav) {
		return theObj.left
	} else {
		return theObj.pixelLeft
	}
}

function getObjectTop(inObjName) {
	var theObj = getStyleObject(inObjName)
	if(gBrowserIsNav) {
		return theObj.top
	} else {
		return theObj.pixelTop
	}
}

// setObjectLeft, setObjectTop
// ---------------------------
// Returns the left and top of a given object.

function setObjectLocation(inObjName, inLeft, inTop) {
	var theObj = getStyleObject(inObjName)
	if(gBrowserIsNav) {
		theObj.left = inLeft
		theObj.top = inTop
	} else {
		theObj.pixelLeft = inLeft
		theObj.pixelTop = inTop
	}
}

function openNewWindow(inURL, inName, inTitle, inWidth, inHeight, inFeatures) {
	var features
	
	features = inFeatures

	if(features != '') features += ','
	
	features += 'title=' + inTitle + ','

	if(inWidth > 0 && inHeight > 0) {
		features += 'width=' + inWidth + ',height=' + inHeight
	}
	
	window.open(inURL, inName, features)
}

var kHabitats = 0
var kInhabitants = 1

function openLivingSpeciesList(inArea, inGroup, inInhabitant) {
	var url
	
	url = '/redirects/living_species.asp'
	url += '?hOri=' + inArea + '&'
	
	if(inArea == kHabitats) {
		url += 'hab='
	} else {
		url += 'group='
	}
	
	url += inGroup
	
	if(inInhabitant > 0) {
		url += '&inhab=' + inInhabitant
	}

	openNewWindow(url, 'living_species_list', 'Living Species List', 500, 520, 'resizable,scrollbars')
}

function openSplashZoneCD(inTrack) {
	var url
	
	url = '/redirects/splash_zone_music.asp?track=' + inTrack
	openNewWindow(url, 'splash_zone_cd', 'Splash Zone CD', 320, 540, '')
}

function openHabitatsPathMap(inName) {
	var url
	
	url = '/redirects/habitats_path_map.asp?name=' + inName
	openNewWindow(url, '', 'Habitats Path Map', 600, 510, 'resizable')
}

function openGlossary(inTerm) {
	var url
	
	url = '/redirects/glossary.asp?term=' + inTerm
	openNewWindow(url, '', 'Monterey Bay Aquarium: Glossary', 465, 500, 'resizable,scrollbars,menubar')
}

function openQTVR(inName) {
	var url
	
	url = '/redirects/qtvr.asp?name=' + inName
	openNewWindow(url, '', 'Monterey Bay Aquarium: QTVR Clip', 400, 300, 'resizable')
}

function openKelpForestInteractive() {
	var url
	
	url = '/redirects/kelp_forest_interactive.asp'
	openNewWindow(url, '', 'Monterey Bay Aquarium: Kelp Forest Interactive', 615, 600, 'resizable,scrollbars')
}

function openSeafoodWatch() {
	var url
	
	url = '/redirects/seafood_watch.asp'
	openNewWindow(url, '', 'Monterey Bay Aquarium: Seafood Watch', 655, 600, 'resizable,scrollbars,menubar')
}

function openOtterTimeline() {
	var url
	
	url = '/redirects/otter_timeline.asp'
	openNewWindow(url, '', 'Monterey Bay Aquarium: Otter Timeline', 600, 510, 'resizable')
}

function openHTMLWindow(inURL, inWidth, inHeight) {
	openNewWindow(inURL, '', 'Monterey Bay Aquarium', inWidth, inHeight, 'resizable,scrollbars,menubar');
}

function openwebbyHTMLWindow(inURL, inWidth, inHeight) {
	openNewWindow(inURL, '', 'Monterey Bay Aquarium', inWidth, inHeight, 'resizable,scrollbars,menubar,toolbar');
}
function openInteractiveWindow(inURL, inWidth, inHeight) {
	openNewWindow(inURL, '', 'Monterey Bay Aquarium', 615, 450, '');
}

function openFormWindow(inURL, inWidth, inHeight) {
	openNewWindow(inURL, '', 'Monterey Bay Aquarium', inWidth, inHeight, 'resizable, menubar');
}

// --------------------------
// Creature Map Rollover for Rocky Shore/Coral Reef in SZ
// Code created with the MouseOver Creator
// This program can be found at http://neilm.com/javascript
// Neil McCorrison, http://neilm.com

function changeIt(ImageToChange, ImageToShow) {
if (document.images) { document[ImageToChange].src = ImageToShow; }
}
function bar(message) {
if (document.images) { window.status = message; return true }
}

function openMoreInfoWindow(inURL, inWidth, inHeight) {
	openNewWindow(inURL, '', 'Field Trip Application: More Info', 300, 300, 'scrollbars,menubar');
}
function openCamWindow(inURL, inWidth, inHeight) {
	openNewWindow(inURL, '', 'Monterey Bay Aquarium', inWidth, inHeight, '');
}

//function showFeatures(inURL) {
//var refWind;
//refWind = window.opener;
//	if (!refWind || !refWind.closed) {
//		window.open(); }
//window.opener.location.href = inURL; }
//	else {	
//		window.location(inURL)
//			}
//}

//	window.open(inURL)}
//window.self(inURL) 
//var test
//test = window.opener.name
//document.write(test)

//		--old function--
function showFeatures(inURL) {
	window.opener.location.href = inURL;
}
