
/* LUKY.COM - All Code Below Is Copyrighted.
   Copyright (c)2009 Todd Roseman. All Rights Reserved.
   Do not use without prior permission.
*/



function relativeFilePart( s )	{
	var i;
	
	var rsl = /\\/g;
	s = s.replace(rsl,'/');
	var re = /\/dw\/(.*)/;
	var rg = re.exec(s);
	if (rg)	{
		if (rg.length<=1)	{
			rr = /\/.com\/(.*)/;
			rg = rr.exec(s);
			if (rg.length<=1) { return s; }
		}
		return rg[1];
	}
	else { return s; }
}


function setCurrentPage() {
	var navEl = document.getElementById("menu");
	var aEls = navEl.getElementsByTagName("A");
	var i, as, thisFile, liEl, liEj, liElast;
	var currentFile = '';
	
	currentFile = relativeFilePart(document.URL);
	// alert(currentFile);

	// find this page and set it's <li> to different class, also set parents li (if exists)
	for (var i=0; i<aEls.length; i++) {
		// className
		as = new String(aEls[i].href);
		thisFile = relativeFilePart(as);
//		alert(thisFile + " " + as);
		// thisFile = as.substring(as.lastIndexOf('/')+1,100);
		// alert( thisFile + currentFile + (thisFile==currentFile));
		if (thisFile == currentFile)	{
			// break; // do all occurances of this file in menu
			
			// ignore home page
			if (currentFile.indexOf('index.htm')!=-1)	{ 
				break;
			}
			
			// set this element
			// set top-level parent (this menu, immediate parent, (not ul though)
			liEl = aEls[i];
			liEl.className = liEl.className + " menuhere";
			// also set parent (li)
			//liEj = liEl.parentNode;
			//liEj.className = liEj.className + " menuhere";
		}
	}
	// if (i == aEls.length) { return; }
	
	// top level item
	//	liEl.style.background = "url(images/bar-bg-on.gif)";
}




var newWin;
function largeImg(source)	{
	var s;
	s = "largeimg.htm?src="+escape(source);

	newWin = window.open(s,"newWin","resizable=yes,menubar=no,titlebar=yes,dependent=yes,width=100,height=100,alwaysRaised=yes");
	newWin.focus();
//	setTimeout('newWin.focus();',250);
	return false;
}


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(setCurrentPage);
