/**
 * Javascript Document by Jeffrey Ouma.
 * Copyright© 2008 artkenya.net Ltd.
 * All rights reserved.
 * 
 * Dialog Box Library
 * ==================
 * Functions that display dialog boxes and notification areas
 * anywhere in the site
 * 
 */

// Create the Dialog namespace under the BLEEZ library
BLEEZ.dialog = {};

/**
 * MODAL DIALOG
 * ============
 * This dialog box takes focus away from the page and prevents further interaction
 * until it is closed
 * 
 */

BLEEZ.dialog.modal = function(){
	this.box = new YAHOO.widget.Dialog("dialog-modal", {
		visible:false,
		close:true,
		draggable:false,
		modal:true,
		zindex:10,
		fixedcenter:true,
		constraintoviewport:true,
		effect:{effect: YAHOO.widget.ContainerEffect.FADE, duration:0.5}
	});

	this.Show = function(cls, hdr, msg, btns, w) {
		if (Dom.get("dialog-modal_mask")) {
			var elm = Dom.get("dialog-modal_mask");
			var parentElm = elm. parentNode;
			var oldElm = parentElm.removeChild(elm);
		}
		w = (!w) ? "350px" : w;
		this.box.setHeader(hdr);
		this.box.setBody("<div class=\"dialog-icon\"></div>" + msg);
		this.box.cfg.queueProperty("buttons", btns);
		this.box.cfg.queueProperty("width", w);
		Dom.removeClass("dialog-modal", "hide");
		Dom.removeClass("dialog-modal", "status-dialog");
		Dom.removeClass("dialog-modal", "error-dialog");
		Dom.removeClass("dialog-modal", "success-dialog");
		Dom.removeClass("dialog-modal", "info-dialog");
		Dom.removeClass("dialog-modal", "question-dialog");
		Dom.removeClass("dialog-modal", "progress-dialog");
		Dom.addClass("dialog-modal", cls);
		var elmArray = Dom.getElementsByClassName("yui-panel-container", "div");
		Dom.setStyle(elmArray, "z-index", "2");
		this.box.render();
		this.box.show();
		this.box.center();
		this.box.hideEvent.subscribe(this.box.removeMask);
		Dom.setStyle("dialog-modal_mask", "z-index", "3");
		Dom.setStyle("dialog-modal_c", "z-index", "4");
	};
};

/* End of BLEEZ.dialog.modal */


/**
 * NOTICE DIALOG
 * ============
 * This dialog box appears unobtrusively on the screen and fades after a given period.
 * It displays a message but provides no buttons for interaction with the site.
 * 
 */

BLEEZ.dialog.notice = function() {
	this.box = new YAHOO.widget.Dialog("dialog-notice", {
		visible:false,
		close:true,
		draggable:false,
		modal:false,
		fixedcenter:false,
		constraintoviewport:true,
		x:10, y:10,
		effect:{effect: YAHOO.widget.ContainerEffect.FADE, duration:1}
	});
	
	this.Show = function(cls, hdr, msg, w, sustain) {
		w = (!w) ? "400" : w;
		var x = Dom.getViewportWidth() - w;
		this.box.header.innerHTML = hdr;
		this.box.body.innerHTML = msg;
		this.box.cfg.queueProperty("x", x);
		this.box.cfg.queueProperty("width", w);
		
		Dom.removeClass("dialog-notice", "hide");
		Dom.addClass("dialog-notice", cls);
		this.box.render();
		this.box.show();
		if(!sustain) {
			this.Hide(false);
		}
	};
	
	this.Hide = function(x){
		if(x == true) {
			this.box.hide();
		} else {
			setTimeout("this.Hide(" + true + ")", 10000);
		}
	};
};

/* End of BLEEZ.dialog.notice */


BLEEZ.dialog.Init = function() {
	try {
		var imageGroup = new YAHOO.util.ImageLoader.group("bd", "mouseover", 2);
		imageGroup.className = " dialog-preload";
	} catch (e) {
		errorHandler(e);
	}
};

// Execute initialization function after the document has rendered
try {
	Event.onDOMReady(BLEEZ.dialog.Init);
} 
catch (e) {
	errorHandler(e);
}
