(function(){window.mcImageManager={settings:{document_base_url:"",relative_urls:false,remove_script_host:false,use_url_path:true,remember_last_path:"auto",target_elements:"",target_form:"",handle:"image,media"},setup:function(){var d=this,h,i=document,j=[];h=i.location.href;if(h.indexOf("?")!=-1){h=h.substring(0,h.indexOf("?"))}h=h.substring(0,h.lastIndexOf("/")+1);d.settings.default_base_url=unescape(h);function g(c){var b,a;for(b=0;b<c.length;b++){a=c[b];j.push(a);if(a.src&&/mcimagemanager\.js/g.test(a.src)){return a.src.substring(0,a.src.lastIndexOf("/"))}}}h=i.documentElement;if(h&&(h=g(h.getElementsByTagName("script")))){return d.baseURL=h}h=i.getElementsByTagName("script");if(h&&(h=g(h))){return d.baseURL=h}h=i.getElementsByTagName("head")[0];if(h&&(h=g(h.getElementsByTagName("script")))){return d.baseURL=h}},relaxDomain:function(){var d=this,c=/(http|https):\/\/([^\/:]+)\/?/.exec(d.baseURL);if(window.tinymce&&tinymce.relaxedDomain&&tinymce.relaxedDomain!=document.location.hostname){d.relaxedDomain=tinymce.relaxedDomain;return}if(c&&c[2]!=document.location.hostname){document.domain=d.relaxedDomain=c[2].replace(/.*\.(.+\..+)$/,"$1")}},init:function(b){this.extend(this.settings,b)},browse:function(c){var d=this;c=c||{};if(c.fields){c.oninsert=function(a){d.each(c.fields.replace(/\s+/g,"").split(/,/),function(f){var b;if(b=document.getElementById(f)){d._setVal(b,a.focusedFile.url)}})}}this.openWin({page:"index.html",scrollbars:"yes"},c)},edit:function(b){this.openWin({page:"edit.html",width:800,height:500},b)},upload:function(b){this.openWin({page:"upload.html",width:550,height:350},b)},view:function(b){this.openWin({page:"view.html",width:800,height:500},b)},createDir:function(b){this.openWin({page:"createdir.html",width:450,height:280},b)},openWin:function(f,l){var i=this,a,k;i.windowArgs=l=i.extend({},i.settings,l);f=i.extend({x:-1,y:-1,width:800,height:500,inline:1},f);if(f.x==-1){f.x=parseInt(screen.width/2)-(f.width/2)}if(f.y==-1){f.y=parseInt(screen.height/2)-(f.height/2)}if(f.page){f.url=i.baseURL+"/../index.php?type=im&page="+f.page}if(l.session_id){f.url+="&sessionid="+l.session_id}if(l.custom_data){f.url+="&custom_data="+escape(l.custom_data)}if(i.relaxedDomain){f.url+="&domain="+escape(i.relaxedDomain)}if(l.target_frame){if(k=frames[l.target_frame]){k.document.location=f.url}if(k=document.getElementById(l.target_frame)){k.src=f.url}return}if(window.tinymce&&tinyMCE.activeEditor){return tinyMCE.activeEditor.windowManager.open(f,l)}if(window.jQuery&&jQuery.WindowManager){return jQuery.WindowManager.open(f,l)}a=window.open(f.url,"mcImageManagerWin","left="+f.x+",top="+f.y+",width="+f.width+",height="+f.height+",scrollbars="+(f.scrollbars?"yes":"no")+",resizable="+(f.resizable?"yes":"no")+",statusbar="+(f.statusbar?"yes":"no"));try{a.focus()}catch(j){}},each:function(i,j,f){var h,g;if(i){f=f||i;if(i.length!==undefined){for(h=0,g=i.length;h<g;h++){j.call(f,i[h],h,i)}}else{for(h in i){if(i.hasOwnProperty(h)){j.call(f,i[h],h,i)}}}}},extend:function(){var i,a=arguments,g=a[0],h,j;for(h=1;h<a.length;h++){if(j=a[h]){for(i in j){g[i]=j[i]}}}return g},open:function(j,n,h,i,k){var m=this,l;k=k||{};if(!k.url&&document.forms[j]&&(l=document.forms[j].elements[n.split(",")[0]])){k.url=l.value}if(!i){k.oninsert=function(a){var b,d,e,c=a.focusedFile;e=n.replace(/\s+/g,"").split(",");for(d=0;d<e.length;d++){if(b=document.forms[j][e[d]]){m._setVal(b,c.url)}}}}else{if(typeof(i)=="string"){i=window[i]}k.oninsert=function(a){i(a.focusedFile.url,a)}}m.browse(k)},filebrowserCallBack:function(o,m,s,n,r){var l=mcImageManager,q,t,p,i={};if(window.mcFileManager&&!r){t=mcFileManager.settings.handle;t=t.split(",");for(q=0;q<t.length;q++){if(s==t[q]){p=1}}if(p&&mcFileManager.filebrowserCallBack(o,m,s,n,1)){return}}l.each(tinyMCE.activeEditor?tinyMCE.activeEditor.settings:tinyMCE.settings,function(a,b){if(b.indexOf("imagemanager_")===0){i[b.substring(13)]=a}});l.browse(l.extend(i,{url:n.document.forms[0][o].value,relative_urls:0,oninsert:function(d){var a,b,c;a=n.document.forms[0];b=d.focusedFile.url;inf=d.focusedFile.custom;if(typeof(TinyMCE_convertURL)!="undefined"){b=TinyMCE_convertURL(b,null,true)}else{if(tinyMCE.convertURL){b=tinyMCE.convertURL(b,null,true)}else{b=tinyMCE.activeEditor.convertURL(b,null,true)}}if(inf.custom&&inf.custom.description){c=["alt","title","linktitle"];for(q=0;q<c.length;q++){if(a.elements[c[q]]){a.elements[c[q]].value=inf.custom.description}}}l._setVal(a[o],b);n=null}}));return true},_setVal:function(f,e){f.value=e;try{f.onchange()}catch(d){}}};mcImageManager.setup();mcImageManager.relaxDomain()})();