/*
  (c) 2008-2014 Samnan ur Rehman
 @web        http://mywebsql.net
 @license    http://mywebsql.net/license
*/
var taskbar={_win:{},init:function(){$("#taskbar .min-all").button().click(function(){taskbar.minimizeAll()})},openDialog:function(a,b,d,e){var f=null;a="dialog-"+a.replace(/ /g,"-");if(obj=this.findDialog(a))return 0==this._win[a].state&&($("#"+a).dialogExtend("restore"),this._win[a].state=1),!1;this._win[a]={status:0,url:b,state:1};f=this.createDialog(a,b,d,e,!1);f.find(".dialog_contents").attr("src","javascript:false");this.updateDialog(0,f.id);f.dialog("open");f.find("ui-dialog-title").html(__("Loading")+
"...");f.find(".dialog_contents").attr("src",b);$("#taskbar").append('<input type="button" value="'+__("Loading")+'..." id="tb-button-'+a+'" />');$("#tb-button-"+a).button().click(function(){taskbar.handle(a)});main_layout.open("south")},openModal:function(a,b,d,e){a="dialog-"+a.replace(/ /g,"-");dlg=this.createDialog(a,b,d,e,!0);dlg.find(".dialog_contents").attr("src","javascript:false");this.updateDialog(0,dlg.id);dlg.dialog("open");dlg.find("ui-dialog-title").html(__("Loading")+"...");dlg.find(".dialog_contents").attr("src",
b)},handle:function(a){0==this._win[a].state&&($("#"+a).dialogExtend("restore"),this._win[a].state=1);$("#"+a).dialog("moveToTop")},findDialog:function(a){for(dlg in this._win)if(dlg==a)return this._win[dlg];return!1},createDialog:function(a,b,d,e,f){b=$("#dialog-template").clone();var c=a.replace(/ /g,"-");b.attr("id",c);b.find(".dialog_contents").attr("id",c+"-contents");b.dialog({modal:f,autoOpen:!1,width:d,height:e,minWidth:460,minHeight:260,open:function(){d=$("#"+c).parent(".ui-dialog").width();
e=$("#"+c).parent(".ui-dialog").height();$("#"+c+"-contents").width(d).height(e)},close:function(){$("#taskbar").find("#tb-button-"+a).remove();0==$("#taskbar").find("input").length&&main_layout.close("south");$("#"+c).dialog("destory");$("#"+c+"-contents").remove();$("#"+c).remove();delete taskbar._win[c]}});f||b.dialogExtend({maximize:!1,minimize:!0,events:{minimize:function(a,b){taskbar.minimize(b.id)}}});b.bind("dialogresizestart dialogdragstart",function(){iframe=$("#"+c+"-contents");var a=$("<div></div>");
$("#"+c).append(a[0]);a[0].id=c+"-div";a.css({position:"absolute"});a.css({top:0,left:0});a.height(iframe.height());a.width("100%")});b.bind("dialogresizestop dialogdragstop",function(){$("#"+c+"-div").remove();d=$("#"+c).parent(".ui-dialog").width();e=$("#"+c).parent(".ui-dialog").height();$("#"+c+"-contents").width(d).height(e)});$("#"+c+"-contents").bind("load",function(){taskbar.updateDialog(1,c)});return b},updateDialog:function(a,b){if(b)if(1==a){$("#"+b+" .dialog_msg").css("display","none");
$("#"+b+"-contents").css("display","block");$("#"+b).parent(".ui-dialog").trigger("resize");try{title=document.getElementById(b+"-contents").contentWindow.title,this._win[b]&&(this._win[b].status=1,$("#tb-button-"+b).button({label:title})),$("#"+b).siblings(".ui-dialog-titlebar").find(".ui-dialog-title").html(title),win=document.getElementById(b+"-contents").contentWindow,$(win.document).find("#popup_overlay").addClass("ui-helper-hidden")}catch(d){}}else $("#"+b+" .dialog_msg").css("display","block"),
$("#"+b+"-contents").css("display","none")},minimize:function(a){this._win[a].state=0},minimizeAll:function(){for(dlg in this._win)1==this._win[dlg].state&&($("#"+dlg).dialogExtend("minimize"),this._win[dlg].state=0)}};