YAHOO.namespace('bp.popup');

YAHOO.bp.popup = function() {
	var $D = YAHOO.util.Dom;
	var $E = YAHOO.util.Event;
	var $ = $D.get;

	var triggerPairing = 'bppopup';
	var triggerVideo = 'pupvideo';
	
	var popupName = 'BPPOPUP';
	
	var defWidth	= 720;
	var defHeight	= 250;
	var defTop		= 100;
	var defLeft		= 100;
	
	var defVideoHeight = 660;
	var defVideoWidth = 840;
	
	var defProperties;

	
	return {
		init : function(e, obj) {
			var allLinks = $D.getElementsByClassName (triggerPairing);
			
			for (var i = 0; i < allLinks.length; i++)
				$E.addListener (allLinks[i], 'click', this.doPopup);
				
			defPairing    = 'width=' + defWidth +
							',height=' + defHeight +
							',top=' + defTop + 
							',left=' + defLeft +
							',dependent=yes,resizable=yes,scrollbars=yes,menubar=no,toolbar=no,status=no,location=no';

			var allVideo = $D.getElementsByClassName (triggerVideo);
			
			for (var i = 0; i < allVideo.length; i++)
				$E.addListener (allVideo[i], 'click', this.doPopup);
				
			defVideo      = 'width=' + defVideoWidth +
							',height=' + defVideoHeight +
							',top=' + defTop + 
							',left=' + defLeft +
							',dependent=yes,resizable=yes,scrollbars=yes,menubar=no,toolbar=no,status=no,location=no';
		},
		doPopup : function(e){
			var t = $E.getTarget(e);

			if (t.nodeName.toLowerCase() != 'a')
				t = t.parentNode;

			var popupProperties = (t.className == triggerVideo) ? defVideo : defPairing;
			// should split className to find all classes...
			
			var thePopup = window.open (t.getAttribute('href'),
										popupName,
										popupProperties);			

			if (thePopup && window.focus) 
			{
				thePopup.focus();
			}
			
			$E.stopEvent (e);
		},
		showPopup : function (s){
			var popupProperties = defPairing;
			
			var thePopup = window.open (s,
										popupName,
										popupProperties);			

			if (thePopup && window.focus) 
				thePopup.focus();
		}
	};
}();

YAHOO.util.Event.addListener(window, 'load', YAHOO.bp.popup.init, YAHOO.bp.popup, true);

