var win;
var root;

function init(strRoot){
	root = strRoot;
	
	//get the reference to the photos lists
	var wrapper;	
	var tempList;
	var list;
	
	if (document.getElementById("photo_categories") != null || document.getElementById("photo_categories") != null){
		wrapper = document.getElementById("photo_categories");
		list = wrapper.getElementsByTagName("ul");
	}
	
	//iterate over the photos links in the lists
	for (var i=0; i<list.length; i++){
		
		tempList = list[i].getElementsByTagName("a");
		
		for (var j=0; j<tempList.length; j++){
			//apply action listener
			tempList[j].onclick = photoClick;
			
			
			//wrap the image in the onion layers
			//build the wrapper DIVs
			var w1 = document.createElement("span");
			w1.className = "wrap1";
			var w2 = document.createElement("span");
			w2.className = "wrap2";
			var w3 = document.createElement("span");
			w3.className = "wrap3";
			
			//attach the spans to each other
			w1.appendChild(w2);
			w2.appendChild(w3);
			
			//duplicate the image node
			//attach the img node to the wrappers
			var imgNode = tempList[j].firstChild;
			var newImgNode = tempList[j].firstChild.cloneNode(true);
			w3.appendChild(newImgNode);
			
			//place the wrapper DIVs in the document tree where the image is
			imgNode.parentNode.replaceChild(w1, imgNode);
		}
	}
}

function photoClick(event){
	
	if ( !(win == null || win.closed) ){
		win.close();
		win = null;
	}
	
	//get the URL of the link object
	var strUrl = new String(this);
	//return true if the NewWindow function fails so that the link  can be followed
	
	return	(NewWindow( root + "lib/viewer.html?" + strUrl, "CMUSS_Photo", 700, 615, "yes") == null);
}


/*
Auto center window script- Eric King (http://redrival.com/eak/index.shtml)
Permission granted to Dynamic Drive to feature script in archive
For full source, usage terms, and 100's more DHTML scripts, visit http://dynamicdrive.com
*/
function NewWindow(mypage,myname,w,h,scroll){
	//center positioning
		
	var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-h)/2 : 0;		

	var settings ="height="+h+",width="+w+",top="+TopPosition+",left="+LeftPosition+",scrollbars="+scroll+",resizable";

	win = window.open(mypage,myname,settings);
	
	return win;
}
