function newWindow(url, name, width, height) {
  photoWindow = window.open(url, name,"location=no,directories=no,menubar=no,status=no,toolbar=no,scrollbars=no,height=" +height+ ",width=" +width+ ",resizable=yes");
  try {
    photoWindow.resizeTo(width,height);
    photoWindow.focus();
  } catch (e) {}
  return false;
}

function newScrollWindow(url, name, width, height) {
  photoWindow = window.open(url, name,"location=no,directories=no,menubar=no,status=no,toolbar=no,scrollbars=yes,height=" +height+ ",width=" +width+ ",resizable=yes");
  try {
    photoWindow.resizeTo(width,height);
    photoWindow.focus();
  } catch (e) {}
  return false;
}

/**
 * Initalizes navigation and setups hover events.
 */


var nav_hover_widget = null;
var nav_hover_arrow = null;

function init_nav() {

	nav_hover_widget = document.getElementById("nav_hover_widget");
	nav_hover_arrow = document.getElementById("nav_hover_arrow");

	if (document.getElementById("nav-main") == null) return;

	var main_nav = document.getElementById("nav-main");
	var li_list = main_nav.getElementsByTagName("ul")[0].childNodes;

	var foundSelected = false;

	for (var ii=0; ii<li_list.length; ii++) {
		if (li_list[ii].nodeName != 'LI') continue;

			foundSelected = (foundSelected || li_list[ii].className.lastIndexOf("selected") != -1);
			li_list[ii].style.zIndex = 30
			                           + ((foundSelected) ? -20 : 0) // Items after and including the selected element need a lower z-index
			                           + ((li_list[ii].className.lastIndexOf("selected") != -1) ? 15 : 0); // the selected item needs a special index, bettween those above and bellow


			// setup mouseover / mouseout methods for placing widget

			li_list[ii].childNodes[0].onmouseover = function() {
			nav_hover_widget.style.visibility = 'visible';
			var val = parseInt(this.parentNode.style.zIndex);
			this.parentNode.style.zIndex = val + parseInt(((val % 10) == 0) ? 5 : 0); // 'normal' zIndex is in 10's (10, 20 ,30 etc...), hovers states are in 5's. This is done to avoid possible event bubbling issues, or events being missed. It also means the values don't need to be stored.

			nav_hover_widget = nav_hover_widget.parentNode.removeChild(nav_hover_widget);
			this.parentNode.appendChild(nav_hover_widget);
		}

		li_list[ii].childNodes[0].onmouseout = function() {
		nav_hover_widget.style.visibility = 'hidden';
		var val = parseInt(this.parentNode.style.zIndex);
		this.parentNode.style.zIndex = val - parseInt(((val % 10) != 0) ? 5 : 0);
	}
}

}

function init_fancy_borders() {

	return;

	/* although this method works very will, and keeps code clean, it takes too long ot
	execute after the page is loaded, which causes the page to "freeze" for up to 5* or 6*
	seconds while the fancyness gets addded. A 'display: none;'; onloacd 'display: block';
	would fix this, howver it can be avoided all together by putting the code in the page.
	This shouldn't be an issue because a custom JSP Tag can be used.

	* 5 or 6 seconds on my (JM) machine, which isn't 'too' slow.

	*/

	var divs = document.getElementsByTagName("div");
	var img = null, div = null, div2 = null;

	for (var ii in divs) {

		if (divs[ii].className == null || divs[ii].className.lastIndexOf("fancy") == -1) continue;

		div = document.createElement("div");
		div.className = "tr";

		div2 = document.createElement("div");
		div2.className = "tl inner";
		div2.innerHTML = divs[ii].innerHTML;

		divs[ii].innerHTML = '';

		div.appendChild(div2);
		divs[ii].appendChild(div);

		div = document.createElement("div");
		div.className = "bl";
		img = document.createElement("img");
		img.setAttribute("src", "images/spacer.gif");
		img.setAttribute("width", "1");
		img.setAttribute("height", "1");
		img.setAttribute("alt", "");

		div.appendChild(img);
		divs[ii].appendChild(div);

		div = document.createElement("div");
		div.className = "br";
		div.appendChild(img.cloneNode(true));

		divs[ii].appendChild(div);
	}
	//<div class="fancy">
	//  <div class="tr">
	//    <div class="tl inner">
	//    <img src="images/DELETEME_house.jpg" width="120" height="90" alt="" />
	//    </div>
	//  </div>

	//  <div class="bl"><img src="images/spacer.gif" width="1" height="1" alt="" /></div>
	//  <div class="br"><img src="images/spacer.gif" width="1" height="1" alt="" /></div>
	//</div>
}



// preserve existing onload code
var wOnloadOld = window.onload;
window.onload = function() {
	if (wOnloadOld != null) {
		wOnloadOld();
	}
	init_nav();
	init_fancy_borders();
	//init_sIFR();
}
