/* 
	Original script:  prepareLinks 
	From: "DOM Scripting" (Friends of Ed/Apress, 2005) by Jeremy Keith, pp. 86-88.
		[Also using addLoadEvent -- same source, pp. 102-104.]
	
	Modified version:  popupHandler
	By:  Spencer Sundell  http://spencersundell.com/  19 Feb 2006
	This script may be used for any non-evil purpose provided you do not sell it and/or 
	claim original authorship.
	If you wanna be a pal, please include this notice in your JavaScript source.  :-)
*/

/*
  USAGE (delete this comment block for live deployment):

	To declare custom height, append width & height vals as 3 digit combos.
	 Format: 	popupclassWWWHHH
	 Example:	popup215095	 ==  width: 215 pixels  height: 95 pixels
	 
	To declare/target a custom window name, add TARGET to your link.

	Use all defaults:
		<a href="pop.html" class="popup">launch</a>
	
	Declare custom dimensions, and use default window name:
		<a href="pop.html" class="popup200100">launch</a></p>
	
	Declare/target custom window name (optional: also declare custom dimensions as above):
		<a href="pop.html" class="popup" target="specialWindow">launch</a>
	  Warning:  this usage will launch new window no matter what. Mind your accessibility.
	  Also: if using frames/iframes, do not target an existing frame name.  Duh.
	
	Declare additional styles as desired BUT pop-up class MUST come first!
		<a href="pop.html" class="popup500100 redLink fooClass" target="widePopup">launch</a>
*/

/* pop-up defaults: */
	var popClass = "popup";
	var popName	= "popWin";
	var popW	= 300;
	var popH	= 150;

addLoadEvent(popupHandler);

/* ------- */
	function popupHandler(){var cl=popClass.length;var a=document.getElementsByTagName("a");for(var i=0;i<a.length;i++){var ca=document.getAttribute?a[i].getAttribute("class").split(" "):a[i].className.split(" ");if(ca[0].substring(0,cl)==popClass){a[i].onclick=function (){var ca2=document.getAttribute?this.getAttribute("class").split(" "):this.className.split(" ");var c=ca2[0];var w=(c==popClass)?popW:c.substring(cl,(cl+3));var h=(c==popClass)?popH:c.substring((cl+3),(cl+6));var t=this.getAttribute("target")?this.getAttribute("target"):popName;popUp(this.getAttribute("href"),t,w,h);return false;}}}}
	function popUp(winURL,t,w,h){var specs="width="+w+",height="+h;/*specs+=",status=1,menubar=1,location=1,toolbar=1,resizable=1,directories=1";*/var scrX=Math.round((screen.width/2)-(w/2));var scrY=Math.round((screen.height/2)-(h/2));if(scrY>100){scrY=scrY-40;}specs+=',top='+scrY+',left='+scrX;var win=window.open(winURL,t,specs);win.focus();}
	function addLoadEvent(func){var oldonload=window.onload;if(typeof window.onload!='function '){window.onload=func;}else{window.onload=function (){oldonload();func();}}}
