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