(function(b){window.ViewDialog={currentWin:b.WindowManager.find(window),init:function(){var d=this,a;d.args=a=b.extend({path:"{default}",visual_path:"/"},d.currentWin.getArgs());d.singeViewTpl=b.templateFromScript("#singleview_template");d.mpgTpl=b.templateFromScript("#mpg_template");d.rmTpl=b.templateFromScript("#rm_template");d.movTpl=b.templateFromScript("#mov_template");d.dcrTpl=b.templateFromScript("#dcr_template");d.footerFullTpl=b.templateFromScript("#single_footer_full");d.footerNoEditTpl=b.templateFromScript("#single_footer_no_edit");d.footerSimpleTpl=b.templateFromScript("#single_footer_simple");b("#prev").click(function(c){if(!b(c.target).hasClass("disabled")){d.getMediaInfo(d.prevMedia)}});b("#next").click(function(c){if(!b(c.target).hasClass("disabled")){d.getMediaInfo(d.nextMedia)}});b("#gallery").click(function(c){if(!b(c.target).hasClass("disabled")){d.currentWin.close()}});b("#singlefooter").click(function(c){var e=c.target,h=e.nodeName=="A"?e:b(e).parents("a")[0];if(h){h=b(h);if(h.attr("id")=="deleteit"&&!h.hasClass("disabled")){d.deleteFile(d.path)}if(h.attr("id")=="edit"&&!h.hasClass("disabled")){d.editFile(d.path)}}});b().keydown(function(c){switch(c.keyCode){case 32:case 110:case 34:case 39:case 40:d.getMediaInfo(d.nextMedia);break;case 102:case 33:case 37:case 38:d.getMediaInfo(d.prevMedia);break;case 27:d.currentWin.close();break}});b(window).bind("resize",function(){d.resizeView()});b("#singlecontent").click(function(c){if(c.target.nodeName=="IMG"&&b(c.target).hasClass("viewimage")){if(a.onselect){RPC.insertFile({relative_urls:a.relative_urls,document_base_url:s.document_base_url,default_base_url:s.default_base_url,no_host:a.remove_script_host||a.no_host,path:d.path,progress_message:b.translate("{#message.insert}"),insert_filter:a.insert_filter,oninsert:function(f){a.onselect(f);d.currentWin.close()}})}else{d.currentWin.close()}}});d.getMediaInfo(a.path);focus()},getMediaInfo:function(d){var a=this;a.path=d;RPC.exec("im.getMediaInfo",{path:d},function(k){var l,c,m,n;l=RPC.toArray(k.result);c=l[0];a.nextMedia=c.next;a.prevMedia=c.prev;if(!c.next){b("#next").addClass("disabled")}else{b("#next").removeClass("disabled")}if(!c.prev){b("#prev").addClass("disabled")}else{b("#prev").removeClass("disabled")}n=a.footerSimpleTpl;switch(c.type){case"jpg":case"jpeg":case"gif":case"png":case"bmp":m=a.singeViewTpl;n=a.footerFullTpl;break;case"mpg":case"mpeg":case"wma":case"wmv":case"asf":case"avi":m=a.mpgTpl;break;case"qt":case"mov":m=a.movTpl;break;case"rm":case"ram":m=a.rmTpl;break;case"dcr":m=a.dcrTpl;break;case"swf":var j=new SWFObject("../../stream/index.php?cmd=im.streamFile&path="+escape(c.path),"swfMovie",c.width,c.height,"7","#FFFFFF");j.addParam("quality","high");j.addParam("scale","showall");j.addParam("wmode","transparent");j.write("singlecontent");b("#singlefooter").html(a.footerNoEditTpl,c);return;case"flv":var j=new SWFObject("flvplayer/flvPlayer.swf","flvPlayer",c.width,c.height,"8","#FFFFFF");j.addVariable("flvToPlay","../../../stream/index.php?cmd=im.streamFile%26path="+escape(c.path));j.addVariable("hiddenGui","false");j.addVariable("showScaleModes","true");j.addVariable("autoStart","false");j.addParam("allowFullScreen","true");j.write("singlecontent");b("#singlefooter").html(a.footerNoEditTpl,c);return}b("#singlecontent").html(m,c);b("#singlefooter").html(n,c);if(c.custom){if(!c.custom.editable){b("#singleview .editsingle a.edt").addClass("disabled")}else{b("#singleview .editsingle a.edt").removeClass("disabled")}}a.resizeView()})},resizeView:function(){b("#singleimg").css({width:b.winWidth()-60,height:b.winHeight()-100})},deleteFile:function(d){var a=this;b.WindowManager.confirm(b.translate("{#view.confirm_delete}"),function(c){if(c){if(!a.isDemo()){RPC.exec("im.deleteFiles",{path0:d},function(g){var h;if(!RPC.handleError({message:"{#error.delete_failed}",visual_path:a.args.visual_path,response:g})){if(a.args.ondelete){a.args.ondelete(d)}if(a.nextMedia){a.getMediaInfo(a.nextMedia)}else{if(a.prevMedia){a.getMediaInfo(a.prevMedia)}else{a.currentWin.close()}}}})}}})},editFile:function(d){var a=this;b.WindowManager.open({url:"edit.html"},{is_demo:a.args.is_demo,path:d,visual_path:this.visualPath,onsave:function(){a.getMediaInfo(a.path)}}).maximize()},isDemo:function(){if(this.args.is_demo){b.WindowManager.info(b.translate("{#error.demo}"));return true}}};b(function(a){ViewDialog.init()})})(jQuery);