// JavaScript Document

/*
	UI Factory handles the UI functions on the Overlay.tv website.
	
	Requirements:
		Prototype (http://www.prototypejs.org)
		PrototypeWindow (http://prototype-window.xilinus.com/)
	
*/

// the 'overlay' div for modal popups fades in unless I do the following.
Windows['overlayShowEffectOptions'] = {duration: 0},
Windows['overlayHideEffectOptions'] = {duration: 0}

var Popup = {
	// Vars
	linkBuffer: 3, // spacing between link and popup


	// Private
	_createWin: function(attribs)
	{
		var defaults = {width:525,height:undefined,destroyOnClose: false,minimizable:false,maximizable:false,draggable:false,resizable:false, showEffect:Element.show, hideEffect:Element.hide};
		for(var key in attribs)
		  defaults[key] = attribs[key];
		
		var win = new PrototypeWindow(defaults);
		return(win);
	},
	
	//Private
	_showWindow : function(win, modal, onLoadFunc, onCloseFunc) {
		var o = new Object();
		
		o.onClose = function(eventName, win) {
			if(onCloseFunc != undefined)
				onCloseFunc.call(eventName, win);
			Windows.removeObserver(this);
		}
		
		if( onLoadFunc != undefined )
			o.onShow = onLoadFunc;
			
		Windows.addObserver(o);

		if( modal == undefined )
		  modal = true;

		win.showCenter(modal);
			
			
		return win;
	},
	
	_clearObserver: function(eventName, win)
	{
		Windows.removeObserver(this);
	},
	

	// Public
	
	// Parameters:
	//    divName (String) name of div id
	//    modal (Boolean) modal window (true) or now (false)  Default True
	//    attribs (Array) (optional) additional parameters for PrototypeWindow contructor (See http://prototype-window.xilinus.com/documentation.html#initialize)
	//    onLoadFunc (function) (optional) function to be called after load
	//    onCloseFunc (function) (optional) function to be called after close
	fromDiv: function(divName,modal,attribs,onLoadFunc,onCloseFunc)
	{
		var win = this._createWin(attribs);
		
		$(divName).addClassName("popupContent");
		win.setContent(divName);
		
		return this._showWindow(win, modal,onLoadFunc, onCloseFunc);
	},
	
	// Parameters:
	//    content (String) html content for windoe
	//    modal (Boolean) modal window (true) or now (false)  Default True
	//    attribs (Array) (optional) additional parameters for PrototypeWindow contructor (See http://prototype-window.xilinus.com/documentation.html#initialize)
	//    onLoadFunc (function) (optional) function to be called after load
	fromContent : function(content, modal, attribs, onLoadFunc) {
		
		var win = this._createWin(attribs);
		
		win.setHTMLContent(content);
		
		return this._showWindow(win, modal, onLoadFunc);
	}
}


