// This object has been adapted for use on Laika.org by the folks at Planetmouse Inc. (http://planetmouse.com)
function pnhGetLayerX() {
	if (document.layers) { return this.layer.left; }
	else if (document.all) { return parseInt(this.layer.style.left); }
	else if (document.getElementById) {	return parseInt(document.defaultView.getComputedStyle(this.layer, null).getPropertyValue('left')); }
	else { return null; }
}
function pnhGetLayerY() {
	if (document.layers) { return this.layer.top; }
	else if (document.all) { return parseInt(this.layer.style.top);}
	else if (document.getElementById) { return parseInt(document.defaultView.getComputedStyle(this.layer, null).getPropertyValue('top')); }
	else { return null;	}
}
function pnhSetLayerX(iPixels) {
	if (document.layers) { this.layer.left = iPixels; }
	else if (document.all) { this.layer.style.left = iPixels; }
	else if (document.getElementById) { this.layer.style.left = iPixels + "px"; }
	else { /* ???? */ }
}
function pnhSetLayerY(iPixels) {
	if (document.layers) { this.layer.top = iPixels; }
	else if (document.all) { this.layer.style.top = iPixels; }
	else if (document.getElementById) { this.layer.style.top = iPixels + "px"; }
	else { /* ???? */ }
}
function pnhSetLayerZ(iIndex) {
	if (document.layers) { this.layer.zIndex = iIndex; }
	else if (document.all) { this.layer.style.zIndex = iIndex; }
	else if (document.getElementById) { this.layer.style.zIndex = iIndex; }
	else { /* ???? */ }
}
function pnhLayerMoveBy(iLeft,iTop) {
	if (document.layers) { this.layer.top = this.getY() + iTop; this.layer.left = this.getX() + iLeft; }
	else if (document.all) { this.layer.style.pixelTop = this.getY() + iTop; this.layer.style.pixelLeft = this.getX() + iLeft; }
	else if (document.getElementById) { this.layer.style.top =  this.getY() + iTop; this.layer.style.left = this.getX() + iLeft; }
	else { /* ???? */ }
}
function pnhRewriteLayerHTML(sHTML, iWidth) {
	// width is a must have for Navigator 4.x - otherwise text won't wrap at same width as it had previous to the rewrite
	if (document.layers) {
		sHTML = "<table cellpadding='0' cellspacing='0' border='0' width='" + iWidth + "'><tr><td width='" + iWidth + "'>" + sHTML + "</td></td></table>";
	 	this.layer.document.open();
		this.layer.document.write(sHTML);
		this.layer.document.close();
	}
	else if ((document.getElementById) || (document.all)) { this.layer.innerHTML = sHTML; }
	else { /* ???? */ }
}
function pnhSetLayerVis(sVisibility) {
	if (document.layers) { this.layer.visibility = sVisibility; }
	else if ((document.all) || (document.getElementById)) { this.layer.style.visibility = sVisibility; }
	else { /* ???? */ }
}

function pnhLayerObject(sLayerName,aNesting) {
	// STEP 1: get ahold of the DOM object
	if (document.getElementById) {
		this.layer = document.getElementById(sLayerName); // should this be "sLayerId"?
	} else if (document.all) {
		this.layer = document.all[sLayerName];
	} else if (document.layers) {
		var layernesting = "";
		// aNesting is an array of parent layers starting outermost to closest
		if (aNesting) {
			for (i=0;i<aNesting.length;i++) {
				// alert(aNesting.length);
				layernesting = layernesting + "document.layers['" + aNesting[i] + "'].";
			}
		}
		// alert(layernesting + "document.layers['" + sLayerName + "']");
		this.layer = eval(layernesting + "document.layers['" + sLayerName + "']");
	} else { }
	
	// STEP 2: hook in the functions
	this.getX = pnhGetLayerX;
	this.getY = pnhGetLayerY;

	this.setX = pnhSetLayerX;
	this.setY = pnhSetLayerY;
	this.moveBy = pnhLayerMoveBy;	

	this.setZ = pnhSetLayerZ;
	this.setHTML = pnhRewriteLayerHTML;
	this.setVisibility = pnhSetLayerVis;
	
}

// this code created for placenamehere.com then adapted for use on laika.org by Planetmouse Inc. (http://planetmouse.com)
function pnhSetWindowStatus(sStatus) { window.status = sStatus; }
function pnhClearWindowStatus() { window.status = ''; }
function pnhGetInnerWidth() {
	if (window.innerWidth) { return window.innerWidth; } // netscape behavior
	else if (document.body.offsetWidth) { return  document.body.offsetWidth; } // IE behavior
	else { return null; }
}
function pnhGetInnerHeight() {
	if (window.innerHeight) { return window.innerHeight; } // netscape behavior
	else if (document.body.offsetHeight) { return  document.body.offsetHeight; } // IE behavior
	else { return null; }
}
function pnhPercentToPixels(iPercent, sDirection) { // the percentage is an integer percentage
	if (sDirection == "width") { return parseInt(this.getInnerWidth()*iPercent/100); }
	else if (sDirection == "height") { return parseInt(this.getInnerHeight()*iPercent/100); }
	else { return null; }
}

function pnhWindowObject() {
	this.setStatus = pnhSetWindowStatus;
	this.clearStatus = pnhClearWindowStatus;
	this.getInnerWidth = pnhGetInnerWidth;
	this.getInnerHeight = pnhGetInnerHeight;
	this.percentToPixels = pnhPercentToPixels;
}
// end of standard objects

// laika section objects
function laLabelOn() {
	this.label.setX(widgets[this.widgetID].getX()+this.labelOffsetX);
	this.label.setY(widgets[this.widgetID].getY()+this.labelOffsetY);
	this.label.setVisibility("visible");
}
function laLabelOff() {
		this.label.setVisibility("hidden");
}

function laikaSection(sTitle, iWidgetID, sLabel, iLabelOffset, iContentOffsetX, iContentOffsetY, aLayers, aStartingLayers, aSpotXs, aSpotYs) {
	this.widgetID = iWidgetID;
	this.widgetX = aSpotXs;
	this.widgetY = aSpotYs;
// ie4 hack	
	if (sLabel != null) {
		this.label = new pnhLayerObject(sLabel,null);
		this.labelSwitch = true;
	}
	else {
		//alert (sTitle);
		this.labelSwitch = false;
	}
	this.labelOffsetX = iLabelOffset;
	this.labelOffsetY = 0;
	this.contentOffsetX = iContentOffsetX;
	this.contentOffsetY = iContentOffsetY;
	
	this.allLayers = new Array();
	if (aLayers) {
		for (x=0;x<aLayers.length;x++) {
		// create object nesting 
		// HACK
			if ((aLayers[x] == "aboutusCopy") || (aLayers[x] == "contactCopy") || (aLayers[x] == "albumDetailCopy")) { 
				this.allLayers[x] = new pnhLayerObject(aLayers[x],new Array(aLayers[x-1]));
				this.allLayers[x].scrollClip = true;
			}
			else if (aLayers[x] == "aboutusBio") {
				this.allLayers[x] = new pnhLayerObject(aLayers[x],new Array(aLayers[x-2]));
				this.allLayers[x].scrollClip = true;
			}
			else if (aLayers[x] == "aboutusFaq") {
				this.allLayers[x] = new pnhLayerObject(aLayers[x],new Array(aLayers[x-4]));
				this.allLayers[x].scrollClip = true;
			}
			else {
				this.allLayers[x] = new pnhLayerObject(aLayers[x],null);
				this.allLayers[x].scrollClip = false;
			}
		}
	}

	this.startingLayers = new Array();
	this.startingLayers = aStartingLayers;
	this.showLabel = laLabelOn;
	this.hideLabel = laLabelOff;
}

// photo content objects
function photoButtonOn(){
	this.buttonLabel.src = "images/photo_on.gif";
}

function photoButtonOff(){
	if (currentPhoto != this.number) {
		this.buttonLabel.src = "images/photo_off.gif";
	}
}

function switchPhoto() {
	prevPhoto = currentPhoto;
	currentPhoto = this.number;
	photographs[prevPhoto].buttonOff();
	var newHtml = "<div class='photoContent'>" + photoImg[this.number] + "</div>"
	sections["photos"].allLayers[2].setHTML(newHtml,285);
}

function photoContent(pNumber) {
	this.number = pNumber;
	this.buttonName = "button" + pNumber;
	if (document.layers) {	
		this.buttonLabel = document.layers["photoNav"].document.images[this.buttonName];
	}
	else if ((document.all)||(document.getElementById)) {
		this.buttonLabel = document.images[this.buttonName];
	}
	else {
	}
	this.buttonOn = photoButtonOn;
	this.buttonOff = photoButtonOff;
	this.photoOn = switchPhoto;
}
// stamp content objects
function stampButtonOn(){
	this.buttonLabel.src = "images/stamp_on.gif";
}

function stampButtonOff(){
	if (currentStamp != this.number) {
		this.buttonLabel.src = "images/photo_off.gif";
	}
}

function switchStamp() {
	prevStamp = currentStamp;
	currentStamp = this.number;
	laikaStamps[prevStamp].buttonOff();
	var newHtml = "<div class='stampsContent'>" + stampImg[this.number] + "</div>"
	sections["stamps"].allLayers[2].setHTML(newHtml,250);
}

function stampContent(pNumber) {
	this.number = pNumber;
	this.buttonName = "sbutton" + pNumber;
	if (document.layers) {	
		this.buttonLabel = document.layers["stampNav"].document.images[this.buttonName];
	}
	else if ((document.all)||(document.getElementById)) {
		this.buttonLabel = document.images[this.buttonName];
	}
	else {
	}
	this.buttonOn = stampButtonOn;
	this.buttonOff = stampButtonOff;
	this.photoOn = switchStamp;
}

// Widget navigation
function setHomePositions() {
	bgLogo.setX(calcDynamicWidth(bgLogoX));  //	set logo position and visibility
	bgLogo.setVisibility("visible");
	
	for (i=0;i<widgets.length;i++) {
		widgets[i].setX(calcDynamicWidth(sections["home"].widgetX[i]));
		widgets[i].setY(sections["home"].widgetY[i]);
		widgets[i].setVisibility("visible");
	}
}

function calcDynamicWidth(iWidth) {
	var winW = thisWindow.getInnerWidth() - 20;
	if (winW<600) { winW = 600 }
	return winW*iWidth/baseWindowWidth;
}

function runTransition(sSection,counter) {
	notAnimating = false;
	nextSection = sSection;
	if (counter == numSteps) {
		// Step 1: Hide ALL of current section
		for (i=0;i<sections[currentSection].allLayers.length;i++) {
			sections[currentSection].allLayers[i].setVisibility("hidden");
		}

		if (document.all) { document.links[0].focus(); }  // redirect focus to fix ie5-mac trails
		
		setTimeout("runTransition(nextSection," + (counter-1) + ")",delay);

	} else if (counter > 0) {
		// Step 2: Transition the nav items
		for (i=0;i<widgets.length;i++) {
			widgets[i].moveBy((calcDynamicWidth(sections[nextSection].widgetX[i])-widgets[i].getX())/motionDivider,(sections[nextSection].widgetY[i]-widgets[i].getY())/motionDivider);
		}
		if (sections[nextSection].label && (nextSection.substring(0,4) != "dead")) {  // move the label
			sections[nextSection].showLabel();
		}
		bgLogo.setX(calcDynamicWidth(bgLogoX));  // also move the logo
		setTimeout("runTransition(nextSection," + (counter-1) + ")",delay);

	} else {
		// Step 3: Reposition content & show all of next section
		for (j=0;j<(sections[sSection].allLayers.length);j++) {
			if (sections[sSection].allLayers[j].scrollClip == false){
				sections[sSection].allLayers[j].setX(widgets[sections[sSection].widgetID].getX() + sections[sSection].contentOffsetX[j]);
				sections[sSection].allLayers[j].setY(widgets[sections[sSection].widgetID].getY() + sections[sSection].contentOffsetY[j]);
			}
		}
		for (i=0;i<sections[sSection].startingLayers.length;i++) {
			sections[sSection].allLayers[sections[sSection].startingLayers[i]].setVisibility("visible");
		}

		// Step 4: set next section as new section
		currentSection = nextSection;
		notAnimating = true;
	}
}

// scroller scripts - thanks to assembler
// ASM SCROLLER 2.0 - (c) 2000 Brent Gustafson, vitaflo.com and assembler.org
var w3c = (document.getElementById) ? 1:0;
var ns4 = (document.layers) ? 1:0;
var ie4 = (document.all) ? 1:0;

var range = "";
var cap = "";
var mutex = 0;
var yplace = 0;
var ymax = 0;
var xplace = 0;
var newsHeight = 0;

var speed = 3; //speed at which the news scrolls

var copyId = new Array();
var copyClipId = new Array();
var yMin = new Array();
var yPlace = new Array();

// define scrolling layers || clipping and clipped
	copyId[0] = "aboutusCopy";
	copyClipId[0] = "aboutusScrollClip";
	copyId[1] = "contactCopy";
	copyClipId[1] = "contactScrollClip";
	copyId[2] = "albumDetailCopy";
	copyClipId[2] = "albumDetailScrollClip";
	copyId[3] = "aboutusBio";
	copyClipId[3] = "aboutusScrollClip";
	copyId[4] = "aboutusFaq";
	copyClipId[4] = "aboutusScrollClip";
	yPlace[0] = 0;
	yPlace[1] = 0;
	yPlace[2] = 0;
	yPlace[3] = 0;
	yPlace[4] = 0;

function redrawScreen() {
  location.reload();
  return false
}

function shiftTo(obj, x, y) {
  if (w3c) {
    obj.style.top = y + "px";
  }
  else if (ns4) {
	 obj.moveTo(x,y);
  } 
  else if (ie4) {
	obj.style.pixelTop = y;
  }
}

function getObject(obj) {
	var theObj = eval("document." + range + obj + cap);
	return theObj;
} 

function scrollUp(scrollNum) {
  if (mutex == 1){
    var theObj = getObject(copyId[scrollNum]);
    if (yPlace[scrollNum] < ymax) {
      yPlace[scrollNum] = yPlace[scrollNum] + speed;
      if (yPlace[scrollNum] > ymax) yPlace[scrollNum] = ymax;
      shiftTo(theObj, xplace, yPlace[scrollNum]);
      setTimeout("scrollUp(" + scrollNum + ")",25);
    }
  }
}
  
function scrollDown(scrollNum) {
  if (mutex == 2){
    var theObj = getObject(copyId[scrollNum]);
    if (yPlace[scrollNum] > yMin[scrollNum]) {
      yPlace[scrollNum] = yPlace[scrollNum] - speed;
      if (yPlace[scrollNum] < yMin[scrollNum]) yPlace[scrollNum] = yMin[scrollNum];
      shiftTo(theObj, xplace, yPlace[scrollNum]);
      setTimeout("scrollDown(" + scrollNum + ")",25);
    }
  }
}

function scrollReset(scrollNum) {
	var theObj = getObject(copyId[scrollNum]);
	yPlace[scrollNum] = 0;
	shiftTo(theObj, xplace, yPlace[scrollNum]);
}

function scrollIt(msg, dir, scrollNum) {
  window.status = msg; 
  mutex = dir;
  if (mutex == 1) scrollUp(scrollNum);
  else if (mutex == 2) scrollDown(scrollNum);
  else if (mutex == 3) scrollReset(scrollNum);  // resets layer to the top
}


function initScroll() {
  if (w3c) {
	range = "getElementById(\"";
    cap = "\")";
	for (i=0;i<copyId.length;i++) {
    	theObj = getObject(copyClipId[i]);
		newsHeight = parseInt(theObj.offsetHeight);
    	theObj = getObject(copyId[i]);
		yMin[i] = (parseInt(theObj.offsetHeight) - newsHeight) * -1;
	}
  }
  else if (ns4) {
    window.captureEvents(Event.RESIZE);
    window.onresize = redrawScreen;
	for (i=0;i<copyId.length;i++) {
		theObj = getObject(copyClipId[i]);
	    newsHeight = theObj.clip.height;
	    copyId[i] = copyClipId[i] + ".document." + copyId[i];
	    theObj = getObject(copyId[i]);
	    yMin[i] = (theObj.clip.height - newsHeight) * -1;
	}
  }
  else if (ie4) {
	for (i=0;i<copyId.length;i++) {
	   	range = "all.";
	    theObj = getObject(copyClipId[i]);
	    newsHeight = theObj.offsetHeight;
	    theObj = getObject(copyId[i]);
	    yMin[i] = (theObj.offsetHeight - newsHeight) * -1;
	}

  }
}

// netscape resize fix - thanks to webmonkey
function WM_netscapeCssFix() {
  /*
    Source: Webmonkey Code Library
    (http://www.hotwired.com/webmonkey/javascript/code_library/)

    Author: Taylor
    Author Email: taylor@wired.com
    Author URL: http://www.taylor.org/
    */

  if (document.WM.WM_netscapeCssFix.initWindowWidth != window.innerWidth || document.WM.WM_netscapeCssFix.initWindowHeight != window.innerHeight) {
    document.location = document.location;
  }
}

function WM_netscapeCssFixCheckIn() {
  if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) == 4)) {
    if (typeof document.WM == 'undefined'){
      document.WM = new Object;
    }
    if (typeof document.WM.WM_scaleFont == 'undefined') {
      document.WM.WM_netscapeCssFix = new Object;
      document.WM.WM_netscapeCssFix.initWindowWidth = window.innerWidth;
      document.WM.WM_netscapeCssFix.initWindowHeight = window.innerHeight;
    }
    window.onresize = WM_netscapeCssFix;
  }
}

WM_netscapeCssFixCheckIn()
