  
var moz = (document.getElementById && !document.all)?true:false;	// Mozilla 5.x / NS 6
var ie = (document.all)?true:false;									// IE 4+
var ns = (document.layers)?true:false;								// NS 4.x
var mac = navigator.appVersion.indexOf("Mac")>0?true:false;
//alert("mac="+mac + ",ie=" +ie);
//alert("browser > ie:" + ie + ", ns:" + ns + ", moz:" + moz + ", isMac:" + mac);


function createWindow(cUrl,cName,cFeatures) {
var xWin = window.open(cUrl,cName,cFeatures)
}

//img writer w/ popup
function writeImg(section,name,w,h,align,vspace) {
	if (mac && ie) {
		document.write("");
	} else {
		html = '<table border="0" cellpadding="0" cellspacing="0" align="' + align + '"><tr><td><a href="javascript:imgWin(\'images/' + section + '/' + name + '-l.jpg\',' + w + ',' + h + ');"><img src="/images/' + section + '/' + name + '-s.jpg" vspace="' + vspace + '" border="0"></a></td><td><img src="/images/pix.gif" height="1" width="3"></td></tr></table>';
		document.write(html);
	}
}

function writeImg2(img) {
	if (mac && ie) {
		document.write("");
	} else {
		html = '<table border="0" cellpadding="0" cellspacing="0" align="left"><tr><td><img src="' + img +'" vspace="5"></td><td><img src="/images/pix.gif" height="1" width="3"></td></tr></table>';
		document.write(html);
	}	
}


function imgWin(img,w,h) {
	
	l=screen.width/2-w/2;
	t=screen.height/2-h/2;

	var myWindow = window.open('','imgwindow','top='+t+',left='+l+',height='+h+',width='+w+',noresize,scrolling=no');
	
	myWindow.document.write('<html><head><title>Fig Leaf Ristorante</title></head>\n');
	myWindow.document.write('<body bgcolor="FFFFFF" marginwidth="0" marginheight="0" leftmargin="0" topmargin="0">\n');
	myWindow.document.write('<table cellpadding="0" cellspacing="0" border="0"><tr><td><img src="' + img + '" border="0"></td></tr></table>\n');
	myWindow.document.write('</body></html>');
	myWindow.focus();
}


// this adjusts a layer to be in the centre of the page.
function centerLayer(layerName) {
	var newLeft;
	var newTop;
	obj = getObject(layerName);
	if (getWindowCentre() > 375) {
		newLeft = Math.round(getWindowCentre() - (getLayerWidth(obj) / 2));	// new horiz.
		newTop = Math.round(getWindowCentreVertical() - (getLayerHeight(obj) / 2)); // new vertical centre
		if (ie) {
			obj.style.pixelLeft = newLeft;
			obj.style.pixelTop = newTop
		} else if (ns) {
			obj.left = newLeft;
			obj.top = newTop;
		} else if (moz) {
			obj.style.left = newLeft;
			obj.style.top = newTop;
		}
	}
	show(layerName,'');
}
// these are helper functions for above.
function getLayerWidth (layer) {
	if (ie) {
		return layer.clientWidth;
	} else if (ns) {
		return layer.clip.width;
	} else if (moz) {
		return layer.offsetWidth;
	}
}
function getLayerHeight (layer) {
	if (ie) {
		return layer.clientHeight;
	} else if (ns) {
		return layer.clip.height;
	} else if (moz) {
		return layer.offsetHeight;
	}
}
function getWindowCentre () {
	if (ie) {
		return Math.round(document.body.clientWidth / 2);
	} else if (ns || moz) {
		return Math.round(window.innerWidth / 2);
	}
}
function getWindowCentreVertical () {
	if (ie) {
		return Math.round(document.body.clientHeight / 2);
	} else if (ns || moz) {
		return Math.round(window.innerHeight / 2);
	}
}
// get object from layer id.
// one of the most useful functions ever.
function getObject(layerId) {
	if (ie) {
		obj = document.all(layerId);
	} else if (ns) {
		obj = document.layers[layerId];
	} else if (moz) {
		obj = document.getElementById(layerId);
	}
	return obj;
}

// this returns our layer, which netscape needs it's nesting layer to do so
// i hate netscape.
function nsNestedLayerGetObject(layerId,nestingLayer) {
	if (ns) {
		obj = document.layers[nestingLayer].document.layers[layerId];
		return obj;
	}
}


function show(obj,nestedLayer) {
	if (nestedLayer != '') {
		if (ns) {
			obj = nsNestedLayerGetObject(obj,nestedLayer);
		} else {
			obj = getObject(obj);
		}
	} else {
		obj = getObject(obj);
	}
	if (ie || moz) {
		obj.style.visibility = 'visible';
	} else if (ns) {
		obj.visibility = 'visible';
	}
}

function hide(obj,nestedLayer) {
	if (nestedLayer != '') {
		if (ns) {
			obj = nsNestedLayerGetObject(obj,nestedLayer);
		} else {
			obj = getObject(obj);
		}
	} else {
		obj = getObject(obj);
	}
	if (ie || moz) {
		obj.style.visibility = 'hidden';
	} else if (ns) {
		obj.visibility = 'hidden';
		
	}
}

function winStatus(msg) {
	if (typeof msg == 'string') {
		window.status = msg;
		return true;
	}
}

// some vars for the text scroller
var scrollTop, scrollHeight, shellTop, shellHeight, intervalID,state;
var scrollTimeOut = 40;
var currentVelocity = 0;

// get some friendly vars of various items for our scroller
function setScrollNames (outerLayer, innerLayer) {
	shellTop = 0;
	if (document.layers) {
		scrollTop = document.layers['main'].document.layers[outerLayer].document.layers[innerLayer].top;
		scrollHeight = document.layers['main'].document.layers[outerLayer].document[innerLayer].clip.bottom;
		shellHeight = document.layers['main'].document.layers[outerLayer].clip.bottom;
	} else if (document.all) {
		scrollTop = document.all[innerLayer].style.pixelTop;
		scrollHeight = document.all[innerLayer].offsetHeight;
		shellHeight = document.all[outerLayer].offsetHeight;
	} else if (document.getElementById) {
		scrollTop = parseInt(document.getElementById(innerLayer).style.top);
		scrollHeight = document.getElementById(innerLayer).offsetHeight;
		shellHeight = document.getElementById(outerLayer).offsetHeight;
	}
}

// clearing function.
function scrollClear () {
	clearTimeout(intervalID);
}

// quasi-intertia scroll function.
// would've liked to eval() layer movement, but ns6 doesn't like to do that.
// ie. eval("obj." + dompointer + " += currentVelocity");

function slide(direction,targetVelocity,cliplayer,textlayer) {
	if (ie || moz) {
		obj = getObject(textlayer);
	} else if (ns) {
		obj = document.layers['main'].document.layers[cliplayer].document.layers[textlayer]; //stupid netscrape...
	}
	setScrollNames(cliplayer,textlayer);
	switch (state) {
		case "acc": //we're accellerating...
			if (currentVelocity < targetVelocity) {
				currentVelocity += 1;
			}
			break;
		case "dec": //we're slowing down...
			currentVelocity -= 1;
			break;
	}
	if (currentVelocity <= 0) {
		clearTimeout(intervalID)
		currentVelocity = 0;
	} else {
		switch(direction) {
			case "up":
				if (scrollTop + parseInt(currentVelocity) < 0) {
					if (ie) {
						obj.style.pixelTop += parseInt(currentVelocity);
					} else if (moz) {
						obj.style.top = parseInt(obj.style.top) + parseInt(currentVelocity)
					} else if (ns) {
						obj.top += parseInt(currentVelocity)
					}
				} else {
					if (ie) {
						obj.style.pixelTop = 0;
					} else if (moz) {
						obj.style.top = 0;
					} else if (ns) {
						obj.top = 0;
					}
				}
				break;
			case "dn":
				if (scrollTop - parseInt(currentVelocity) > 0 - scrollHeight + shellHeight) {
					if (ie) {
						obj.style.pixelTop -= parseInt(currentVelocity);
					} else if (moz) {
						obj.style.top = parseInt(obj.style.top) - parseInt(currentVelocity)
					} else if (ns) {
						obj.top -= parseInt(currentVelocity)
					}
				} else {
					if (ie) {
						obj.style.pixelTop = 0 - scrollHeight + shellHeight;
					} else if (moz) {
						obj.style.top = 0 - scrollHeight + shellHeight;
					} else if (ns) {
						obj.top = 0 - scrollHeight + shellHeight;
					}
				}
				break;
		}
		intervalID = setTimeout("slide('" + direction + "'," + targetVelocity + ",'" + cliplayer + "','" + textlayer + "')",scrollTimeOut);
	}
}
