/*
Viewer is an extension of Lightview
It creates custom CONFIRM & ALERT, and pop up info.
This Class requires plugins: Lightview.
*/

document.write("<div id='__Viewer-Container__' style='display:none;padding:10px;font-weight:bold;text-align:center'></div>");

var Viewer=Object.extend(Lightview,{

//------------------------------------------------------------------------------
	// Pop an information that can shut down on its own
	popInfo:function(content,timeout){
	   this._showUpdateContent(content,timeout);
	},
//------------------------------------------------------------------------------
    // Create an alert window
	alert:function(info,fn){

	      var content="\
		    <img src='"+gmbApp.iconDir+"/error.png'>\
		    <div id='hrLine'></div>\
		    "+info+"\
		    <div id='hrLine'></div>\
		    "+this._makeTable(this._makeButton('Ok',fn))+"\
			<div class='clear'></div>\
		  ";

		  this._showUpdateContent(content)
	},
//------------------------------------------------------------------------------
    // Create a confirm window
	confirm:function(info,yesFn,noFn){
	      var content="\
		    <img src='"+gmbApp.iconDir+"/important.png'>\
		    <div id='hrLine'></div>\
		    "+info+"\
		    <div id='hrLine'></div>\
		    "+this._makeTable(this._makeButton('Yes',yesFn)+this._makeButton('No',noFn))+"\
			<div class='clear'></div><div class='clear'></div>\
		  ";

		  this._showUpdateContent(content)
	},
//------------------------------------------------------------------------------
   // To update and show the window
	_showUpdateContent:function(viewerContent,timeout){

	      $("__Viewer-Container__").update(viewerContent)

	       this.show({
			   href:"#__Viewer-Container__",
			   rel:'inline',
			   options:{menubar:false,autosize:true}
		   })

		   if(timeout>0)window.setTimeout(function(){this.hide()}.bind(this), (timeout + 1.5)*1000);
	},
//------------------------------------------------------------------------------
    // Eval a str to function for execution
	_evalFn: function(fn){eval(fn)},
	// Create a centered table
	_makeTable : function(content){return ("<center><table border='0'><tr><td align='center'>"+content+"</td></tr></table></center>");},
	// Create a button with value and onCLick content
	_makeButton : function(value,onClick){return ("<a  href='javascript:gmb()' class='CoolButton' onClick='Viewer._evalFn(\"Viewer.hide();"+onClick+"\")'><span>"+value+"</span></a>");},
	// Close window
	_destroy:function(){this.hide()}

});