YAHOO.namespace("Estalea.util");

YAHOO.Estalea.util.PopupLinks = function(cfg){
	
	this.className = (null != cfg.className) ? cfg.className : "popup";
	
	this.closeClassName = (null != cfg.closeClassName) ? cfg.closeClassName : "closePopup";
	
	this.tagName = (null != cfg.tagName) ? cfg.tagName : "a";
	
	this.popupLinks = YAHOO.util.Dom.getElementsByClassName(this.className, this.tagName);
	
	this.closePopupLinks = YAHOO.util.Dom.getElementsByClassName(this.closeClassName, this.tagName);
	
	this.features = (null != cfg.features) ? cfg.features : "location=0,menubar=0,resizable=no,scrollbars=yes,width=600,height=600";
	
	for(i=0;i<this.popupLinks.length;i++){
		YAHOO.util.Event.addListener(this.popupLinks[i], "click", this.popupWindow, this, true);
	}
	
	for(i=0;i<this.closePopupLinks.length;i++){
		YAHOO.util.Event.addListener(this.closePopupLinks[i], "click", this.closePopupWindow, this, true);
	}
	
};

YAHOO.Estalea.util.PopupLinks.prototype = {

	popupWindow : function(event){
		YAHOO.util.Event.stopEvent(event);
		var target = YAHOO.util.Event.getTarget(event);
		while(typeof(target.href) == "undefined" && null != target.parentNode){
			target = target.parentNode;	
		}
		var newPopupWindow = window.open(target.href, '_blank', this.features);
    	return newPopupWindow;
	},
	
	closePopupWindow : function(event){
		YAHOO.util.Event.stopEvent(event);
		window.close();
	}
};