(function() {
	// when the document finishes loading, call the init() function below
	YAHOO.util.Event.addListener(window, "load", init);
	
	YAHOO.namespace("library");
	
	function init() {
		// create modal panel for lexis nexis
		createPanelVerify();
		
		// grab lexis nexis div 
		var lnLink = YAHOO.util.Dom.getElementsByClassName("lexisnexis", "a");
		
		try {
			for (var i = 0; i < lnLink.length; ++i) {
				YAHOO.util.Event.addListener(lnLink[i], "click", verifySelect);
			}
		} catch (e) { }
	}
	
	var verifySelect = function(e) {
		// prevent following of link
		YAHOO.util.Event.preventDefault(e);
		
		// capture href
		YAHOO.library.wait.href = this.href;
		
		// show panel
		YAHOO.library.wait.show();
	}
	
	var createPanelVerify = function () {
		YAHOO.library.wait = 
			new YAHOO.widget.Panel("wait",  
				{ width:"300px", 
				  fixedcenter:true, 
				  close:true, 
				  draggable:false, 
				  zindex:4,
				  modal:true,
				  visible:false
				} 
			);
	
		YAHOO.library.wait.setHeader("LexisNexis Access");
		YAHOO.library.wait.setBody("<p>Using LexisNexis requires a <a href='http://library.sd.gov/howdoi/index.htm' title='get a State Libray barcode and password' target='_blank' style='text-decoration: underline'>State Library barcode and password</a>.</p><p>Do you want to continue to LexisNexis?</p><p><button id='btnContinue' value='Continue'>Continue</button><button id='btnCancel' value='Cancel'>Cancel</button></p>");
		YAHOO.library.wait.render(document.body);
		
		// setup control buttons
		YAHOO.util.Event.addListener("btnCancel", "click", hidePanel);
		YAHOO.util.Event.addListener("btnContinue", "click", goToLN);
	}
	
	var hidePanel = function (e) {
		YAHOO.library.wait.hide();
	}
	
	var goToLN = function (e) {
		// pass user along
		location.href = YAHOO.library.wait.href;
	}
})();