/*
 * hipic.web.app
 * Copyright(c) 2010, FeiKan.
 * 
 * This code is licensed under BSD license. Use it as you wish, 
 * but keep this copyright intact.
 */


$(function()
{app.ui.msgbox=function(icon,height,closeable)
{var _el;var _icon=icon||'info';var _text,_btns;var _height=height||OP['ui-msgbox-default-height'];var _win,_pane,_textPane,_btnPane;var _init=function()
{var hc=_height-30;if(hc<64)
{hc=64;}
_win=new UI_WIN(400,_height,closeable);_el=_win.el();_pane=$('<div style="padding:0 20px;"><div>');_textPane=$('<div class="ui-msgbox-textpane" style="display:block;margin-bottom:5px;padding-left:80px;height:{0}px;"><div>'.toString(hc)).appendTo(_pane);_btnPane=$('<div style="padding-top:5px;text-align:right;border-top:dashed 1px #ccc;"><div>').appendTo(_pane);var icocls;switch(_icon)
{case'i':case'info':icocls='ui-msgbox-info';break;case'e':case'error':icocls='ui-msgbox-error';break;case'q':case'question':icocls='ui-msgbox-question';case'l':case'loading':icocls='ui-msgbox-loading';break;}
_win.el().addClass('ui-msgbox').append(_pane);_textPane.addClass(icocls);};var _buildButton=function()
{_btnPane.empty();if(_btns)
{$.each(_btns,function()
{var bt;var c=this.toString().toLowerCase();switch(c)
{case'ok':bt=WORD(E['ui-msgbox-result-ok']);break;case'yes':bt=WORD(E['ui-msgbox-result-yes']);break;case'no':bt=WORD(E['ui-msgbox-result-no']);break;case'cancel':bt=WORD(E['ui-msgbox-result-cancel']);break;}
if(bt)
{var b=$('<button style="margin:0 10px;padding:0 10px;">{0}</button>'.toString(bt)).appendTo(_btnPane);b.bind('click',{'btn':bt},_onButtonClick);}});_btnPane.show();}
else
{_btnPane.hide();}};var _onButtonClick=function(e)
{if(_el.triggerHandler(E['ui-msgbox-on-close'],e.data)!==false)
{_close();}};var _show=function()
{if(!_win)
{_init();}
_buildButton();_textPane.empty().append(_text);_win.show();};var _close=function()
{$.each(_btnPane.children('button'),function()
{$(this).unbind('click');});_win.close();_win=null;};return{el:function()
{if(!_el)
{_init();}
return _el;},show:function(buttons,text,height)
{var t=text||buttons||'';var b=text?(buttons===undefined?['ok']:buttons):['ok'];if(t)
{_text=t;}
if(b)
{if(TYPE.isArray(b))
{_btns=b;}
else
{_btns=[b];}
_text=t;}
if(TYPE.isInteger(height)&&height>30)
{_height=height-30;}
_show();return this;},close:function()
{_close();return this;}}};app.ui.msgbox.show=function(height,msg,ico,btn,callback)
{var h=undefined;var m=height;var i=msg;var b=ico;var c=btn;if(TYPE.isInteger(height))
{h=height;m=msg;i=ico;b=btn;c=callback;}
var bx=new UI_MSGBOX(i).show(b,m,h);if(!c)
{bx=null;}
else
{bx.el().bind(E['ui-msgbox-on-close'],c);}};$.extend(window,{UI_MSGBOX:app.ui.msgbox});});
