function wMenu(menuImgId, overOrOut, ev) {
	var subMenu = document.getElementById("divSubMenu");
	var menuImg = document.getElementById(menuImgId);
	if (!ev) ev = window.event;
	if (ev.pageX || ev.pageY) {
		mouseX = ev.pageX;
		mouseY = ev.pageY;
	} else if (ev.clientX || ev.clientY) {
		mouseX = ev.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
		mouseY = ev.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
	}
	subMenuL = Number(subMenu.style.left.substring(0, subMenu.style.left.length-2));
	subMenuW = 91;
	subMenuT = Number(subMenu.style.top.substring(0, subMenu.style.top.length-2));
	subMenuH = 243;
	if (menuImgId != 'menu2') {
		if (overOrOut) {
			menuImg.src='/src/imgs/w'+menuImgId+'a.gif';
		} else {
			menuImg.src='/src/imgs/w'+menuImgId+'.gif';
		}
		if (subMenu.style.display != 'none') {
			if (((mouseX>subMenuL) && (mouseX<subMenuL+subMenuW)) && ((mouseY>subMenuT-5) && (mouseY<subMenuT+subMenuH))){
			} else if (mc != 'catalog') {
				document.getElementById('menu2').src='/src/imgs/wmenu2.gif';
				subMenu.style.display = 'none';
			}
		}
	} else {
		if (overOrOut) {
			var l = 0;
			var t = 0;
			elem = menuImg;
			while (elem) {
				l += elem.offsetLeft;
				t += elem.offsetTop;
				elem = elem.offsetParent;
			}
			menuImg.src='/src/imgs/w'+menuImgId+'a.gif';
			subMenu.style.left = l + 124;
			subMenu.style.top = t + 45;
			subMenu.style.display = 'block';
		} else {
			if (subMenu.style.display != 'none') {
				o = subMenuT+subMenuH;
				if (((mouseX>subMenuL) && (mouseX<subMenuL+subMenuW)) && ((mouseY>subMenuT-5) && (mouseY<subMenuT+subMenuH))){
				} else {
					menuImg.src='/src/imgs/w'+menuImgId+'.gif';
					subMenu.style.display = 'none';
				}
			}
		}
	}
	return true;
}

function getDocumentHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}
function getDocumentWidth() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollWidth, D.documentElement.scrollWidth),
        Math.max(D.body.offsetWidth, D.documentElement.offsetWidth),
        Math.max(D.body.clientWidth, D.documentElement.clientWidth)
    );
}

function getClientHeight() {
    return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}

function getClientWidth() {
    return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function getBodyScrollTop() {
    return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}

function getBodyScrollLeft() {
    return self.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || (document.body && document.body.scrollLeft);
}

function getClientCenterX() {
    return parseInt((getBodyScrollLeft()+getClientWidth())/2);
}

function getClientCenterY() {
    return parseInt((getBodyScrollTop()+getClientHeight())/2);
}

function test() {
	text='getBodyScrollTop()='+getBodyScrollTop()+' getBodyScrollLeft()='+getBodyScrollLeft()+"\n";
	text = text + 'getClientHeight()='+getClientHeight()+' getClientWidth()='+getClientWidth()+"\n";
	text = text + 'getDocumentHeight()='+getDocumentHeight()+' getDocumentWidth()='+getDocumentWidth()+"\n";
	text = text + 'getClientCenterY()='+getClientCenterY()+' getClientCenterX()='+getClientCenterX()+"\n";
	alert(text);
}

function showPhoto(photoId, w, h) {
	var hideFrame = document.getElementById("hideFrame");
	var showPhotoDiv = document.getElementById("showPhotoDiv");
	var photoText = document.getElementById("photoText"+photoId).innerHTML;
		
	hideFrame.style.height = getDocumentHeight();
	hideFrame.style.width = getDocumentWidth();
	hideFrame.style.display = 'block';

	var theText = '<table border="0" align="center" cellpadding="0" cellspacing="0"><tr><td><img src="/src/imgs/border-top-left1.gif"></td><td class="catalogTd">&nbsp;</td><td><img src="/src/imgs/border-top-right1.gif"></td></tr>';
	theText = theText+'<tr><td class="catalogTd">&nbsp;</td><td class="catalogTd"><a class="cat" href="javascript:hidePhoto(); void(0);"><img border=0 src=\'/src/photo/'+photoId+'.jpg\' width='+w+' height='+h+'><br>'+photoText+'</a></td><td class="catalogTd">&nbsp;</td></tr>';
	theText = theText+'<tr><td class="catalogTd">&nbsp;</td><td class="catalogTd">';
		theText = theText+'<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0"><tr>';
		theText = theText+'<td align="left"><a href="javascript: next_prev_photo('+photoId+', false); void(0);"><img src="/src/imgs/arrowleft.gif" width="30" height="17" border="0"></a></td>';
		theText = theText+'<td align="right"><a href="javascript: next_prev_photo('+photoId+', true); void(0);"><img src="/src/imgs/arrowright.gif" width="30" height="17" border="0"></a></td>';
		theText = theText+'</tr></table>';
	theText = theText+'</td><td class="catalogTd">&nbsp;</td></tr>';
	theText = theText+'<tr><td><img src="/src/imgs/border-bottom-left1.gif"></td><td class="catalogTd">&nbsp;</td><td><img src="/src/imgs/border-bottom-right1.gif"></td></tr></table>';
	showPhotoDiv.innerHTML = theText;
	w = w+30; h = h+60;
	showPhotoDiv.style.width = w;
	showPhotoDiv.style.height = h;
	if ((getBodyScrollTop()==0) && (h>getClientHeight())) {
		showPhotoDiv.style.top = 10;
	} else if ((getBodyScrollTop()==(getDocumentHeight()-getClientHeight())) && (h>getClientHeight())) {
		showPhotoDiv.style.top = getDocumentHeight()-h-10;
	} else {
		showPhotoDiv.style.top = getClientCenterY()-h/2;
	}
	showPhotoDiv.style.left = getClientCenterX()-w/2;
	showPhotoDiv.style.display = 'block';
	return true;
}

function hidePhoto() {
	var hideFrame = document.getElementById("hideFrame");
	var showPhotoDiv = document.getElementById("showPhotoDiv");

	hideFrame.style.display = 'none';
	showPhotoDiv.style.display = 'none';
	return true;
}

function next_prev_photo(photoId, nextOrPrevs) {
	var flag = false;
	for (i=0; i<photoArray.length; i++) {
		if (photoId==photoArray[i][0]) {
			if ((!nextOrPrevs) && (i==0)) {
				flag = false;
				var first = false;
				break;
			} else if (nextOrPrevs && (i==photoArray.length-1)) {
				flag = false;
				break;
			} else {
				flag = true;
				if (nextOrPrevs) { photoId=photoArray[i+1][0]; i++; } else { photoId=photoArray[i-1][0]; i--; }
				break;
			}
		}
	}
	
	if (flag) {
		var showPhotoDiv = document.getElementById("showPhotoDiv");
		showPhotoDiv.style.display = 'none';
		
		w = photoArray[i][1];
		h = photoArray[i][2];
		var photoText = document.getElementById("photoText"+photoId).innerHTML;
		
		var theText = '<table border="0" align="center" cellpadding="0" cellspacing="0"><tr><td><img src="/src/imgs/border-top-left1.gif"></td><td class="catalogTd">&nbsp;</td><td><img src="/src/imgs/border-top-right1.gif"></td></tr>';
		theText = theText+'<tr><td class="catalogTd">&nbsp;</td><td class="catalogTd"><a class="cat" href="javascript:hidePhoto(); void(0);"><img border=0 src=\'/src/photo/'+photoId+'.jpg\' width='+w+' height='+h+'><br>'+photoText+'</a></td><td class="catalogTd">&nbsp;</td></tr>';
		theText = theText+'<tr><td class="catalogTd">&nbsp;</td><td class="catalogTd">';
			theText = theText+'<table width="100%" border="0" align="center" cellpadding="8" cellspacing="0"><tr>';
			theText = theText+'<td align="left"><a href="javascript: next_prev_photo('+photoId+', false); void(0);"><img src="/src/imgs/arrowleft.gif" width="30" height="17" border="0"></a></td>';
			theText = theText+'<td align="right"><a href="javascript: next_prev_photo('+photoId+', true); void(0);"><img src="/src/imgs/arrowright.gif" width="30" height="17" border="0"></a></td>';
		theText = theText+'</tr></table>';
		theText = theText+'</td><td class="catalogTd">&nbsp;</td></tr>';
		theText = theText+'<tr><td><img src="/src/imgs/border-bottom-left1.gif"></td><td class="catalogTd">&nbsp;</td><td><img src="/src/imgs/border-bottom-right1.gif"></td></tr></table>';
		showPhotoDiv.innerHTML = theText;
		w = w+30; h = h+60;
		showPhotoDiv.style.width = w;
		showPhotoDiv.style.height = h;
		if ((getBodyScrollTop()==0) && (h>getClientHeight())) {
			showPhotoDiv.style.top = 10;
		} else if ((getBodyScrollTop()==(getDocumentHeight()-getClientHeight())) && (h>getClientHeight())) {
			showPhotoDiv.style.top = getDocumentHeight()-h-10;
		} else {
			showPhotoDiv.style.top = getClientCenterY()-h/2;
		}
		showPhotoDiv.style.left = getClientCenterX()-w/2;
		showPhotoDiv.style.display = 'block';
		return true;	
	} else {
		return false;
	}
}

function highlightTableRows(tableId, hoverClass, clickClass, multiple) {
	var table = document.getElementById(tableId);
	if (typeof multiple == 'undefined') multiple = true;
	if (hoverClass) {
		var hoverClassReg = new RegExp("\\b"+hoverClass+"\\b");
		table.onmouseover = table.onmouseout = function(e) {
			if (!e) e = window.event;
			var elem = e.target || e.srcElement;
			while (!elem.tagName || !elem.tagName.match(/td|th|table/i)) elem = elem.parentNode;
			if (elem.parentNode.tagName == 'TR' && elem.parentNode.parentNode.tagName == 'TBODY') {
				var row = elem.parentNode;
				if (!row.getAttribute('clickedRow')) row.className = e.type=="mouseover"?row.className+" "+hoverClass:row.className.replace(hoverClassReg," ");
			}
		};
	}

	
	if (clickClass) table.onclick = function(e) {
		if (!e) e = window.event;
		var elem = e.target || e.srcElement;
		while (!elem.tagName || !elem.tagName.match(/td|th|table/i)) elem = elem.parentNode;
		if (elem.parentNode.tagName == 'TR' && elem.parentNode.parentNode.tagName == 'TBODY') {
			var clickClassReg = new RegExp("\\b"+clickClass+"\\b");
			var row = elem.parentNode;
			if (row.getAttribute('clickedRow')) {
				row.removeAttribute('clickedRow');
				row.className = row.className.replace(clickClassReg, "");
				row.className += " "+hoverClass;
			} else {
				if (hoverClass) row.className = row.className.replace(hoverClassReg, "");
				row.className += " "+clickClass;
				row.setAttribute('clickedRow', true);
				if (!multiple) {
					var lastRowI = table.getAttribute("lastClickedRowI");
					if (lastRowI!==null && lastRowI!=='' && row.sectionRowIndex!=lastRowI) {
						var lastRow = table.tBodies[0].rows[lastRowI];
						lastRow.className = lastRow.className.replace(clickClassReg, "");
						lastRow.removeAttribute('clickedRow');
					}
				}
				table.setAttribute("lastClickedRowI", row.sectionRowIndex);
			}
		}
	};
}