// JavaScript Document

JAPI._popupLibrary = {
	
	setImagePopup : function(element, pic_url, trigger_event, defuse_event){
		//($("show_image"), "images/mouse.jpg", "mouseover", "mouseout")
		var popup_id = 'popup' + JAPI.popup().generate_random();
		
		JAPI.common().addEvent(element, trigger_event, new Function('e', JAPI.popup().createShowPopup(popup_id, pic_url)), false);
		JAPI.common().addEvent(element, defuse_event, new Function('e', JAPI.popup().createRemovePopup(popup_id)), false); 
		
		
	}, // end function
	
	createImagePopup : function(e, popup_id, pic_url){
		
		var image = document.createElement("img");
		image.src = pic_url;
		
		var div = document.createElement("div");
		
		var x = JAPI.coordinate().getCursorXPosition(e) - 120; // + 1 a fix for firefox
		var y = JAPI.coordinate().getCursorYPosition(e) + 1; // + 1 a fix for firefox
		
		div.style.position = "absolute";
		div.style.left = x + "px";
		div.style.top = y + "px";
		div.style.zIndex = 100;
		div.style.borderColor = '#000000';
		div.style.borderWidth = '1px';
		div.style.borderStyle = 'solid';
		div.style.visibility = 'visible';
		div.style.width ='auto';
		div.style.height ='auto';
		div.id = popup_id;
		
		div.appendChild(image);
		
		document.body.appendChild(div);
		
		return div;
	}, // end function
	
	createShowPopup : function(popup_id, pic_url) {
		var func = "";
		
		func += "if(!e) e = window.event;";
		func += "var d = JAPI.popup().createImagePopup(e,\'" + popup_id + "\', \'" + pic_url + "\');";
		func += "document.body.style.cursor = 'wait';";
		
		return func;
	}, // end function
	
	createRemovePopup : function(popup_id){
		var func = "";
		
		func += "var popup = $(\'"+popup_id+"\');";
		func += "if(popup) popup.parentNode.removeChild(popup);";
		func += "document.body.style.cursor = 'auto';";
		
		return func;
	}, // end function 
	
	generate_random : function(){
		return Math.floor(Math.random()*10001)
	} // end function
	
} // end Library
