if(typeof(XWiki)=="undefined"){XWiki=new Object()
}if(typeof(XWiki.widgets)=="undefined"){XWiki.widgets=new Object()
}XWiki.widgets.FullScreen=Class.create({margin:0,buttonSize:16,initialize:function(){this.buttons=$(document.body).down(".bottombuttons");
if(!this.buttons){this.buttons=new Element("div",{"class":"bottombuttons"}).update(new Element("div",{"class":"buttons"}));
this.buttons._x_isCustom=true;
document.body.appendChild(this.buttons.hide())
}this.buttonsPlaceholder=new Element("span");
this.toolbarPlaceholder=new Element("span");
this.createCloseButtons();
$$("textarea",".maximizable").each(function(b){this.addBehavior(b)
}.bind(this));
$$(".xRichTextEditor").each(function(b){this.addBehavior(b)
}.bind(this));
this.addWysiwyg20Listener();
this.maximizedReference=$(document.body).down("input[name='x-maximized']");
if(this.maximizedReference&&this.maximizedReference.value!=""){var a=$$(this.maximizedReference.value);
if(a&&a.length>0){this.makeFullScreen(a[0])
}}},addBehavior:function(a){if(this.isWysiwyg20Content(a)){this.addWysiwyg20ContentButton(a)
}else{if(this.isWysiwyg10Content(a)){this.addWysiwyg10ContentButton(a)
}else{if(this.isWikiContent(a)){this.addWikiContentButton(a)
}else{if(this.isWysiwyg20Field(a)){this.addWysiwyg20FieldButton(a)
}else{if(this.isWikiField(a)){this.addWikiFieldButton(a)
}else{if(this.isWysiwyg10Field(a)){this.addWysiwyg10FieldButton(a)
}else{this.addElementButton(a)
}}}}}}},addWysiwyg20Listener:function(){document.observe("xwiki:wysiwyg:created",this.wysiwyg20Created.bindAsEventListener(this))
},wysiwyg20Created:function(b){var a=$(b.memo.instance.getRichTextArea()).up(".xRichTextEditor");
this.addBehavior(a);
while(true){a=a.up();
if(!a){return
}else{if(a.previous(".fullScreenEditLinkContainer")){a.previous(".fullScreenEditLinkContainer").remove();
return
}}}},isWikiContent:function(a){return a.name=="content"&&a.visible()
},isWysiwyg10Content:function(a){return a.name=="content"&&(Prototype.Browser.IE?a.previous(".mceEditorContainer"):a.next(".mceEditorContainer"))
},isWysiwyg20Content:function(a){return a.hasClassName("xRichTextEditor")&&a.up("div[id^=content_container]")
},isWikiField:function(a){return a.visible()
},isWysiwyg10Field:function(a){return !a.visible()&&a.name!="content"&&(Prototype.Browser.IE?a.previous(".mceEditorContainer"):a.next(".mceEditorContainer"))
},isWysiwyg20Field:function(a){return a.hasClassName("xRichTextEditor")&&!a.up("div[id^=content_container]")
},addWikiContentButton:function(a){a._toolbar=$(document.body).down(".leftmenu2");
if(a._toolbar){a._toolbar.insert({top:this.createOpenButton(a)})
}else{this.addWikiFieldButton(a)
}},addWysiwyg10ContentButton:function(e){var b=(Prototype.Browser.IE?e.previous(".mceEditorContainer"):e.next(".mceEditorContainer"));
if(!b){return false
}var d=b.down(".mceToolbar");
if(!d){return false
}var a=new Element("span",{"class":"mce_editor_fullscreentoolbar"});
var c=new Element("a",{"class":"mceButtonNormal"});
a.insert(new Element("img",{"class":"mceSeparatorLine",height:15,width:1,src:d.down("img.mceSeparatorLine").src}));
a.insert(c.insert(this.createOpenButton(b)));
d.insert(a);
b._toolbar=d;
return true
},addWysiwyg20ContentButton:function(b){var a=b.down(".gwt-MenuBar");
if(!a){if(!b._x_fullScreenLoader){b._x_fullScreenLoader_iterations=0;
b._x_fullScreenLoader=new PeriodicalExecuter(function(c){if(c._x_fullScreenLoader_iteration>100){c._x_fullScreenLoader.stop();
c._x_fullScreenLoader=false;
return
}c._x_fullScreenLoader_iteration++;
this.addWysiwyg20ContentButton(c)
}.bind(this,b),0.2)
}return false
}a.insert({top:this.createOpenButton(b)});
b._toolbar=a;
if(b._x_fullScreenLoader){b._x_fullScreenLoader.stop();
b._x_fullScreenLoader=false
}return true
},addElementButton:function(a){Element.insert(a,{before:this.createOpenLink(a)})
},addWikiFieldButton:function(a){Element.insert(a,{before:this.createOpenLink(a)})
},addWysiwyg10FieldButton:function(a){this.addWysiwyg10ContentButton(a)
},addWysiwyg20FieldButton:function(a){this.addWysiwyg20ContentButton(a)
},createOpenButton:function(b){var a=new Element("img",{"class":"fullScreenEditButton",title:"$msg.get('core.editors.fullscreen.editFullScreen')",alt:"$msg.get('core.editors.fullscreen.editFullScreen')",src:"$xwiki.getSkinFile('icons/silk/arrow_out.gif')"});
a.observe("click",this.makeFullScreen.bind(this,b));
a.observe("mousedown",this.preventDrag.bindAsEventListener(this));
b._x_fullScreenActivator=a;
a._x_maximizedElement=b;
return a
},createOpenLink:function(b){var c=new Element("div",{"class":"fullScreenEditLinkContainer"});
var a=new Element("a",{"class":"fullScreenEditLink",title:"$msg.get('core.editors.fullscreen.editFullScreen')"});
a.update("${msg.get('core.editors.fullscreen.editFullScreen')} &raquo;");
a.observe("click",this.makeFullScreen.bind(this,b));
c.update(a);
b._x_fullScreenActivator=a;
a._x_maximizedElement=b;
return c
},createCloseButtons:function(){this.closeButton=new Element("img",{"class":"fullScreenCloseButton",title:"$msg.get('core.editors.fullscreen.exitFullScreen')",alt:"$msg.get('core.editors.fullscreen.exitFullScreen')",src:"$xwiki.getSkinFile('icons/silk/arrow_in.gif')"});
this.closeButton.observe("click",this.closeFullScreen.bind(this));
this.closeButton.observe("mousedown",this.preventDrag.bindAsEventListener(this));
this.closeButton.hide();
this.actionCloseButton=new Element("input",{type:"button","class":"button",value:"$msg.get('core.editors.fullscreen.exitFullScreen')"});
this.actionCloseButtonWrapper=new Element("span",{"class":"buttonwrapper"});
this.actionCloseButtonWrapper.update(this.actionCloseButton);
this.actionCloseButton.observe("click",this.closeFullScreen.bind(this));
this.actionCloseButtonWrapper.hide();
this.buttons.down(".buttons").insert({top:this.actionCloseButtonWrapper})
},makeFullScreen:function(d){document.fire("xwiki:fullscreen:enter",{target:d});
if(this.maximizedReference){if(d.id){this.maximizedReference.value=d.tagName+"[id='"+d.id+"']"
}else{if(d.name){this.maximizedReference.value=d.tagName+"[name='"+d.name+"']"
}else{if(d.className){this.maximizedReference.value=d.tagName+"."+d.className
}}}}this.maximized=d;
if(typeof d.setSelectionRange=="function"){var g=d.selectionStart;
var i=d.selectionEnd;
var b=d.scrollTop
}d._originalStyle={width:d.style.width,height:d.style.height};
if(d.hasClassName("xRichTextEditor")){var c=d.down(".gwt-RichTextArea");
c._originalStyle={width:c.style.width,height:c.style.height}
}else{if(d.hasClassName("mceEditorContainer")){var c=d.down(".mceEditorIframe");
c._originalStyle={width:c.style.width,height:c.style.height};
var f=d.down(".mceEditorSource");
f._originalStyle={width:f.style.width,height:f.style.height}
}}var a=d.up();
a.addClassName("fullScreenWrapper");
if(d._toolbar){if(d._toolbar.hasClassName("leftmenu2")){a.insert({top:d._toolbar.replace(this.toolbarPlaceholder)})
}d._x_fullScreenActivator.replace(this.closeButton)
}a.insert(this.buttons.replace(this.buttonsPlaceholder).show());
var h=d.up();
d._x_fullScreenActivator.hide();
while(h!=document.body){h._originalStyle={overflow:h.style.overflow,position:h.style.position,width:h.style.width,height:h.style.height,left:h.style.left,right:h.style.right,top:h.style.top,bottom:h.style.bottom,padding:h.style.padding,margin:h.style.margin};
h.setStyle({overflow:"visible",position:"absolute",width:"100%",height:"100%",left:0,top:0,right:0,bottom:0,padding:0,margin:0});
h.siblings().each(function(j){j._originalDisplay=j.style.display;
j.setStyle({display:"none"})
});
h=h.up()
}document.body._originalStyle={overflow:h.style.overflow,width:h.style.width,height:h.style.height};
var e=$(document.body).up();
e._originalStyle={overflow:e.style.overflow,width:e.style.width,height:e.style.height};
$(document.body).setStyle({overflow:"hidden",width:"100%",height:"100%"});
e.setStyle({overflow:"hidden",width:"100%",height:"100%"});
this.resizeListener=this.resizeTextArea.bind(this,d);
Event.observe(window,"resize",this.resizeListener);
this.closeButton.show();
this.actionCloseButtonWrapper.show();
this.resizeTextArea(d);
if(d._toolbar){d._toolbar.viewportOffset()
}if(typeof d.setSelectionRange=="function"){d.scrollTop=b;
d.selectionStart=g;
d.selectionEnd=i
}document.fire("xwiki:fullscreen:entered",{target:d})
},closeFullScreen:function(){var d=this.maximized;
document.fire("xwiki:fullscreen:exit",{target:d});
if(typeof d.setSelectionRange=="function"){var g=d.selectionStart;
var j=d.selectionEnd;
var a=d.scrollTop
}this.closeButton.hide();
this.actionCloseButtonWrapper.hide();
Event.stopObserving(window,"resize",this.resizeListener);
d.up().removeClassName("fullScreenWrapper");
if(d.hasClassName("xRichTextEditor")){var b=d.down(".gwt-RichTextArea");
b.setStyle(b._originalStyle)
}else{if(d.hasClassName("mceEditorContainer")){var b=d.down(".mceEditorIframe");
b.setStyle(b._originalStyle);
var e=d.down(".mceEditorSource");
e.setStyle(e._originalStyle)
}}var h=d.up();
var f=[];
while(h!=document.body){f.push(h);
h=h.up()
}var c=f.length;
while(c--){h=f[c];
h.setStyle(h._originalStyle);
h.siblings().each(function(i){i.style.display=i._originalDisplay
})
}document.body.setStyle(document.body._originalStyle);
$(document.body).up().setStyle($(document.body).up()._originalStyle);
this.buttonsPlaceholder.replace(this.buttons);
if(this.buttons._x_isCustom){this.buttons.hide()
}if(d._toolbar){if(d._toolbar.hasClassName("leftmenu2")){this.toolbarPlaceholder.replace(d._toolbar)
}this.closeButton.replace(d._x_fullScreenActivator)
}if(Prototype.Browser.IE){setTimeout(function(){d._x_fullScreenActivator.show();
this.setStyle(this._originalStyle)
}.bind(d),500)
}else{d._x_fullScreenActivator.show();
d.setStyle(d._originalStyle)
}delete this.maximized;
if(this.maximizedReference){this.maximizedReference.value=""
}if(typeof d.setSelectionRange=="function"){d.scrollTop=a;
d.selectionStart=g;
d.selectionEnd=j
}document.fire("xwiki:fullscreen:exited",{target:d})
},resizeTextArea:function(b){if(!this.maximized){return
}var a=document.viewport.getHeight();
var c=document.viewport.getWidth();
if(c<=0){c=document.body.clientWidth;
a=document.body.clientHeight
}c=c-this.margin;
a=a-b.positionedOffset().top-this.margin-this.buttons.getHeight();
b.setStyle({width:c+"px",height:a+"px"});
if(b.hasClassName("xRichTextEditor")){b.down(".gwt-RichTextArea").setStyle({width:c+"px",height:a-b.down(".xToolbar").getHeight()-b.down(".gwt-MenuBar").getHeight()+"px"})
}else{if(b.hasClassName("mceEditorContainer")){b.down(".mceEditorIframe").setStyle({width:c+"px",height:a-b._toolbar.getHeight()+"px"});
b.down(".mceEditorSource").setStyle({width:c+"px",height:a-b._toolbar.getHeight()+"px"})
}}document.fire("xwiki:fullscreen:resized",{target:b})
},preventDrag:function(a){a.stop()
}});
document.observe("xwiki:dom:loaded",function(){new XWiki.widgets.FullScreen()
});