DOM = (document.getElementById)? true : false;
IE = (navigator.userAgent.indexOf("MSIE") != -1);

screenPopup = function(src, para){
	nw = window.open("","",para);
	nw.document.open();
		nw.document.write('<!DOCTYPE HTML PUBLIC "-\/\/W3C\/\/DTD HTML 4.01 Transitional\/\/EN"><html><head><title>PortaOne | Screenshot Popup<\/title><\/head><body>')
		nw.document.write("<a href='#' onclick='window.close();'><img src='"+src+"' style='border-width: 0px;'><\/a>");
		nw.document.write('<\/body><\/html>');
	nw.document.close();
}

removeClassName = function(node, str){
	re = new RegExp(str,"gi");
	node.className = node.className.replace(re,"");
	re = /\s+/gi;
	node.className = node.className.replace(re," ");
}

clearActivePages = function(containerNode){
	aList = document.getElementsByTagName("A");
	for(var i=0; i<aList.length; i++){
		removeClassName(aList.item(i),"hlPage");
	}
}

showPagedList = function(page, listNode, ipp){
	liList = listNode.getElementsByTagName("LI");
	start = (page-1) * ipp;
	end = (page * ipp > liList.length)?  liList.length : page * ipp;
	for(var i=0; i< liList.length; i++){
		liList.item(i).style.display = (i>= start && i<end)? "block" : "none";
	}
}

drawPage  = function(num, containerNode, listNode, ipp, firstPage){
	aNode = document.createElement("A");
	aNode.appendChild(document.createTextNode("\u00a0\u00a0"+num+"\u00a0\u00a0"));
	aNode.href="#";
	aNode.page = num;
	aNode.listNode = listNode;
	aNode.ipp = ipp;
	if(firstPage) aNode.className += "hlPage";
	aNode.onclick = aNode.onmousedown = function(){
		clearActivePages(this.parentNode);
		this.className = "hlPage";
		showPagedList(this.page, this.listNode, this.ipp)
		return false;
	}
	containerNode.appendChild(aNode);
}

makePager = function(listID, containerID){
	items_per_page = (arguments[2])? arguments[2] : 10;
	listNode = document.getElementById(listID);
	containerNode = document.getElementById(containerID);
	if(listNode && containerNode){
		liList = listNode.getElementsByTagName("LI");

		active_pos = -1;
		for(var i=0; i<liList.length; i++){
			if(liList.item(i).className.indexOf("current_page_item") != -1){
				active_pos = i;
				break;
			}
		}
		pages = Math.ceil(liList.length / items_per_page);
		active_page = (active_pos >=0 )? Math.ceil((active_pos+1)/items_per_page) : 1;
		if(pages > 1){
			for(var i=0; i< pages; i++){
				drawPage(i+1, containerNode, listNode, items_per_page, i+1==active_page);
			}
		}
		showPagedList(active_page, listNode, items_per_page);
	}
}                                                              