if (is.ns4) {
	var domRef="document.layers.";
	var domClose = ""
	var styleRef="";
} else if ((is.ie) && (!is.dom) && (!is.ie55)) {	
	var domRef="document.all.";
	var domClose = ""
	var styleRef=".style"; 
	leftPos = 'left'; 
} else if ((is.dom)||(is.ie55)) {
	var domRef="document.getElementById(\""
	var domClose = "\")"
	var styleRef=".style"
	var leftPos = 'left';
}

var timerid, tableCount = 0, chromeWidth, maskFramWidth;
var frameScrollPos = new Array();

function init() {
	var maskClip = getRef('maskClip');
	if(maskClip) {
		is.ie ? chromeWidth = document.body.offsetWidth : chromeWidth = window.innerWidth;
		maskFramWidth = chromeWidth - 254;
		
		// left menu
		var top = 0;
		var right = 230;
		var bottom = 322;
		var left = 0;
		maskClip.style.clip = getClipFormat(top,right,bottom,left);
		
		menuH = getRef('menuHeight').offsetTop;
		getRef('menu').maxScrollPos = bottom - menuH;
		getRef('menu').minScrollPos = 0;
		getRef('menu').speed = 3;
		getRef('menu').timerSpeed = 10;
		getRef('menu').OxPos = getRef('menu').style.left;
		// main content
		getPhotoPositions();
	}

	// reveal the navigation...
	getRef('nav').style.visibility = "visible";
}

onresize = init;

function getPhotoPositions() {
	var content = getRef('fram');
	var tables = content.getElementsByTagName("TABLE");
	var pos = 0;
	var loop = tables.length;
	tableCount = Number(loop);
	var lastPos = 0;
	if (!frameScrollPos.push) { 
		frameScrollPos = new Array(loop);
		frameScrollPos[0] = 0;
	} else {
		frameScrollPos.push(pos);
	 }
	for (i=0;i<loop;i++) {
		pos += Number(tables[i].offsetWidth);
		if (lastPos == 0 && pos > maskFramWidth) {
			lastPos = pos-tables[i].offsetWidth;
		}
		if (!frameScrollPos.push) {
			frameScrollPos[i+1] = pos;
		} else {
		  frameScrollPos.push(pos);
		}
	}
	content.style.width = frameScrollPos[frameScrollPos.length-1] + "px";
	var frameMask = getRef('maskFram');
	var frameTop = 0;
	var frameRight = lastPos;
	var frameBottom = 350;
	var frameLeft = 0;
	// alert("frameTop: " + frameTop + ", frameRight: " + frameRight + ", frameBottom: " + frameBottom + ", frameLeft: " + frameLeft);
	frameMask.style.width = maskFramWidth + "px";
	frameMask.style.clip = getClipFormat(frameTop,frameRight,frameBottom,frameLeft);
	
	getRef('fram').maxScrollPos = frameRight - frameScrollPos[frameScrollPos.length-1];
	getRef('fram').minScrollPos = 0;
	getRef('fram').speed = 3;
	getRef('fram').timerSpeed = 10;
	getRef('fram').OyPos = getRef('fram').style.top;
	
}

//* create object reference 
function getRef(obj) {
	if (typeof(obj) == 'string') {	
		theObj = eval(domRef+obj+domClose);		
	} else {
		theObj = obj	
	}
	return theObj	
}

function getClipFormat(top,right,bottom,left) {
	if (is.dom) {
		var clipRect = 
			"rect("
			+ top + "px "
			+ right + "px "
			+ bottom + "px "
			+ left + "px"
			+ ")";
			return clipRect;
	} else {
		clipRect = "rect(" + top + " " + right + " " + bottom + " " + left + ")";
		return clipRect;
	}
	
}

function goToFramePos(num) {
	photos = getRef('fram');
	var OxPos = photos.style.left.split("px")[0];
	var newPos = -Number(frameScrollPos[num]);
	photos.style.left = newPos + "px";
	var deltaW = 0, pos = 0, oldPos = 0, lastPos = 0;
	for(i=Number(num);i<tableCount;i++) {
		deltaW = Number(frameScrollPos[i+1]-frameScrollPos[i]);
		oldPos = pos;
		pos += deltaW;
		if (pos > maskFramWidth && lastPos == 0) {
			lastPos = oldPos;
		}
	}
	if (lastPos == 0) lastPos = pos;
	var frameMask = getRef('maskFram');
	var frameTop = 0;
	var frameRight = lastPos;
	var frameBottom = 350;
	var frameLeft = 0;
	frameMask.style.width = maskFramWidth + "px";
	frameMask.style.clip = getClipFormat(frameTop,frameRight,frameBottom,frameLeft);	
}

function shiftHort(div, x, y) {
  if (is.dom) {  
    div.style.left = x + "px";
  } else if (is.ns4) {
	 div.moveTo(x,y);
  } else if ((is.ie) && (!is.dom)) { 
    div.style.pixelLeft = x;
  }
}

function shiftVert(div, x, y) {
  if (is.dom) {  
	div.style.top = y + "px";
  } else if (is.ns4) {
	 div.moveTo(x,y);
  } else if ((is.ie) && (!is.dom)) { 
		div.style.top = y;
  }
}


function scrollUp() {
	menuObj = getRef("menu");		
	OyPos = menuObj.style.top.split("px")[0];
	// alert("this is from scrollUp" + OyPos);
	if (OyPos < menuObj.minScrollPos) {
	// alert("increasing by 1: " + OyPos);
		OyPos = Number(OyPos) + Number(menuObj.speed);
      	if (OyPos >  menuObj.minScrollPos)  { 
			OyPos =  menuObj.minScrollPos; 
		}
		shiftVert(menuObj, menuObj.OxPos, OyPos);
		timerid = setTimeout("scrollUp()", menuObj.timerSpeed);
	} else {
		OyPos = menuObj.minScrollPos;
		shiftVert(menuObj, menuObj.OxPos, OyPos);
		clearTimeout(timerid);
	}
}

function scrollDown() {
	menuObj = getRef("menu");		
	OyPos = menuObj.style.top.split("px")[0];
 	if (OyPos > menuObj.maxScrollPos) {
      		OyPos = OyPos - menuObj.speed;
      		if (OyPos < menuObj.maxScrollPos) {OyPos = menuObj.maxScrollPos;}
      		shiftVert(menuObj, menuObj.OxPos, OyPos);
      		timerid = setTimeout("scrollDown()",menuObj.timerSpeed);
		} else {
		OyPos = menuObj.maxScrollPos;
   		shiftVert(menuObj, menuObj.OxPos, OyPos);
		clearTimeout(timerid);
	
	}
}

function stopScroll() {
	clearTimeout(timerid);
	return;
}

// for changing clip widths
function clipValues(obj,which) {
	if (is.ns4) {
		if (which=="t") return obj.clip.top
		if (which=="r") return obj.clip.right
		if (which=="b") return obj.clip.bottom
		if (which=="l") return obj.clip.left
	}
	else if ((is.ie) || (is.dom)) {
	// alert(obj.id);
	// alert(obj.style.clip);
		var clips = obj.style.clip		
		var regexp = /pt/
		var rpl = clips.replace(regexp,"px")
		// alert(rpl);
		rpl = rpl.replace(regexp,"px")
		// alert(rpl);
		var clipv = rpl.split("rect(")[1].split(")")[0].split("px")
		// alert(clipv)
		if (which=="t") return Number(clipv[0])		
		if (which=="r") return Number(clipv[1])	
		if (which=="b") return Number(clipv[2])
		if (which=="l") return Number(clipv[3])
	}
}

function clipBy(obj,t,r,b,l) {
	if (is.ns4) {
		obj.clip.top = clipValues(obj,'t') + t
		obj.clip.right = clipValues(obj,'r') + r
		obj.clip.bottom = clipValues(obj,'b') + b
		obj.clip.left = clipValues(obj,'l') + l
	}
	else if ((is.ie) || (is.dom)) {
	obj.style.clip = "rect("+(this.clipValues(obj,'t')+t)+"px "+(this.clipValues(obj,'r')+r)+"px "+Number(this.clipValues(obj,'b')+b)+"px "+Number(this.clipValues(obj,'l')+l)+"px)"
	
	}
}


	