(function($){"use strict";var console=window.console?window.console:{log:$.noop,error:function(msg){$.error(msg);}};var supportsProp=(('prop'in $.fn)&&('removeProp'in $.fn));function Wysiwyg(){this.controls={bold:{groupIndex:0,visible:true,tags:["b","strong"],css:{fontWeight:"bold"},tooltip:"Bold",hotkey:{"ctrl":1,"key":66}},copy:{groupIndex:8,visible:false,tooltip:"Copy"},createLink:{groupIndex:6,visible:true,exec:function(){var self=this;if($.wysiwyg.controls&&$.wysiwyg.controls.link){$.wysiwyg.controls.link.init(this);}else if($.wysiwyg.autoload){$.wysiwyg.autoload.control("wysiwyg.link.js",function(){self.controls.createLink.exec.apply(self);});}else{console.error("$.wysiwyg.controls.link not defined. You need to include wysiwyg.link.js file");}},tags:["a"],tooltip:"Create link"},cut:{groupIndex:8,visible:false,tooltip:"Cut"},decreaseFontSize:{groupIndex:9,visible:false,tags:["small"],tooltip:"Decrease font size",exec:function(){this.decreaseFontSize();}},h1:{groupIndex:7,visible:true,className:"h1",command:($.browser.msie||$.browser.safari)?"FormatBlock":"heading","arguments":($.browser.msie||$.browser.safari)?"<h1>":"h1",tags:["h1"],tooltip:"Header 1"},h2:{groupIndex:7,visible:true,className:"h2",command:($.browser.msie||$.browser.safari)?"FormatBlock":"heading","arguments":($.browser.msie||$.browser.safari)?"<h2>":"h2",tags:["h2"],tooltip:"Header 2"},h3:{groupIndex:7,visible:true,className:"h3",command:($.browser.msie||$.browser.safari)?"FormatBlock":"heading","arguments":($.browser.msie||$.browser.safari)?"<h3>":"h3",tags:["h3"],tooltip:"Header 3"},highlight:{tooltip:"Highlight",className:"highlight",groupIndex:1,visible:false,css:{backgroundColor:"rgb(255, 255, 102)"},exec:function(){var command,node,selection,args;if($.browser.msie||$.browser.safari){command="backcolor";}else{command="hilitecolor";}
if($.browser.msie){node=this.getInternalRange().parentElement();}else{selection=this.getInternalSelection();node=selection.extentNode||selection.focusNode;while(node.style===undefined){node=node.parentNode;if(node.tagName&&node.tagName.toLowerCase()==="body"){return;}}}
if(node.style.backgroundColor==="rgb(255, 255, 102)"||node.style.backgroundColor==="#ffff66"){args="#ffffff";}else{args="#ffff66";}
this.editorDoc.execCommand(command,false,args);}},html:{groupIndex:10,visible:false,exec:function(){var elementHeight;if(this.options.resizeOptions&&$.fn.resizable){elementHeight=this.element.height();}
if(this.viewHTML){this.setContent(this.original.value);$(this.original).hide();this.editor.show();if(this.options.resizeOptions&&$.fn.resizable){if(elementHeight===this.element.height()){this.element.height(elementHeight+this.editor.height());}
this.element.resizable($.extend(true,{alsoResize:this.editor},this.options.resizeOptions));}
this.ui.toolbar.find("li").each(function(){var li=$(this);if(li.hasClass("html")){li.removeClass("active");}else{li.removeClass('disabled');}});}else{this.saveContent();$(this.original).css({width:this.element.outerWidth()-6,height:this.element.height()-this.ui.toolbar.height()-6,resize:"none"}).show();this.editor.hide();if(this.options.resizeOptions&&$.fn.resizable){if(elementHeight===this.element.height()){this.element.height(this.ui.toolbar.height());}
this.element.resizable("destroy");}
this.ui.toolbar.find("li").each(function(){var li=$(this);if(li.hasClass("html")){li.addClass("active");}else{if(false===li.hasClass("fullscreen")){li.removeClass("active").addClass('disabled');}}});}
this.viewHTML=!(this.viewHTML);},tooltip:"View source code"},increaseFontSize:{groupIndex:9,visible:false,tags:["big"],tooltip:"Increase font size",exec:function(){this.increaseFontSize();}},indent:{groupIndex:2,visible:true,tooltip:"Indent"},insertHorizontalRule:{groupIndex:6,visible:true,tags:["hr"],tooltip:"Insert Horizontal Rule"},insertImage:{groupIndex:6,visible:true,exec:function(){var self=this;if($.wysiwyg.controls&&$.wysiwyg.controls.image){$.wysiwyg.controls.image.init(this);}else if($.wysiwyg.autoload){$.wysiwyg.autoload.control("wysiwyg.image.js",function(){self.controls.insertImage.exec.apply(self);});}else{console.error("$.wysiwyg.controls.image not defined. You need to include wysiwyg.image.js file");}},tags:["img"],tooltip:"Insert image"},insertOrderedList:{groupIndex:5,visible:true,tags:["ol"],tooltip:"Insert Ordered List"},insertTable:{groupIndex:6,visible:true,exec:function(){var self=this;if($.wysiwyg.controls&&$.wysiwyg.controls.table){$.wysiwyg.controls.table(this);}else if($.wysiwyg.autoload){$.wysiwyg.autoload.control("wysiwyg.table.js",function(){self.controls.insertTable.exec.apply(self);});}else{console.error("$.wysiwyg.controls.table not defined. You need to include wysiwyg.table.js file");}},tags:["table"],tooltip:"Insert table"},insertUnorderedList:{groupIndex:5,visible:true,tags:["ul"],tooltip:"Insert Unordered List"},italic:{groupIndex:0,visible:true,tags:["i","em"],css:{fontStyle:"italic"},tooltip:"Italic",hotkey:{"ctrl":1,"key":73}},justifyCenter:{groupIndex:1,visible:true,tags:["center"],css:{textAlign:"center"},tooltip:"Justify Center"},justifyFull:{groupIndex:1,visible:true,css:{textAlign:"justify"},tooltip:"Justify Full"},justifyLeft:{visible:true,groupIndex:1,css:{textAlign:"left"},tooltip:"Justify Left"},justifyRight:{groupIndex:1,visible:true,css:{textAlign:"right"},tooltip:"Justify Right"},ltr:{groupIndex:10,visible:false,exec:function(){var p=this.dom.getElement("p");if(!p){return false;}
$(p).attr("dir","ltr");return true;},tooltip:"Left to Right"},outdent:{groupIndex:2,visible:true,tooltip:"Outdent"},paragraph:{groupIndex:7,visible:false,className:"paragraph",command:"FormatBlock","arguments":($.browser.msie||$.browser.safari)?"<p>":"p",tags:["p"],tooltip:"Paragraph"},paste:{groupIndex:8,visible:false,tooltip:"Paste"},redo:{groupIndex:4,visible:true,tooltip:"Redo"},removeFormat:{groupIndex:10,visible:true,exec:function(){this.removeFormat();},tooltip:"Remove formatting"},rtl:{groupIndex:10,visible:false,exec:function(){var p=this.dom.getElement("p");if(!p){return false;}
$(p).attr("dir","rtl");return true;},tooltip:"Right to Left"},strikeThrough:{groupIndex:0,visible:true,tags:["s","strike"],css:{textDecoration:"line-through"},tooltip:"Strike-through"},subscript:{groupIndex:3,visible:true,tags:["sub"],tooltip:"Subscript"},superscript:{groupIndex:3,visible:true,tags:["sup"],tooltip:"Superscript"},underline:{groupIndex:0,visible:true,tags:["u"],css:{textDecoration:"underline"},tooltip:"Underline",hotkey:{"ctrl":1,"key":85}},undo:{groupIndex:4,visible:true,tooltip:"Undo"},code:{visible:true,groupIndex:6,tooltip:"Code snippet",exec:function(){var range=this.getInternalRange(),common=$(range.commonAncestorContainer),$nodeName=range.commonAncestorContainer.nodeName.toLowerCase();if(common.parent("code").length){common.unwrap();}else{if($nodeName!=="body"){common.wrap("<code/>");}}}}};this.defaults={html:'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body style="margin: 3px;">INITIAL_CONTENT</body></html>',debug:false,controls:{},css:{},events:{},autoGrow:false,autoSave:true,brIE:true,formHeight:270,formWidth:440,iFrameClass:null,initialContent:"<p>Initial content</p>",maxHeight:10000,maxLength:0,messages:{nonSelection:"Select the text you wish to link"},toolbarHtml:'<ul role="menu" class="toolbar"></ul>',removeHeadings:false,replaceDivWithP:false,resizeOptions:false,rmUnusedControls:false,rmUnwantedBr:true,tableFiller:"Lorem ipsum",initialMinHeight:null,controlImage:{forceRelativeUrls:false},controlLink:{forceRelativeUrls:false},plugins:{autoload:false,i18n:false,rmFormat:{rmMsWordMarkup:false}}};this.availableControlProperties=["arguments","callback","className","command","css","custom","exec","groupIndex","hotkey","icon","tags","tooltip","visible"];this.editor=null;this.editorDoc=null;this.element=null;this.options={};this.original=null;this.savedRange=null;this.timers=[];this.validKeyCodes=[8,9,13,16,17,18,19,20,27,33,34,35,36,37,38,39,40,45,46];this.isDestroyed=false;this.dom={ie:{parent:null},w3c:{parent:null}};this.dom.parent=this;this.dom.ie.parent=this.dom;this.dom.w3c.parent=this.dom;this.ui={};this.ui.self=this;this.ui.toolbar=null;this.ui.initialHeight=null;this.dom.getAncestor=function(element,filterTagName){filterTagName=filterTagName.toLowerCase();while(element&&"body"!==element.tagName.toLowerCase()){if(filterTagName===element.tagName.toLowerCase()){return element;}
element=element.parentNode;}
return null;};this.dom.getElement=function(filterTagName){var dom=this;if(window.getSelection){return dom.w3c.getElement(filterTagName);}else{return dom.ie.getElement(filterTagName);}};this.dom.ie.getElement=function(filterTagName){var dom=this.parent,selection=dom.parent.getInternalSelection(),range=selection.createRange(),element;if("Control"===selection.type){if(1===range.length){element=range.item(0);}else{return null;}}else{element=range.parentElement();}
return dom.getAncestor(element,filterTagName);};this.dom.w3c.getElement=function(filterTagName){var dom=this.parent,range=dom.parent.getInternalRange(),element;if(!range){return null;}
element=range.commonAncestorContainer;if(3===element.nodeType){element=element.parentNode;}
if(element===range.startContainer){element=element.childNodes[range.startOffset];}
return dom.getAncestor(element,filterTagName);};this.ui.addHoverClass=function(){$(this).addClass("wysiwyg-button-hover");};this.ui.appendControls=function(){var ui=this,self=this.self,controls=self.parseControls(),hasVisibleControls=true,groups=[],controlsByGroup={},i,currentGroupIndex,iterateGroup=function(controlName,control){if(control.groupIndex&&currentGroupIndex!==control.groupIndex){currentGroupIndex=control.groupIndex;hasVisibleControls=false;}
if(!control.visible){return;}
if(!hasVisibleControls){ui.appendItemSeparator();hasVisibleControls=true;}
if(control.custom){ui.appendItemCustom(controlName,control);}else{ui.appendItem(controlName,control);}};$.each(controls,function(name,c){var index="empty";if(undefined!==c.groupIndex){if(""===c.groupIndex){index="empty";}else{index=c.groupIndex;}}
if(undefined===controlsByGroup[index]){groups.push(index);controlsByGroup[index]={};}
controlsByGroup[index][name]=c;});groups.sort(function(a,b){if("number"===typeof(a)&&typeof(a)===typeof(b)){return(a-b);}else{a=a.toString();b=b.toString();if(a>b){return 1;}
if(a===b){return 0;}
return-1;}});if(0<groups.length){currentGroupIndex=groups[0];}
for(i=0;i<groups.length;i+=1){$.each(controlsByGroup[groups[i]],iterateGroup);}};this.ui.appendItem=function(name,control){var self=this.self,className=control.className||control.command||name||"empty",tooltip=control.tooltip||control.command||name||"";return $('<li role="menuitem" unselectable="on">'+(className)+"</li>").addClass(className).attr("title",tooltip).hover(this.addHoverClass,this.removeHoverClass).click(function(){if($(this).hasClass("disabled")){return false;}
self.triggerControl.apply(self,[name,control]);this.blur();self.ui.returnRange();self.ui.focus();return true;}).appendTo(self.ui.toolbar);};this.ui.appendItemCustom=function(name,control){var self=this.self,tooltip=control.tooltip||control.command||name||"";if(control.callback){$(window).bind("trigger-"+name+".wysiwyg",control.callback);}
return $('<li role="menuitem" unselectable="on" style="background: url(\''+control.icon+'\') no-repeat;"></li>').addClass("custom-command-"+name).addClass("wysiwyg-custom-command").addClass(name).attr("title",tooltip).hover(this.addHoverClass,this.removeHoverClass).click(function(){if($(this).hasClass("disabled")){return false;}
self.triggerControl.apply(self,[name,control]);this.blur();self.ui.returnRange();self.ui.focus();self.triggerControlCallback(name);return true;}).appendTo(self.ui.toolbar);};this.ui.appendItemSeparator=function(){var self=this.self;return $('<li role="separator" class="separator"></li>').appendTo(self.ui.toolbar);};this.autoSaveFunction=function(){this.saveContent();};this.ui.checkTargets=function(element){var self=this.self;$.each(self.options.controls,function(name,control){var className=control.className||control.command||name||"empty",tags,elm,css,el,checkActiveStatus=function(cssProperty,cssValue){var handler;if("function"===typeof(cssValue)){handler=cssValue;if(handler(el.css(cssProperty).toString().toLowerCase(),self)){self.ui.toolbar.find("."+className).addClass("active");}}else{if(el.css(cssProperty).toString().toLowerCase()===cssValue){self.ui.toolbar.find("."+className).addClass("active");}}};if("fullscreen"!==className){self.ui.toolbar.find("."+className).removeClass("active");}
if(control.tags||(control.options&&control.options.tags)){tags=control.tags||(control.options&&control.options.tags);elm=element;while(elm){if(elm.nodeType!==1){break;}
if($.inArray(elm.tagName.toLowerCase(),tags)!==-1){self.ui.toolbar.find("."+className).addClass("active");}
elm=elm.parentNode;}}
if(control.css||(control.options&&control.options.css)){css=control.css||(control.options&&control.options.css);el=$(element);while(el){if(el[0].nodeType!==1){break;}
$.each(css,checkActiveStatus);el=el.parent();}}});};this.ui.designMode=function(){var attempts=3,self=this.self,runner;runner=function(attempts){if("on"===self.editorDoc.designMode){if(self.timers.designMode){window.clearTimeout(self.timers.designMode);}
if(self.innerDocument()!==self.editorDoc){self.ui.initFrame();}
return;}
try{self.editorDoc.designMode="on";}catch(e){}
attempts-=1;if(attempts>0){self.timers.designMode=window.setTimeout(function(){runner(attempts);},100);}};runner(attempts);};this.destroy=function(){this.isDestroyed=true;var i,$form=this.element.closest("form");for(i=0;i<this.timers.length;i+=1){window.clearTimeout(this.timers[i]);}
$form.unbind(".wysiwyg");this.element.remove();$.removeData(this.original,"wysiwyg");$(this.original).show();return this;};this.getRangeText=function(){var r=this.getInternalRange();if(r.toString){r=r.toString();}else if(r.text){r=r.text;}
return r;};this.execute=function(command,arg){if(typeof(arg)==="undefined"){arg=null;}
this.editorDoc.execCommand(command,false,arg);};this.extendOptions=function(options){var controls={};if("object"===typeof options.controls){controls=options.controls;delete options.controls;}
options=$.extend(true,{},this.defaults,options);options.controls=$.extend(true,{},controls,this.controls,controls);if(options.rmUnusedControls){$.each(options.controls,function(controlName){if(!controls[controlName]){delete options.controls[controlName];}});}
return options;};this.ui.focus=function(){var self=this.self;self.editor.get(0).contentWindow.focus();return self;};this.ui.returnRange=function(){var self=this.self,sel;if(self.savedRange!==null){if(window.getSelection){sel=window.getSelection();if(sel.rangeCount>0){sel.removeAllRanges();}
try{sel.addRange(self.savedRange);}catch(e){console.error(e);}}else if(window.document.createRange){window.getSelection().addRange(self.savedRange);}else if(window.document.selection){self.savedRange.select();}
self.savedRange=null;}};this.increaseFontSize=function(){if($.browser.mozilla||$.browser.opera){this.editorDoc.execCommand('increaseFontSize',false,null);}else if($.browser.safari){var newNode=this.editorDoc.createElement('big');this.getInternalRange().surroundContents(newNode);}else{console.error("Internet Explorer?");}};this.decreaseFontSize=function(){if($.browser.mozilla||$.browser.opera){this.editorDoc.execCommand('decreaseFontSize',false,null);}else if($.browser.safari){var newNode=this.editorDoc.createElement('small');this.getInternalRange().surroundContents(newNode);}else{console.error("Internet Explorer?");}};this.getContent=function(){return this.events.filter('getContent',this.editorDoc.body.innerHTML);};this.events={_events:{},bind:function(eventName,callback){if(typeof(this._events.eventName)!=="object"){this._events[eventName]=[];}
this._events[eventName].push(callback);},trigger:function(eventName,args){if(typeof(this._events.eventName)==="object"){var editor=this.editor;$.each(this._events[eventName],function(k,v){if(typeof(v)==="function"){v.apply(editor,args);}});}},filter:function(eventName,originalText){if(typeof(this._events[eventName])==="object"){var editor=this.editor,args=Array.prototype.slice.call(arguments,1);$.each(this._events[eventName],function(k,v){if(typeof(v)==="function"){originalText=v.apply(editor,args);}});}
return originalText;}};this.getElementByAttributeValue=function(tagName,attributeName,attributeValue){var i,value,elements=this.editorDoc.getElementsByTagName(tagName);for(i=0;i<elements.length;i+=1){value=elements[i].getAttribute(attributeName);if($.browser.msie){value=value.substr(value.length-attributeValue.length);}
if(value===attributeValue){return elements[i];}}
return false;};this.getInternalRange=function(){var selection=this.getInternalSelection();if(!selection){return null;}
if(selection.rangeCount&&selection.rangeCount>0){return selection.getRangeAt(0);}else if(selection.createRange){return selection.createRange();}
return null;};this.getInternalSelection=function(){if(this.editor.get(0).contentWindow){if(this.editor.get(0).contentWindow.getSelection){return this.editor.get(0).contentWindow.getSelection();}
if(this.editor.get(0).contentWindow.selection){return this.editor.get(0).contentWindow.selection;}}
if(this.editorDoc.getSelection){return this.editorDoc.getSelection();}
if(this.editorDoc.selection){return this.editorDoc.selection;}
return null;};this.getRange=function(){var selection=this.getSelection();if(!selection){return null;}
if(selection.rangeCount&&selection.rangeCount>0){selection.getRangeAt(0);}else if(selection.createRange){return selection.createRange();}
return null;};this.getSelection=function(){return(window.getSelection)?window.getSelection():window.document.selection;};this.ui.grow=function(){var self=this.self,innerBody=$(self.editorDoc.body),innerHeight=$.browser.msie?innerBody[0].scrollHeight:innerBody.height()+2+20,minHeight=self.ui.initialHeight,height=Math.max(innerHeight,minHeight);height=Math.min(height,self.options.maxHeight);self.editor.attr("scrolling",height<self.options.maxHeight?"no":"auto");innerBody.css("overflow",height<self.options.maxHeight?"hidden":"");self.editor.get(0).height=height;return self;};this.init=function(element,options){var self=this,$form=$(element).closest("form"),newX=element.width||element.clientWidth||0,newY=element.height||element.clientHeight||0;this.options=this.extendOptions(options);this.original=element;this.ui.toolbar=$(this.options.toolbarHtml);if($.browser.msie&&parseInt($.browser.version,10)<8){this.options.autoGrow=false;}
if(newX===0&&element.cols){newX=(element.cols*8)+21;}
if(newY===0&&element.rows){newY=(element.rows*16)+16;}
this.editor=$(window.location.protocol==="https:"?'<iframe src="javascript:false;"></iframe>':"<iframe></iframe>").attr("frameborder","0");if(this.options.iFrameClass){this.editor.addClass(this.options.iFrameClass);}else{this.editor.css({minHeight:(newY-6).toString()+"px",width:(newX>50)?(newX-8).toString()+"px":""});if($.browser.msie&&parseInt($.browser.version,10)<7){this.editor.css("height",newY.toString()+"px");}}
this.editor.attr("tabindex",$(element).attr("tabindex"));this.element=$("<div/>").addClass("wysiwyg");if(!this.options.iFrameClass){this.element.css({width:(newX>0)?newX.toString()+"px":"100%"});}
$(element).hide().before(this.element);this.viewHTML=false;this.initialContent=$(element).val();this.ui.initFrame();if(this.options.resizeOptions&&$.fn.resizable){this.element.resizable($.extend(true,{alsoResize:this.editor},this.options.resizeOptions));}
if(this.options.autoSave){$form.bind("submit.wysiwyg",function(){self.autoSaveFunction();});}
$form.bind("reset.wysiwyg",function(){self.resetFunction();});};this.ui.initFrame=function(){var self=this.self,stylesheet,growHandler,saveHandler;self.ui.appendControls();self.element.append(self.ui.toolbar).append($("<div><!-- --></div>").css({clear:"both"})).append(self.editor);self.editorDoc=self.innerDocument();if(self.isDestroyed){return null;}
self.ui.designMode();self.editorDoc.open();self.editorDoc.write(self.options.html.replace(/INITIAL_CONTENT/,function(){return self.wrapInitialContent();}));self.editorDoc.close();$.wysiwyg.plugin.bind(self);$(self.editorDoc).trigger("initFrame.wysiwyg");$(self.editorDoc).bind("click.wysiwyg",function(event){self.ui.checkTargets(event.target?event.target:event.srcElement);});$(self.original).focus(function(){if($(this).filter(":visible")){return;}
self.ui.focus();});$(self.editorDoc).keydown(function(event){var emptyContentRegex;if(event.keyCode===8){emptyContentRegex=/^<([\w]+)[^>]*>(<br\/?>)?<\/\1>$/;if(emptyContentRegex.test(self.getContent())){event.stopPropagation();return false;}}
return true;});if(!$.browser.msie){$(self.editorDoc).keydown(function(event){var controlName;if(event.ctrlKey||event.metaKey){for(controlName in self.controls){if(self.controls[controlName].hotkey&&self.controls[controlName].hotkey.ctrl){if(event.keyCode===self.controls[controlName].hotkey.key){self.triggerControl.apply(self,[controlName,self.controls[controlName]]);return false;}}}}
return true;});}else if(self.options.brIE){$(self.editorDoc).keydown(function(event){if(event.keyCode===13){var rng=self.getRange();rng.pasteHTML("<br/>");rng.collapse(false);rng.select();return false;}
return true;});}
if(self.options.plugins.rmFormat.rmMsWordMarkup){$(self.editorDoc).bind("keyup.wysiwyg",function(event){if(event.ctrlKey||event.metaKey){if(86===event.keyCode){if($.wysiwyg.rmFormat){if("object"===typeof(self.options.plugins.rmFormat.rmMsWordMarkup)){$.wysiwyg.rmFormat.run(self,{rules:{msWordMarkup:self.options.plugins.rmFormat.rmMsWordMarkup}});}else{$.wysiwyg.rmFormat.run(self,{rules:{msWordMarkup:{enabled:true}}});}}}}});}
if(self.options.autoSave){$(self.editorDoc).keydown(function(){self.autoSaveFunction();}).keyup(function(){self.autoSaveFunction();}).mousedown(function(){self.autoSaveFunction();}).bind($.support.noCloneEvent?"input.wysiwyg":"paste.wysiwyg",function(){self.autoSaveFunction();});}
if(self.options.autoGrow){if(self.options.initialMinHeight!==null){self.ui.initialHeight=self.options.initialMinHeight;}else{self.ui.initialHeight=$(self.editorDoc).height();}
$(self.editorDoc.body).css("border","1px solid white");growHandler=function(){self.ui.grow();};$(self.editorDoc).keyup(growHandler);$(self.editorDoc).bind("editorRefresh.wysiwyg",growHandler);self.ui.grow();}
if(self.options.css){if(String===self.options.css.constructor){if($.browser.msie){stylesheet=self.editorDoc.createStyleSheet(self.options.css);$(stylesheet).attr({"media":"all"});}else{stylesheet=$("<link/>").attr({"href":self.options.css,"media":"all","rel":"stylesheet","type":"text/css"});$(self.editorDoc).find("head").append(stylesheet);}}else{self.timers.initFrame_Css=window.setTimeout(function(){$(self.editorDoc.body).css(self.options.css);},0);}}
if(self.initialContent.length===0){if("function"===typeof(self.options.initialContent)){self.setContent(self.options.initialContent());}else{self.setContent(self.options.initialContent);}}
if(self.options.maxLength>0){$(self.editorDoc).keydown(function(event){if($(self.editorDoc).text().length>=self.options.maxLength&&$.inArray(event.which,self.validKeyCodes)===-1){event.preventDefault();}});}
$.each(self.options.events,function(key,handler){$(self.editorDoc).bind(key+".wysiwyg",function(event){handler.apply(self.editorDoc,[event,self]);});});if($.browser.msie){$(self.editorDoc).bind("beforedeactivate.wysiwyg",function(){self.savedRange=self.getInternalRange();});}else{$(self.editorDoc).bind("blur.wysiwyg",function(){self.savedRange=self.getInternalRange();});}
$(self.editorDoc.body).addClass("wysiwyg");if(self.options.events&&self.options.events.save){saveHandler=self.options.events.save;$(self.editorDoc).bind("keyup.wysiwyg",saveHandler);$(self.editorDoc).bind("change.wysiwyg",saveHandler);if($.support.noCloneEvent){$(self.editorDoc).bind("input.wysiwyg",saveHandler);}else{$(self.editorDoc).bind("paste.wysiwyg",saveHandler);$(self.editorDoc).bind("cut.wysiwyg",saveHandler);}}
if(self.options.xhtml5&&self.options.unicode){var replacements={ne:8800,le:8804,para:182,xi:958,darr:8595,nu:957,oacute:243,Uacute:218,omega:969,prime:8242,pound:163,igrave:236,thorn:254,forall:8704,emsp:8195,lowast:8727,brvbar:166,alefsym:8501,nbsp:160,delta:948,clubs:9827,lArr:8656,Omega:937,Auml:196,cedil:184,and:8743,plusmn:177,ge:8805,raquo:187,uml:168,equiv:8801,laquo:171,rdquo:8221,Epsilon:917,divide:247,fnof:402,chi:967,Dagger:8225,iacute:237,rceil:8969,sigma:963,Oslash:216,acute:180,frac34:190,lrm:8206,upsih:978,Scaron:352,part:8706,exist:8707,nabla:8711,image:8465,prop:8733,zwj:8205,omicron:959,aacute:225,Yuml:376,Yacute:221,weierp:8472,rsquo:8217,otimes:8855,kappa:954,thetasym:977,harr:8596,Ouml:214,Iota:921,ograve:242,sdot:8901,copy:169,oplus:8853,acirc:226,sup:8835,zeta:950,Iacute:205,Oacute:211,crarr:8629,Nu:925,bdquo:8222,lsquo:8216,apos:39,Beta:914,eacute:233,egrave:232,lceil:8968,Kappa:922,piv:982,Ccedil:199,ldquo:8220,Xi:926,cent:162,uarr:8593,hellip:8230,Aacute:193,ensp:8194,sect:167,Ugrave:217,aelig:230,ordf:170,curren:164,sbquo:8218,macr:175,Phi:934,Eta:919,rho:961,Omicron:927,sup2:178,euro:8364,aring:229,Theta:920,mdash:8212,uuml:252,otilde:245,eta:951,uacute:250,rArr:8658,nsub:8836,agrave:224,notin:8713,ndash:8211,Psi:936,Ocirc:212,sube:8838,szlig:223,micro:181,not:172,sup1:185,middot:183,iota:953,ecirc:234,lsaquo:8249,thinsp:8201,sum:8721,ntilde:241,scaron:353,cap:8745,atilde:227,lang:10216,__replacement:65533,isin:8712,gamma:947,Euml:203,ang:8736,upsilon:965,Ntilde:209,hearts:9829,Alpha:913,Tau:932,spades:9824,dagger:8224,THORN:222,"int":8747,lambda:955,Eacute:201,Uuml:220,infin:8734,rlm:8207,Aring:197,ugrave:249,Egrave:200,Acirc:194,rsaquo:8250,ETH:208,oslash:248,alpha:945,Ograve:210,Prime:8243,mu:956,ni:8715,real:8476,bull:8226,beta:946,icirc:238,eth:240,prod:8719,larr:8592,ordm:186,perp:8869,Gamma:915,reg:174,ucirc:251,Pi:928,psi:968,tilde:732,asymp:8776,zwnj:8204,Agrave:192,deg:176,AElig:198,times:215,Delta:916,sim:8764,Otilde:213,Mu:924,uArr:8657,circ:710,theta:952,Rho:929,sup3:179,diams:9830,tau:964,Chi:935,frac14:188,oelig:339,shy:173,or:8744,dArr:8659,phi:966,iuml:239,Lambda:923,rfloor:8971,iexcl:161,cong:8773,ccedil:231,Icirc:206,frac12:189,loz:9674,rarr:8594,cup:8746,radic:8730,frasl:8260,euml:235,OElig:338,hArr:8660,Atilde:195,Upsilon:933,there4:8756,ouml:246,oline:8254,Ecirc:202,yacute:253,auml:228,permil:8240,sigmaf:962,iquest:191,empty:8709,pi:960,Ucirc:219,supe:8839,Igrave:204,yen:165,rang:10217,trade:8482,lfloor:8970,minus:8722,Zeta:918,sub:8834,epsilon:949,yuml:255,Sigma:931,Iuml:207,ocirc:244};self.events.bind("getContent",function(text){return text.replace(/&(?:amp;)?(?!amp|lt|gt|quot)([a-z][a-z0-9]*);/gi,function(str,p1){if(!replacements[p1]){p1=p1.toLowerCase();if(!replacements[p1]){p1="__replacement";}}
var num=replacements[p1];return String.fromCharCode(num);});});}};this.innerDocument=function(){var element=this.editor.get(0);if(element.nodeName.toLowerCase()==="iframe"){if(element.contentDocument){return element.contentDocument;}else if(element.contentWindow){return element.contentWindow.document;}
if(this.isDestroyed){return null;}
console.error("Unexpected error in innerDocument");}
return element;};this.insertHtml=function(szHTML){var img,range;if(!szHTML||szHTML.length===0){return this;}
if($.browser.msie){this.ui.focus();this.editorDoc.execCommand("insertImage",false,"#jwysiwyg#");img=this.getElementByAttributeValue("img","src","#jwysiwyg#");if(img){$(img).replaceWith(szHTML);}}else{if($.browser.mozilla){if(1===$(szHTML).length){range=this.getInternalRange();range.deleteContents();range.insertNode($(szHTML).get(0));}else{this.editorDoc.execCommand("insertHTML",false,szHTML);}}else{if(!this.editorDoc.execCommand("insertHTML",false,szHTML)){this.editor.focus();this.editorDoc.execCommand("insertHTML",false,szHTML);}}}
this.saveContent();return this;};this.parseControls=function(){var self=this;$.each(this.options.controls,function(controlName,control){$.each(control,function(propertyName){if(-1===$.inArray(propertyName,self.availableControlProperties)){throw controlName+'["'+propertyName+'"]: property "'+propertyName+'" not exists in Wysiwyg.availableControlProperties';}});});if(this.options.parseControls){return this.options.parseControls.call(this);}
return this.options.controls;};this.removeFormat=function(){if($.browser.msie){this.ui.focus();}
if(this.options.removeHeadings){this.editorDoc.execCommand("formatBlock",false,"<p>");}
this.editorDoc.execCommand("removeFormat",false,null);this.editorDoc.execCommand("unlink",false,null);if($.wysiwyg.rmFormat&&$.wysiwyg.rmFormat.enabled){if("object"===typeof(this.options.plugins.rmFormat.rmMsWordMarkup)){$.wysiwyg.rmFormat.run(this,{rules:{msWordMarkup:this.options.plugins.rmFormat.rmMsWordMarkup}});}else{$.wysiwyg.rmFormat.run(this,{rules:{msWordMarkup:{enabled:true}}});}}
return this;};this.ui.removeHoverClass=function(){$(this).removeClass("wysiwyg-button-hover");};this.resetFunction=function(){this.setContent(this.initialContent);};this.saveContent=function(){if(this.original){var content,newContent;content=this.getContent();if(this.options.rmUnwantedBr){content=content.replace(/<br\/?>$/,"");}
if(this.options.replaceDivWithP){newContent=$("<div/>").addClass("temp").append(content);newContent.children("div").each(function(){var element=$(this),p=element.find("p"),i;if(0===p.length){p=$("<p></p>");if(this.attributes.length>0){for(i=0;i<this.attributes.length;i+=1){p.attr(this.attributes[i].name,element.attr(this.attributes[i].name));}}
p.append(element.html());element.replaceWith(p);}});content=newContent.html();}
$(this.original).val(content);if(this.options.events&&this.options.events.save){this.options.events.save.call(this);}}
return this;};this.setContent=function(newContent){this.editorDoc.body.innerHTML=newContent;this.saveContent();return this;};this.triggerControl=function(name,control){var cmd=control.command||name,args=control["arguments"]||[];if(control.exec){control.exec.apply(this);}else{this.ui.focus();this.ui.withoutCss();try{this.editorDoc.execCommand(cmd,false,args);}catch(e){console.error(e);}}
if(this.options.autoSave){this.autoSaveFunction();}};this.triggerControlCallback=function(name){$(window).trigger("trigger-"+name+".wysiwyg",[this]);};this.ui.withoutCss=function(){var self=this.self;if($.browser.mozilla){try{self.editorDoc.execCommand("styleWithCSS",false,false);}catch(e){try{self.editorDoc.execCommand("useCSS",false,true);}catch(e2){}}}
return self;};this.wrapInitialContent=function(){var content=this.initialContent,found=content.match(/<\/?p>/gi);if(!found){return"<p>"+content+"</p>";}else{}
return content;};}
$.wysiwyg={messages:{noObject:"Something goes wrong, check object"},addControl:function(object,name,settings){return object.each(function(){var oWysiwyg=$(this).data("wysiwyg"),customControl={},toolbar;if(!oWysiwyg){return this;}
customControl[name]=$.extend(true,{visible:true,custom:true},settings);$.extend(true,oWysiwyg.options.controls,customControl);toolbar=$(oWysiwyg.options.toolbarHtml);oWysiwyg.ui.toolbar.replaceWith(toolbar);oWysiwyg.ui.toolbar=toolbar;oWysiwyg.ui.appendControls();});},clear:function(object){return object.each(function(){var oWysiwyg=$(this).data("wysiwyg");if(!oWysiwyg){return this;}
oWysiwyg.setContent("");});},console:console,destroy:function(object){return object.each(function(){var oWysiwyg=$(this).data("wysiwyg");if(!oWysiwyg){return this;}
oWysiwyg.destroy();});},"document":function(object){var oWysiwyg=object.data("wysiwyg");if(!oWysiwyg){return undefined;}
return $(oWysiwyg.editorDoc);},getContent:function(object){var oWysiwyg=object.data("wysiwyg");if(!oWysiwyg){return undefined;}
return oWysiwyg.getContent();},init:function(object,options){return object.each(function(){var opts=$.extend(true,{},options),obj;if(("textarea"!==this.nodeName.toLowerCase())||$(this).data("wysiwyg")){return;}
obj=new Wysiwyg();obj.init(this,opts);$.data(this,"wysiwyg",obj);$(obj.editorDoc).trigger("afterInit.wysiwyg");});},insertHtml:function(object,szHTML){return object.each(function(){var oWysiwyg=$(this).data("wysiwyg");if(!oWysiwyg){return this;}
oWysiwyg.insertHtml(szHTML);});},plugin:{listeners:{},bind:function(Wysiwyg){var self=this;$.each(this.listeners,function(action,handlers){var i,plugin;for(i=0;i<handlers.length;i+=1){plugin=self.parseName(handlers[i]);$(Wysiwyg.editorDoc).bind(action+".wysiwyg",{plugin:plugin},function(event){$.wysiwyg[event.data.plugin.name][event.data.plugin.method].apply($.wysiwyg[event.data.plugin.name],[Wysiwyg]);});}});},exists:function(name){var plugin;if("string"!==typeof(name)){return false;}
plugin=this.parseName(name);if(!$.wysiwyg[plugin.name]||!$.wysiwyg[plugin.name][plugin.method]){return false;}
return true;},listen:function(action,handler){var plugin;plugin=this.parseName(handler);if(!$.wysiwyg[plugin.name]||!$.wysiwyg[plugin.name][plugin.method]){return false;}
if(!this.listeners[action]){this.listeners[action]=[];}
this.listeners[action].push(handler);return true;},parseName:function(name){var elements;if("string"!==typeof(name)){return false;}
elements=name.split(".");if(2>elements.length){return false;}
return{name:elements[0],method:elements[1]};},register:function(data){if(!data.name){console.error("Plugin name missing");}
$.each($.wysiwyg,function(pluginName){if(pluginName===data.name){console.error("Plugin with name '"+data.name+"' was already registered");}});$.wysiwyg[data.name]=data;return true;}},removeFormat:function(object){return object.each(function(){var oWysiwyg=$(this).data("wysiwyg");if(!oWysiwyg){return this;}
oWysiwyg.removeFormat();});},save:function(object){return object.each(function(){var oWysiwyg=$(this).data("wysiwyg");if(!oWysiwyg){return this;}
oWysiwyg.saveContent();});},selectAll:function(object){var oWysiwyg=object.data("wysiwyg"),oBody,oRange,selection;if(!oWysiwyg){return this;}
oBody=oWysiwyg.editorDoc.body;if(window.getSelection){selection=oWysiwyg.getInternalSelection();selection.selectAllChildren(oBody);}else{oRange=oBody.createTextRange();oRange.moveToElementText(oBody);oRange.select();}},setContent:function(object,newContent){return object.each(function(){var oWysiwyg=$(this).data("wysiwyg");if(!oWysiwyg){return this;}
oWysiwyg.setContent(newContent);});},triggerControl:function(object,controlName){return object.each(function(){var oWysiwyg=$(this).data("wysiwyg");if(!oWysiwyg){return this;}
if(!oWysiwyg.controls[controlName]){console.error("Control '"+controlName+"' not exists");}
oWysiwyg.triggerControl.apply(oWysiwyg,[controlName,oWysiwyg.controls[controlName]]);});},support:{prop:supportsProp},utils:{extraSafeEntities:[["<",">","'",'"'," "],[32]],encodeEntities:function(str){var self=this,aStr,aRet=[];if(this.extraSafeEntities[1].length===0){$.each(this.extraSafeEntities[0],function(i,ch){self.extraSafeEntities[1].push(ch.charCodeAt(0));});}
aStr=str.split("");$.each(aStr,function(i){var iC=aStr[i].charCodeAt(0);if($.inArray(iC,self.extraSafeEntities[1])&&(iC<65||iC>127||(iC>90&&iC<97))){aRet.push('&#'+iC+';');}else{aRet.push(aStr[i]);}});return aRet.join('');}}};$.fn.wysiwyg=function(method){var args=arguments,plugin;if("undefined"!==typeof $.wysiwyg[method]){args=Array.prototype.concat.call([args[0]],[this],Array.prototype.slice.call(args,1));return $.wysiwyg[method].apply($.wysiwyg,Array.prototype.slice.call(args,1));}else if("object"===typeof method||!method){Array.prototype.unshift.call(args,this);return $.wysiwyg.init.apply($.wysiwyg,args);}else if($.wysiwyg.plugin.exists(method)){plugin=$.wysiwyg.plugin.parseName(method);args=Array.prototype.concat.call([args[0]],[this],Array.prototype.slice.call(args,1));return $.wysiwyg[plugin.name][plugin.method].apply($.wysiwyg[plugin.name],Array.prototype.slice.call(args,1));}else{console.error("Method '"+method+"' does not exist on jQuery.wysiwyg.\nTry to include some extra controls or plugins");}};$.fn.getWysiwyg=function(){return $.data(this,"wysiwyg");};})(jQuery);;(function($){var tmp,loading,overlay,wrap,outer,content,close,title,nav_left,nav_right,selectedIndex=0,selectedOpts={},selectedArray=[],currentIndex=0,currentOpts={},currentArray=[],ajaxLoader=null,imgPreloader=new Image(),imgRegExp=/\.(jpg|gif|png|bmp|jpeg)(.*)?$/i,swfRegExp=/[^\.]\.(swf)\s*$/i,loadingTimer,loadingFrame=1,titleHeight=0,titleStr='',start_pos,final_pos,busy=false,fx=$.extend($('<div/>')[0],{prop:0}),isIE6=$.browser.msie&&$.browser.version<7&&!window.XMLHttpRequest,_abort=function(){loading.hide();imgPreloader.onerror=imgPreloader.onload=null;if(ajaxLoader){ajaxLoader.abort();}
tmp.empty();},_error=function(){if(false===selectedOpts.onError(selectedArray,selectedIndex,selectedOpts)){loading.hide();busy=false;return;}
selectedOpts.titleShow=false;selectedOpts.width='auto';selectedOpts.height='auto';tmp.html('<p id="fancybox-error">The requested content cannot be loaded.<br />Please try again later.</p>');_process_inline();},_start=function(){var obj=selectedArray[selectedIndex],href,type,title,str,emb,ret;_abort();selectedOpts=$.extend({},$.fn.fancybox.defaults,(typeof $(obj).data('fancybox')=='undefined'?selectedOpts:$(obj).data('fancybox')));ret=selectedOpts.onStart(selectedArray,selectedIndex,selectedOpts);if(ret===false){busy=false;return;}else if(typeof ret=='object'){selectedOpts=$.extend(selectedOpts,ret);}
title=selectedOpts.title||(obj.nodeName?$(obj).attr('title'):obj.title)||'';if(obj.nodeName&&!selectedOpts.orig){selectedOpts.orig=$(obj).children("img:first").length?$(obj).children("img:first"):$(obj);}
if(title===''&&selectedOpts.orig&&selectedOpts.titleFromAlt){title=selectedOpts.orig.attr('alt');}
href=selectedOpts.href||(obj.nodeName?$(obj).attr('href'):obj.href)||null;if((/^(?:javascript)/i).test(href)||href=='#'){href=null;}
if(selectedOpts.type){type=selectedOpts.type;if(!href){href=selectedOpts.content;}}else if(selectedOpts.content){type='html';}else if(href){if(href.match(imgRegExp)){type='image';}else if(href.match(swfRegExp)){type='swf';}else if($(obj).hasClass("iframe")){type='iframe';}else if(href.indexOf("#")===0){type='inline';}else{type='ajax';}}
if(!type){_error();return;}
if(type=='inline'){obj=href.substr(href.indexOf("#"));type=$(obj).length>0?'inline':'ajax';}
selectedOpts.type=type;selectedOpts.href=href;selectedOpts.title=title;if(selectedOpts.autoDimensions){if(selectedOpts.type=='html'||selectedOpts.type=='inline'||selectedOpts.type=='ajax'){selectedOpts.width='auto';selectedOpts.height='auto';}else{selectedOpts.autoDimensions=false;}}
if(selectedOpts.modal){selectedOpts.overlayShow=true;selectedOpts.hideOnOverlayClick=false;selectedOpts.hideOnContentClick=false;selectedOpts.enableEscapeButton=false;selectedOpts.showCloseButton=false;}
selectedOpts.padding=parseInt(selectedOpts.padding,10);selectedOpts.margin=parseInt(selectedOpts.margin,10);tmp.css('padding',(selectedOpts.padding+selectedOpts.margin));$('.fancybox-inline-tmp').unbind('fancybox-cancel').bind('fancybox-change',function(){$(this).replaceWith(content.children());});switch(type){case'html':tmp.html(selectedOpts.content);_process_inline();break;case'inline':if($(obj).parent().is('#fancybox-content')===true){busy=false;return;}
$('<div class="fancybox-inline-tmp" />').hide().insertBefore($(obj)).bind('fancybox-cleanup',function(){$(this).replaceWith(content.children());}).bind('fancybox-cancel',function(){$(this).replaceWith(tmp.children());});$(obj).appendTo(tmp);_process_inline();break;case'image':busy=false;$.fancybox.showActivity();imgPreloader=new Image();imgPreloader.onerror=function(){_error();};imgPreloader.onload=function(){busy=true;imgPreloader.onerror=imgPreloader.onload=null;_process_image();};imgPreloader.src=href;break;case'swf':selectedOpts.scrolling='no';str='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+selectedOpts.width+'" height="'+selectedOpts.height+'"><param name="movie" value="'+href+'"></param>';emb='';$.each(selectedOpts.swf,function(name,val){str+='<param name="'+name+'" value="'+val+'"></param>';emb+=' '+name+'="'+val+'"';});str+='<embed src="'+href+'" type="application/x-shockwave-flash" width="'+selectedOpts.width+'" height="'+selectedOpts.height+'"'+emb+'></embed></object>';tmp.html(str);_process_inline();break;case'ajax':busy=false;$.fancybox.showActivity();selectedOpts.ajax.win=selectedOpts.ajax.success;ajaxLoader=$.ajax($.extend({},selectedOpts.ajax,{url:href,data:selectedOpts.ajax.data||{},error:function(XMLHttpRequest,textStatus,errorThrown){if(XMLHttpRequest.status>0){_error();}},success:function(data,textStatus,XMLHttpRequest){var o=typeof XMLHttpRequest=='object'?XMLHttpRequest:ajaxLoader;if(o.status==200){if(typeof selectedOpts.ajax.win=='function'){ret=selectedOpts.ajax.win(href,data,textStatus,XMLHttpRequest);if(ret===false){loading.hide();return;}else if(typeof ret=='string'||typeof ret=='object'){data=ret;}}
tmp.html(data);_process_inline();}}}));break;case'iframe':_show();break;}},_process_inline=function(){var
w=selectedOpts.width,h=selectedOpts.height;if(w.toString().indexOf('%')>-1){w=parseInt(($(window).width()-(selectedOpts.margin*2))*parseFloat(w)/100,10)+'px';}else{w=w=='auto'?'auto':w+'px';}
if(h.toString().indexOf('%')>-1){h=parseInt(($(window).height()-(selectedOpts.margin*2))*parseFloat(h)/100,10)+'px';}else{h=h=='auto'?'auto':h+'px';}
tmp.wrapInner('<div style="width:'+w+';height:'+h+';overflow: '+(selectedOpts.scrolling=='auto'?'auto':(selectedOpts.scrolling=='yes'?'scroll':'hidden'))+';position:relative;"></div>');selectedOpts.width=tmp.width();selectedOpts.height=tmp.height();_show();},_process_image=function(){selectedOpts.width=imgPreloader.width;selectedOpts.height=imgPreloader.height;$("<img />").attr({'id':'fancybox-img','src':imgPreloader.src,'alt':selectedOpts.title}).appendTo(tmp);_show();},_show=function(){var pos,equal;loading.hide();if(wrap.is(":visible")&&false===currentOpts.onCleanup(currentArray,currentIndex,currentOpts)){$.event.trigger('fancybox-cancel');busy=false;return;}
busy=true;$(content.add(overlay)).unbind();$(window).unbind("resize.fb scroll.fb");$(document).unbind('keydown.fb');if(wrap.is(":visible")&&currentOpts.titlePosition!=='outside'){wrap.css('height',wrap.height());}
currentArray=selectedArray;currentIndex=selectedIndex;currentOpts=selectedOpts;if(currentOpts.overlayShow){overlay.css({'background-color':currentOpts.overlayColor,'opacity':currentOpts.overlayOpacity,'cursor':currentOpts.hideOnOverlayClick?'pointer':'auto','height':$(document).height()});if(!overlay.is(':visible')){if(isIE6){$('select:not(#fancybox-tmp select)').filter(function(){return this.style.visibility!=='hidden';}).css({'visibility':'hidden'}).one('fancybox-cleanup',function(){this.style.visibility='inherit';});}
overlay.show();}}else{overlay.hide();}
final_pos=_get_zoom_to();_process_title();if(wrap.is(":visible")){$(close.add(nav_left).add(nav_right)).hide();pos=wrap.position(),start_pos={top:pos.top,left:pos.left,width:wrap.width(),height:wrap.height()};equal=(start_pos.width==final_pos.width&&start_pos.height==final_pos.height);content.fadeTo(currentOpts.changeFade,0.3,function(){var finish_resizing=function(){content.html(tmp.contents()).fadeTo(currentOpts.changeFade,1,_finish);};$.event.trigger('fancybox-change');content.empty().removeAttr('filter').css({'border-width':currentOpts.padding,'width':final_pos.width-currentOpts.padding*2,'height':selectedOpts.autoDimensions?'auto':final_pos.height-titleHeight-currentOpts.padding*2});if(equal){finish_resizing();}else{fx.prop=0;$(fx).animate({prop:1},{duration:currentOpts.changeSpeed,easing:currentOpts.easingChange,step:_draw,complete:finish_resizing});}});return;}
wrap.removeAttr("style");content.css('border-width',currentOpts.padding);if(currentOpts.transitionIn=='elastic'){start_pos=_get_zoom_from();content.html(tmp.contents());wrap.show();if(currentOpts.opacity){final_pos.opacity=0;}
fx.prop=0;$(fx).animate({prop:1},{duration:currentOpts.speedIn,easing:currentOpts.easingIn,step:_draw,complete:_finish});return;}
if(currentOpts.titlePosition=='inside'&&titleHeight>0){title.show();}
content.css({'width':final_pos.width-currentOpts.padding*2,'height':selectedOpts.autoDimensions?'auto':final_pos.height-titleHeight-currentOpts.padding*2}).html(tmp.contents());wrap.css(final_pos).fadeIn(currentOpts.transitionIn=='none'?0:currentOpts.speedIn,_finish);},_format_title=function(title){if(title&&title.length){if(currentOpts.titlePosition=='float'){return'<table id="fancybox-title-float-wrap" cellpadding="0" cellspacing="0"><tr><td id="fancybox-title-float-left"></td><td id="fancybox-title-float-main">'+title+'</td><td id="fancybox-title-float-right"></td></tr></table>';}
return'<div id="fancybox-title-'+currentOpts.titlePosition+'">'+title+'</div>';}
return false;},_process_title=function(){titleStr=currentOpts.title||'';titleHeight=0;title.empty().removeAttr('style').removeClass();if(currentOpts.titleShow===false){title.hide();return;}
titleStr=$.isFunction(currentOpts.titleFormat)?currentOpts.titleFormat(titleStr,currentArray,currentIndex,currentOpts):_format_title(titleStr);if(!titleStr||titleStr===''){title.hide();return;}
title.addClass('fancybox-title-'+currentOpts.titlePosition).html(titleStr).appendTo('body').show();switch(currentOpts.titlePosition){case'inside':title.css({'width':final_pos.width-(currentOpts.padding*2),'marginLeft':currentOpts.padding,'marginRight':currentOpts.padding});titleHeight=title.outerHeight(true);title.appendTo(outer);final_pos.height+=titleHeight;break;case'over':title.css({'marginLeft':currentOpts.padding,'width':final_pos.width-(currentOpts.padding*2),'bottom':currentOpts.padding}).appendTo(outer);break;case'float':title.css('left',parseInt((title.width()-final_pos.width-40)/2,10)*-1).appendTo(wrap);break;default:title.css({'width':final_pos.width-(currentOpts.padding*2),'paddingLeft':currentOpts.padding,'paddingRight':currentOpts.padding}).appendTo(wrap);break;}
title.hide();},_set_navigation=function(){if(currentOpts.enableEscapeButton||currentOpts.enableKeyboardNav){$(document).bind('keydown.fb',function(e){if(e.keyCode==27&&currentOpts.enableEscapeButton){e.preventDefault();$.fancybox.close();}else if((e.keyCode==37||e.keyCode==39)&&currentOpts.enableKeyboardNav&&e.target.tagName!=='INPUT'&&e.target.tagName!=='TEXTAREA'&&e.target.tagName!=='SELECT'){e.preventDefault();$.fancybox[e.keyCode==37?'prev':'next']();}});}
if(!currentOpts.showNavArrows){nav_left.hide();nav_right.hide();return;}
if((currentOpts.cyclic&&currentArray.length>1)||currentIndex!==0){nav_left.show();}
if((currentOpts.cyclic&&currentArray.length>1)||currentIndex!=(currentArray.length-1)){nav_right.show();}},_finish=function(){if(!$.support.opacity){content.get(0).style.removeAttribute('filter');wrap.get(0).style.removeAttribute('filter');}
if(selectedOpts.autoDimensions){content.css('height','auto');}
wrap.css('height','auto');if(titleStr&&titleStr.length){title.show();}
if(currentOpts.showCloseButton){close.show();}
_set_navigation();if(currentOpts.hideOnContentClick){content.bind('click',$.fancybox.close);}
if(currentOpts.hideOnOverlayClick){overlay.bind('click',$.fancybox.close);}
$(window).bind("resize.fb",$.fancybox.resize);if(currentOpts.centerOnScroll){$(window).bind("scroll.fb",$.fancybox.center);}
if(currentOpts.type=='iframe'){$('<iframe id="fancybox-frame" name="fancybox-frame'+new Date().getTime()+'" frameborder="0" hspace="0" '+($.browser.msie?'allowtransparency="true""':'')+' scrolling="'+selectedOpts.scrolling+'" src="'+currentOpts.href+'"></iframe>').appendTo(content);}
wrap.show();busy=false;$.fancybox.center();currentOpts.onComplete(currentArray,currentIndex,currentOpts);_preload_images();},_preload_images=function(){var href,objNext;if((currentArray.length-1)>currentIndex){href=currentArray[currentIndex+1].href;if(typeof href!=='undefined'&&href.match(imgRegExp)){objNext=new Image();objNext.src=href;}}
if(currentIndex>0){href=currentArray[currentIndex-1].href;if(typeof href!=='undefined'&&href.match(imgRegExp)){objNext=new Image();objNext.src=href;}}},_draw=function(pos){var dim={width:parseInt(start_pos.width+(final_pos.width-start_pos.width)*pos,10),height:parseInt(start_pos.height+(final_pos.height-start_pos.height)*pos,10),top:parseInt(start_pos.top+(final_pos.top-start_pos.top)*pos,10),left:parseInt(start_pos.left+(final_pos.left-start_pos.left)*pos,10)};if(typeof final_pos.opacity!=='undefined'){dim.opacity=pos<0.5?0.5:pos;}
wrap.css(dim);content.css({'width':dim.width-currentOpts.padding*2,'height':dim.height-(titleHeight*pos)-currentOpts.padding*2});},_get_viewport=function(){return[$(window).width()-(currentOpts.margin*2),$(window).height()-(currentOpts.margin*2),$(document).scrollLeft()+currentOpts.margin,$(document).scrollTop()+currentOpts.margin];},_get_zoom_to=function(){var view=_get_viewport(),to={},resize=currentOpts.autoScale,double_padding=currentOpts.padding*2,ratio;if(currentOpts.width.toString().indexOf('%')>-1){to.width=parseInt((view[0]*parseFloat(currentOpts.width))/100,10);}else{to.width=currentOpts.width+double_padding;}
if(currentOpts.height.toString().indexOf('%')>-1){to.height=parseInt((view[1]*parseFloat(currentOpts.height))/100,10);}else{to.height=currentOpts.height+double_padding;}
if(resize&&(to.width>view[0]||to.height>view[1])){if(selectedOpts.type=='image'||selectedOpts.type=='swf'){ratio=(currentOpts.width)/(currentOpts.height);if((to.width)>view[0]){to.width=view[0];to.height=parseInt(((to.width-double_padding)/ratio)+double_padding,10);}
if((to.height)>view[1]){to.height=view[1];to.width=parseInt(((to.height-double_padding)*ratio)+double_padding,10);}}else{to.width=Math.min(to.width,view[0]);to.height=Math.min(to.height,view[1]);}}
to.top=parseInt(Math.max(view[3]-20,view[3]+((view[1]-to.height-40)*0.5)),10);to.left=parseInt(Math.max(view[2]-20,view[2]+((view[0]-to.width-40)*0.5)),10);return to;},_get_obj_pos=function(obj){var pos=obj.offset();pos.top+=parseInt(obj.css('paddingTop'),10)||0;pos.left+=parseInt(obj.css('paddingLeft'),10)||0;pos.top+=parseInt(obj.css('border-top-width'),10)||0;pos.left+=parseInt(obj.css('border-left-width'),10)||0;pos.width=obj.width();pos.height=obj.height();return pos;},_get_zoom_from=function(){var orig=selectedOpts.orig?$(selectedOpts.orig):false,from={},pos,view;if(orig&&orig.length){pos=_get_obj_pos(orig);from={width:pos.width+(currentOpts.padding*2),height:pos.height+(currentOpts.padding*2),top:pos.top-currentOpts.padding-20,left:pos.left-currentOpts.padding-20};}else{view=_get_viewport();from={width:currentOpts.padding*2,height:currentOpts.padding*2,top:parseInt(view[3]+view[1]*0.5,10),left:parseInt(view[2]+view[0]*0.5,10)};}
return from;},_animate_loading=function(){if(!loading.is(':visible')){clearInterval(loadingTimer);return;}
$('div',loading).css('top',(loadingFrame*-40)+'px');loadingFrame=(loadingFrame+1)%12;};$.fn.fancybox=function(options){if(!$(this).length){return this;}
$(this).data('fancybox',$.extend({},options,($.metadata?$(this).metadata():{}))).unbind('click.fb').bind('click.fb',function(e){e.preventDefault();if(busy){return;}
busy=true;$(this).blur();selectedArray=[];selectedIndex=0;var rel=$(this).attr('rel')||'';if(!rel||rel==''||rel==='nofollow'){selectedArray.push(this);}else{selectedArray=$("a[rel="+rel+"], area[rel="+rel+"]");selectedIndex=selectedArray.index(this);}
_start();return;});return this;};$.fancybox=function(obj){var opts;if(busy){return;}
busy=true;opts=typeof arguments[1]!=='undefined'?arguments[1]:{};selectedArray=[];selectedIndex=parseInt(opts.index,10)||0;if($.isArray(obj)){for(var i=0,j=obj.length;i<j;i++){if(typeof obj[i]=='object'){$(obj[i]).data('fancybox',$.extend({},opts,obj[i]));}else{obj[i]=$({}).data('fancybox',$.extend({content:obj[i]},opts));}}
selectedArray=jQuery.merge(selectedArray,obj);}else{if(typeof obj=='object'){$(obj).data('fancybox',$.extend({},opts,obj));}else{obj=$({}).data('fancybox',$.extend({content:obj},opts));}
selectedArray.push(obj);}
if(selectedIndex>selectedArray.length||selectedIndex<0){selectedIndex=0;}
_start();};$.fancybox.showActivity=function(){clearInterval(loadingTimer);loading.show();loadingTimer=setInterval(_animate_loading,66);};$.fancybox.hideActivity=function(){loading.hide();};$.fancybox.next=function(){return $.fancybox.pos(currentIndex+1);};$.fancybox.prev=function(){return $.fancybox.pos(currentIndex-1);};$.fancybox.pos=function(pos){if(busy){return;}
pos=parseInt(pos);selectedArray=currentArray;if(pos>-1&&pos<currentArray.length){selectedIndex=pos;_start();}else if(currentOpts.cyclic&&currentArray.length>1){selectedIndex=pos>=currentArray.length?0:currentArray.length-1;_start();}
return;};$.fancybox.cancel=function(){if(busy){return;}
busy=true;$.event.trigger('fancybox-cancel');_abort();selectedOpts.onCancel(selectedArray,selectedIndex,selectedOpts);busy=false;};$.fancybox.close=function(){if(busy||wrap.is(':hidden')){return;}
busy=true;if(currentOpts&&false===currentOpts.onCleanup(currentArray,currentIndex,currentOpts)){busy=false;return;}
_abort();$(close.add(nav_left).add(nav_right)).hide();$(content.add(overlay)).unbind();$(window).unbind("resize.fb scroll.fb");$(document).unbind('keydown.fb');content.find('iframe').attr('src',isIE6&&/^https/i.test(window.location.href||'')?'javascript:void(false)':'about:blank');if(currentOpts.titlePosition!=='inside'){title.empty();}
wrap.stop();function _cleanup(){overlay.fadeOut('fast');title.empty().hide();wrap.hide();$.event.trigger('fancybox-cleanup');content.empty();currentOpts.onClosed(currentArray,currentIndex,currentOpts);currentArray=selectedOpts=[];currentIndex=selectedIndex=0;currentOpts=selectedOpts={};busy=false;}
if(currentOpts.transitionOut=='elastic'){start_pos=_get_zoom_from();var pos=wrap.position();final_pos={top:pos.top,left:pos.left,width:wrap.width(),height:wrap.height()};if(currentOpts.opacity){final_pos.opacity=1;}
title.empty().hide();fx.prop=1;$(fx).animate({prop:0},{duration:currentOpts.speedOut,easing:currentOpts.easingOut,step:_draw,complete:_cleanup});}else{wrap.fadeOut(currentOpts.transitionOut=='none'?0:currentOpts.speedOut,_cleanup);}};$.fancybox.resize=function(){if(overlay.is(':visible')){overlay.css('height',$(document).height());}
$.fancybox.center(true);};$.fancybox.center=function(){var view,align;if(busy){return;}
align=arguments[0]===true?1:0;view=_get_viewport();if(!align&&(wrap.width()>view[0]||wrap.height()>view[1])){return;}
wrap.stop().animate({'top':parseInt(Math.max(view[3]-20,view[3]+((view[1]-content.height()-40)*0.5)-currentOpts.padding)),'left':parseInt(Math.max(view[2]-20,view[2]+((view[0]-content.width()-40)*0.5)-currentOpts.padding))},typeof arguments[0]=='number'?arguments[0]:200);};$.fancybox.init=function(){if($("#fancybox-wrap").length){return;}
$('body').append(tmp=$('<div id="fancybox-tmp"></div>'),loading=$('<div id="fancybox-loading"><div></div></div>'),overlay=$('<div id="fancybox-overlay"></div>'),wrap=$('<div id="fancybox-wrap"></div>'));outer=$('<div id="fancybox-outer"></div>').append('<div class="fancybox-bg" id="fancybox-bg-n"></div><div class="fancybox-bg" id="fancybox-bg-ne"></div><div class="fancybox-bg" id="fancybox-bg-e"></div><div class="fancybox-bg" id="fancybox-bg-se"></div><div class="fancybox-bg" id="fancybox-bg-s"></div><div class="fancybox-bg" id="fancybox-bg-sw"></div><div class="fancybox-bg" id="fancybox-bg-w"></div><div class="fancybox-bg" id="fancybox-bg-nw"></div>').appendTo(wrap);outer.append(content=$('<div id="fancybox-content"></div>'),close=$('<a id="fancybox-close"></a>'),title=$('<div id="fancybox-title"></div>'),nav_left=$('<a href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a>'),nav_right=$('<a href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a>'));close.click($.fancybox.close);loading.click($.fancybox.cancel);nav_left.click(function(e){e.preventDefault();$.fancybox.prev();});nav_right.click(function(e){e.preventDefault();$.fancybox.next();});if($.fn.mousewheel){wrap.bind('mousewheel.fb',function(e,delta){if(busy){e.preventDefault();}else if($(e.target).get(0).clientHeight==0||$(e.target).get(0).scrollHeight===$(e.target).get(0).clientHeight){e.preventDefault();$.fancybox[delta>0?'prev':'next']();}});}
if(!$.support.opacity){wrap.addClass('fancybox-ie');}
if(isIE6){loading.addClass('fancybox-ie6');wrap.addClass('fancybox-ie6');$('<iframe id="fancybox-hide-sel-frame" src="'+(/^https/i.test(window.location.href||'')?'javascript:void(false)':'about:blank')+'" scrolling="no" border="0" frameborder="0" tabindex="-1"></iframe>').prependTo(outer);}};$.fn.fancybox.defaults={padding:10,margin:40,opacity:false,modal:false,cyclic:false,scrolling:'auto',width:560,height:340,autoScale:true,autoDimensions:true,centerOnScroll:false,ajax:{},swf:{wmode:'transparent'},hideOnOverlayClick:true,hideOnContentClick:false,overlayShow:true,overlayOpacity:0.7,overlayColor:'#777',titleShow:true,titlePosition:'float',titleFormat:null,titleFromAlt:false,transitionIn:'fade',transitionOut:'fade',speedIn:300,speedOut:300,changeSpeed:300,changeFade:'fast',easingIn:'swing',easingOut:'swing',showCloseButton:true,showNavArrows:true,enableEscapeButton:true,enableKeyboardNav:true,onStart:function(){},onCancel:function(){},onComplete:function(){},onCleanup:function(){},onClosed:function(){},onError:function(){}};$(document).ready(function(){$.fancybox.init();});})(jQuery);(function($){"use strict";var console=window.console?window.console:{log:$.noop,error:function(msg){$.error(msg);}};var supportsProp=(('prop'in $.fn)&&('removeProp'in $.fn));function Wysiwyg(){this.controls={bold:{groupIndex:0,visible:true,tags:["b","strong"],css:{fontWeight:"bold"},tooltip:"Bold",hotkey:{"ctrl":1,"key":66}},copy:{groupIndex:8,visible:false,tooltip:"Copy"},createLink:{groupIndex:6,visible:true,exec:function(){var self=this;if($.wysiwyg.controls&&$.wysiwyg.controls.link){$.wysiwyg.controls.link.init(this);}else if($.wysiwyg.autoload){$.wysiwyg.autoload.control("wysiwyg.link.js",function(){self.controls.createLink.exec.apply(self);});}else{console.error("$.wysiwyg.controls.link not defined. You need to include wysiwyg.link.js file");}},tags:["a"],tooltip:"Create link"},cut:{groupIndex:8,visible:false,tooltip:"Cut"},decreaseFontSize:{groupIndex:9,visible:false,tags:["small"],tooltip:"Decrease font size",exec:function(){this.decreaseFontSize();}},h1:{groupIndex:7,visible:true,className:"h1",command:($.browser.msie||$.browser.safari)?"FormatBlock":"heading","arguments":($.browser.msie||$.browser.safari)?"<h1>":"h1",tags:["h1"],tooltip:"Header 1"},h2:{groupIndex:7,visible:true,className:"h2",command:($.browser.msie||$.browser.safari)?"FormatBlock":"heading","arguments":($.browser.msie||$.browser.safari)?"<h2>":"h2",tags:["h2"],tooltip:"Header 2"},h3:{groupIndex:7,visible:true,className:"h3",command:($.browser.msie||$.browser.safari)?"FormatBlock":"heading","arguments":($.browser.msie||$.browser.safari)?"<h3>":"h3",tags:["h3"],tooltip:"Header 3"},highlight:{tooltip:"Highlight",className:"highlight",groupIndex:1,visible:false,css:{backgroundColor:"rgb(255, 255, 102)"},exec:function(){var command,node,selection,args;if($.browser.msie||$.browser.safari){command="backcolor";}else{command="hilitecolor";}
if($.browser.msie){node=this.getInternalRange().parentElement();}else{selection=this.getInternalSelection();node=selection.extentNode||selection.focusNode;while(node.style===undefined){node=node.parentNode;if(node.tagName&&node.tagName.toLowerCase()==="body"){return;}}}
if(node.style.backgroundColor==="rgb(255, 255, 102)"||node.style.backgroundColor==="#ffff66"){args="#ffffff";}else{args="#ffff66";}
this.editorDoc.execCommand(command,false,args);}},html:{groupIndex:10,visible:false,exec:function(){var elementHeight;if(this.options.resizeOptions&&$.fn.resizable){elementHeight=this.element.height();}
if(this.viewHTML){this.setContent(this.original.value);$(this.original).hide();this.editor.show();if(this.options.resizeOptions&&$.fn.resizable){if(elementHeight===this.element.height()){this.element.height(elementHeight+this.editor.height());}
this.element.resizable($.extend(true,{alsoResize:this.editor},this.options.resizeOptions));}
this.ui.toolbar.find("li").each(function(){var li=$(this);if(li.hasClass("html")){li.removeClass("active");}else{li.removeClass('disabled');}});}else{this.saveContent();$(this.original).css({width:this.element.outerWidth()-6,height:this.element.height()-this.ui.toolbar.height()-6,resize:"none"}).show();this.editor.hide();if(this.options.resizeOptions&&$.fn.resizable){if(elementHeight===this.element.height()){this.element.height(this.ui.toolbar.height());}
this.element.resizable("destroy");}
this.ui.toolbar.find("li").each(function(){var li=$(this);if(li.hasClass("html")){li.addClass("active");}else{if(false===li.hasClass("fullscreen")){li.removeClass("active").addClass('disabled');}}});}
this.viewHTML=!(this.viewHTML);},tooltip:"View source code"},increaseFontSize:{groupIndex:9,visible:false,tags:["big"],tooltip:"Increase font size",exec:function(){this.increaseFontSize();}},indent:{groupIndex:2,visible:true,tooltip:"Indent"},insertHorizontalRule:{groupIndex:6,visible:true,tags:["hr"],tooltip:"Insert Horizontal Rule"},insertImage:{groupIndex:6,visible:true,exec:function(){var self=this;if($.wysiwyg.controls&&$.wysiwyg.controls.image){$.wysiwyg.controls.image.init(this);}else if($.wysiwyg.autoload){$.wysiwyg.autoload.control("wysiwyg.image.js",function(){self.controls.insertImage.exec.apply(self);});}else{console.error("$.wysiwyg.controls.image not defined. You need to include wysiwyg.image.js file");}},tags:["img"],tooltip:"Insert image"},insertOrderedList:{groupIndex:5,visible:true,tags:["ol"],tooltip:"Insert Ordered List"},insertTable:{groupIndex:6,visible:true,exec:function(){var self=this;if($.wysiwyg.controls&&$.wysiwyg.controls.table){$.wysiwyg.controls.table(this);}else if($.wysiwyg.autoload){$.wysiwyg.autoload.control("wysiwyg.table.js",function(){self.controls.insertTable.exec.apply(self);});}else{console.error("$.wysiwyg.controls.table not defined. You need to include wysiwyg.table.js file");}},tags:["table"],tooltip:"Insert table"},insertUnorderedList:{groupIndex:5,visible:true,tags:["ul"],tooltip:"Insert Unordered List"},italic:{groupIndex:0,visible:true,tags:["i","em"],css:{fontStyle:"italic"},tooltip:"Italic",hotkey:{"ctrl":1,"key":73}},justifyCenter:{groupIndex:1,visible:true,tags:["center"],css:{textAlign:"center"},tooltip:"Justify Center"},justifyFull:{groupIndex:1,visible:true,css:{textAlign:"justify"},tooltip:"Justify Full"},justifyLeft:{visible:true,groupIndex:1,css:{textAlign:"left"},tooltip:"Justify Left"},justifyRight:{groupIndex:1,visible:true,css:{textAlign:"right"},tooltip:"Justify Right"},ltr:{groupIndex:10,visible:false,exec:function(){var p=this.dom.getElement("p");if(!p){return false;}
$(p).attr("dir","ltr");return true;},tooltip:"Left to Right"},outdent:{groupIndex:2,visible:true,tooltip:"Outdent"},paragraph:{groupIndex:7,visible:false,className:"paragraph",command:"FormatBlock","arguments":($.browser.msie||$.browser.safari)?"<p>":"p",tags:["p"],tooltip:"Paragraph"},paste:{groupIndex:8,visible:false,tooltip:"Paste"},redo:{groupIndex:4,visible:true,tooltip:"Redo"},removeFormat:{groupIndex:10,visible:true,exec:function(){this.removeFormat();},tooltip:"Remove formatting"},rtl:{groupIndex:10,visible:false,exec:function(){var p=this.dom.getElement("p");if(!p){return false;}
$(p).attr("dir","rtl");return true;},tooltip:"Right to Left"},strikeThrough:{groupIndex:0,visible:true,tags:["s","strike"],css:{textDecoration:"line-through"},tooltip:"Strike-through"},subscript:{groupIndex:3,visible:true,tags:["sub"],tooltip:"Subscript"},superscript:{groupIndex:3,visible:true,tags:["sup"],tooltip:"Superscript"},underline:{groupIndex:0,visible:true,tags:["u"],css:{textDecoration:"underline"},tooltip:"Underline",hotkey:{"ctrl":1,"key":85}},undo:{groupIndex:4,visible:true,tooltip:"Undo"},code:{visible:true,groupIndex:6,tooltip:"Code snippet",exec:function(){var range=this.getInternalRange(),common=$(range.commonAncestorContainer),$nodeName=range.commonAncestorContainer.nodeName.toLowerCase();if(common.parent("code").length){common.unwrap();}else{if($nodeName!=="body"){common.wrap("<code/>");}}}}};this.defaults={html:'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body style="margin: 3px;">INITIAL_CONTENT</body></html>',debug:false,controls:{},css:{},events:{},autoGrow:false,autoSave:true,brIE:true,formHeight:270,formWidth:440,iFrameClass:null,initialContent:"<p>Initial content</p>",maxHeight:10000,maxLength:0,messages:{nonSelection:"Select the text you wish to link"},toolbarHtml:'<ul role="menu" class="toolbar"></ul>',removeHeadings:false,replaceDivWithP:false,resizeOptions:false,rmUnusedControls:false,rmUnwantedBr:true,tableFiller:"Lorem ipsum",initialMinHeight:null,controlImage:{forceRelativeUrls:false},controlLink:{forceRelativeUrls:false},plugins:{autoload:false,i18n:false,rmFormat:{rmMsWordMarkup:false}}};this.availableControlProperties=["arguments","callback","className","command","css","custom","exec","groupIndex","hotkey","icon","tags","tooltip","visible"];this.editor=null;this.editorDoc=null;this.element=null;this.options={};this.original=null;this.savedRange=null;this.timers=[];this.validKeyCodes=[8,9,13,16,17,18,19,20,27,33,34,35,36,37,38,39,40,45,46];this.isDestroyed=false;this.dom={ie:{parent:null},w3c:{parent:null}};this.dom.parent=this;this.dom.ie.parent=this.dom;this.dom.w3c.parent=this.dom;this.ui={};this.ui.self=this;this.ui.toolbar=null;this.ui.initialHeight=null;this.dom.getAncestor=function(element,filterTagName){filterTagName=filterTagName.toLowerCase();while(element&&"body"!==element.tagName.toLowerCase()){if(filterTagName===element.tagName.toLowerCase()){return element;}
element=element.parentNode;}
return null;};this.dom.getElement=function(filterTagName){var dom=this;if(window.getSelection){return dom.w3c.getElement(filterTagName);}else{return dom.ie.getElement(filterTagName);}};this.dom.ie.getElement=function(filterTagName){var dom=this.parent,selection=dom.parent.getInternalSelection(),range=selection.createRange(),element;if("Control"===selection.type){if(1===range.length){element=range.item(0);}else{return null;}}else{element=range.parentElement();}
return dom.getAncestor(element,filterTagName);};this.dom.w3c.getElement=function(filterTagName){var dom=this.parent,range=dom.parent.getInternalRange(),element;if(!range){return null;}
element=range.commonAncestorContainer;if(3===element.nodeType){element=element.parentNode;}
if(element===range.startContainer){element=element.childNodes[range.startOffset];}
return dom.getAncestor(element,filterTagName);};this.ui.addHoverClass=function(){$(this).addClass("wysiwyg-button-hover");};this.ui.appendControls=function(){var ui=this,self=this.self,controls=self.parseControls(),hasVisibleControls=true,groups=[],controlsByGroup={},i,currentGroupIndex,iterateGroup=function(controlName,control){if(control.groupIndex&&currentGroupIndex!==control.groupIndex){currentGroupIndex=control.groupIndex;hasVisibleControls=false;}
if(!control.visible){return;}
if(!hasVisibleControls){ui.appendItemSeparator();hasVisibleControls=true;}
if(control.custom){ui.appendItemCustom(controlName,control);}else{ui.appendItem(controlName,control);}};$.each(controls,function(name,c){var index="empty";if(undefined!==c.groupIndex){if(""===c.groupIndex){index="empty";}else{index=c.groupIndex;}}
if(undefined===controlsByGroup[index]){groups.push(index);controlsByGroup[index]={};}
controlsByGroup[index][name]=c;});groups.sort(function(a,b){if("number"===typeof(a)&&typeof(a)===typeof(b)){return(a-b);}else{a=a.toString();b=b.toString();if(a>b){return 1;}
if(a===b){return 0;}
return-1;}});if(0<groups.length){currentGroupIndex=groups[0];}
for(i=0;i<groups.length;i+=1){$.each(controlsByGroup[groups[i]],iterateGroup);}};this.ui.appendItem=function(name,control){var self=this.self,className=control.className||control.command||name||"empty",tooltip=control.tooltip||control.command||name||"";return $('<li role="menuitem" unselectable="on">'+(className)+"</li>").addClass(className).attr("title",tooltip).hover(this.addHoverClass,this.removeHoverClass).click(function(){if($(this).hasClass("disabled")){return false;}
self.triggerControl.apply(self,[name,control]);this.blur();self.ui.returnRange();self.ui.focus();return true;}).appendTo(self.ui.toolbar);};this.ui.appendItemCustom=function(name,control){var self=this.self,tooltip=control.tooltip||control.command||name||"";if(control.callback){$(window).bind("trigger-"+name+".wysiwyg",control.callback);}
return $('<li role="menuitem" unselectable="on" style="background: url(\''+control.icon+'\') no-repeat;"></li>').addClass("custom-command-"+name).addClass("wysiwyg-custom-command").addClass(name).attr("title",tooltip).hover(this.addHoverClass,this.removeHoverClass).click(function(){if($(this).hasClass("disabled")){return false;}
self.triggerControl.apply(self,[name,control]);this.blur();self.ui.returnRange();self.ui.focus();self.triggerControlCallback(name);return true;}).appendTo(self.ui.toolbar);};this.ui.appendItemSeparator=function(){var self=this.self;return $('<li role="separator" class="separator"></li>').appendTo(self.ui.toolbar);};this.autoSaveFunction=function(){this.saveContent();};this.ui.checkTargets=function(element){var self=this.self;$.each(self.options.controls,function(name,control){var className=control.className||control.command||name||"empty",tags,elm,css,el,checkActiveStatus=function(cssProperty,cssValue){var handler;if("function"===typeof(cssValue)){handler=cssValue;if(handler(el.css(cssProperty).toString().toLowerCase(),self)){self.ui.toolbar.find("."+className).addClass("active");}}else{if(el.css(cssProperty).toString().toLowerCase()===cssValue){self.ui.toolbar.find("."+className).addClass("active");}}};if("fullscreen"!==className){self.ui.toolbar.find("."+className).removeClass("active");}
if(control.tags||(control.options&&control.options.tags)){tags=control.tags||(control.options&&control.options.tags);elm=element;while(elm){if(elm.nodeType!==1){break;}
if($.inArray(elm.tagName.toLowerCase(),tags)!==-1){self.ui.toolbar.find("."+className).addClass("active");}
elm=elm.parentNode;}}
if(control.css||(control.options&&control.options.css)){css=control.css||(control.options&&control.options.css);el=$(element);while(el){if(el[0].nodeType!==1){break;}
$.each(css,checkActiveStatus);el=el.parent();}}});};this.ui.designMode=function(){var attempts=3,self=this.self,runner;runner=function(attempts){if("on"===self.editorDoc.designMode){if(self.timers.designMode){window.clearTimeout(self.timers.designMode);}
if(self.innerDocument()!==self.editorDoc){self.ui.initFrame();}
return;}
try{self.editorDoc.designMode="on";}catch(e){}
attempts-=1;if(attempts>0){self.timers.designMode=window.setTimeout(function(){runner(attempts);},100);}};runner(attempts);};this.destroy=function(){this.isDestroyed=true;var i,$form=this.element.closest("form");for(i=0;i<this.timers.length;i+=1){window.clearTimeout(this.timers[i]);}
$form.unbind(".wysiwyg");this.element.remove();$.removeData(this.original,"wysiwyg");$(this.original).show();return this;};this.getRangeText=function(){var r=this.getInternalRange();if(r.toString){r=r.toString();}else if(r.text){r=r.text;}
return r;};this.execute=function(command,arg){if(typeof(arg)==="undefined"){arg=null;}
this.editorDoc.execCommand(command,false,arg);};this.extendOptions=function(options){var controls={};if("object"===typeof options.controls){controls=options.controls;delete options.controls;}
options=$.extend(true,{},this.defaults,options);options.controls=$.extend(true,{},controls,this.controls,controls);if(options.rmUnusedControls){$.each(options.controls,function(controlName){if(!controls[controlName]){delete options.controls[controlName];}});}
return options;};this.ui.focus=function(){var self=this.self;self.editor.get(0).contentWindow.focus();return self;};this.ui.returnRange=function(){var self=this.self,sel;if(self.savedRange!==null){if(window.getSelection){sel=window.getSelection();if(sel.rangeCount>0){sel.removeAllRanges();}
try{sel.addRange(self.savedRange);}catch(e){console.error(e);}}else if(window.document.createRange){window.getSelection().addRange(self.savedRange);}else if(window.document.selection){self.savedRange.select();}
self.savedRange=null;}};this.increaseFontSize=function(){if($.browser.mozilla||$.browser.opera){this.editorDoc.execCommand('increaseFontSize',false,null);}else if($.browser.safari){var newNode=this.editorDoc.createElement('big');this.getInternalRange().surroundContents(newNode);}else{console.error("Internet Explorer?");}};this.decreaseFontSize=function(){if($.browser.mozilla||$.browser.opera){this.editorDoc.execCommand('decreaseFontSize',false,null);}else if($.browser.safari){var newNode=this.editorDoc.createElement('small');this.getInternalRange().surroundContents(newNode);}else{console.error("Internet Explorer?");}};this.getContent=function(){return this.events.filter('getContent',this.editorDoc.body.innerHTML);};this.events={_events:{},bind:function(eventName,callback){if(typeof(this._events.eventName)!=="object"){this._events[eventName]=[];}
this._events[eventName].push(callback);},trigger:function(eventName,args){if(typeof(this._events.eventName)==="object"){var editor=this.editor;$.each(this._events[eventName],function(k,v){if(typeof(v)==="function"){v.apply(editor,args);}});}},filter:function(eventName,originalText){if(typeof(this._events[eventName])==="object"){var editor=this.editor,args=Array.prototype.slice.call(arguments,1);$.each(this._events[eventName],function(k,v){if(typeof(v)==="function"){originalText=v.apply(editor,args);}});}
return originalText;}};this.getElementByAttributeValue=function(tagName,attributeName,attributeValue){var i,value,elements=this.editorDoc.getElementsByTagName(tagName);for(i=0;i<elements.length;i+=1){value=elements[i].getAttribute(attributeName);if($.browser.msie){value=value.substr(value.length-attributeValue.length);}
if(value===attributeValue){return elements[i];}}
return false;};this.getInternalRange=function(){var selection=this.getInternalSelection();if(!selection){return null;}
if(selection.rangeCount&&selection.rangeCount>0){return selection.getRangeAt(0);}else if(selection.createRange){return selection.createRange();}
return null;};this.getInternalSelection=function(){if(this.editor.get(0).contentWindow){if(this.editor.get(0).contentWindow.getSelection){return this.editor.get(0).contentWindow.getSelection();}
if(this.editor.get(0).contentWindow.selection){return this.editor.get(0).contentWindow.selection;}}
if(this.editorDoc.getSelection){return this.editorDoc.getSelection();}
if(this.editorDoc.selection){return this.editorDoc.selection;}
return null;};this.getRange=function(){var selection=this.getSelection();if(!selection){return null;}
if(selection.rangeCount&&selection.rangeCount>0){selection.getRangeAt(0);}else if(selection.createRange){return selection.createRange();}
return null;};this.getSelection=function(){return(window.getSelection)?window.getSelection():window.document.selection;};this.ui.grow=function(){var self=this.self,innerBody=$(self.editorDoc.body),innerHeight=$.browser.msie?innerBody[0].scrollHeight:innerBody.height()+2+20,minHeight=self.ui.initialHeight,height=Math.max(innerHeight,minHeight);height=Math.min(height,self.options.maxHeight);self.editor.attr("scrolling",height<self.options.maxHeight?"no":"auto");innerBody.css("overflow",height<self.options.maxHeight?"hidden":"");self.editor.get(0).height=height;return self;};this.init=function(element,options){var self=this,$form=$(element).closest("form"),newX=element.width||element.clientWidth||0,newY=element.height||element.clientHeight||0;this.options=this.extendOptions(options);this.original=element;this.ui.toolbar=$(this.options.toolbarHtml);if($.browser.msie&&parseInt($.browser.version,10)<8){this.options.autoGrow=false;}
if(newX===0&&element.cols){newX=(element.cols*8)+21;}
if(newY===0&&element.rows){newY=(element.rows*16)+16;}
this.editor=$(window.location.protocol==="https:"?'<iframe src="javascript:false;"></iframe>':"<iframe></iframe>").attr("frameborder","0");if(this.options.iFrameClass){this.editor.addClass(this.options.iFrameClass);}else{this.editor.css({minHeight:(newY-6).toString()+"px",width:(newX>50)?(newX-8).toString()+"px":""});if($.browser.msie&&parseInt($.browser.version,10)<7){this.editor.css("height",newY.toString()+"px");}}
this.editor.attr("tabindex",$(element).attr("tabindex"));this.element=$("<div/>").addClass("wysiwyg");if(!this.options.iFrameClass){this.element.css({width:(newX>0)?newX.toString()+"px":"100%"});}
$(element).hide().before(this.element);this.viewHTML=false;this.initialContent=$(element).val();this.ui.initFrame();if(this.options.resizeOptions&&$.fn.resizable){this.element.resizable($.extend(true,{alsoResize:this.editor},this.options.resizeOptions));}
if(this.options.autoSave){$form.bind("submit.wysiwyg",function(){self.autoSaveFunction();});}
$form.bind("reset.wysiwyg",function(){self.resetFunction();});};this.ui.initFrame=function(){var self=this.self,stylesheet,growHandler,saveHandler;self.ui.appendControls();self.element.append(self.ui.toolbar).append($("<div><!-- --></div>").css({clear:"both"})).append(self.editor);self.editorDoc=self.innerDocument();if(self.isDestroyed){return null;}
self.ui.designMode();self.editorDoc.open();self.editorDoc.write(self.options.html.replace(/INITIAL_CONTENT/,function(){return self.wrapInitialContent();}));self.editorDoc.close();$.wysiwyg.plugin.bind(self);$(self.editorDoc).trigger("initFrame.wysiwyg");$(self.editorDoc).bind("click.wysiwyg",function(event){self.ui.checkTargets(event.target?event.target:event.srcElement);});$(self.original).focus(function(){if($(this).filter(":visible")){return;}
self.ui.focus();});$(self.editorDoc).keydown(function(event){var emptyContentRegex;if(event.keyCode===8){emptyContentRegex=/^<([\w]+)[^>]*>(<br\/?>)?<\/\1>$/;if(emptyContentRegex.test(self.getContent())){event.stopPropagation();return false;}}
return true;});if(!$.browser.msie){$(self.editorDoc).keydown(function(event){var controlName;if(event.ctrlKey||event.metaKey){for(controlName in self.controls){if(self.controls[controlName].hotkey&&self.controls[controlName].hotkey.ctrl){if(event.keyCode===self.controls[controlName].hotkey.key){self.triggerControl.apply(self,[controlName,self.controls[controlName]]);return false;}}}}
return true;});}else if(self.options.brIE){$(self.editorDoc).keydown(function(event){if(event.keyCode===13){var rng=self.getRange();rng.pasteHTML("<br/>");rng.collapse(false);rng.select();return false;}
return true;});}
if(self.options.plugins.rmFormat.rmMsWordMarkup){$(self.editorDoc).bind("keyup.wysiwyg",function(event){if(event.ctrlKey||event.metaKey){if(86===event.keyCode){if($.wysiwyg.rmFormat){if("object"===typeof(self.options.plugins.rmFormat.rmMsWordMarkup)){$.wysiwyg.rmFormat.run(self,{rules:{msWordMarkup:self.options.plugins.rmFormat.rmMsWordMarkup}});}else{$.wysiwyg.rmFormat.run(self,{rules:{msWordMarkup:{enabled:true}}});}}}}});}
if(self.options.autoSave){$(self.editorDoc).keydown(function(){self.autoSaveFunction();}).keyup(function(){self.autoSaveFunction();}).mousedown(function(){self.autoSaveFunction();}).bind($.support.noCloneEvent?"input.wysiwyg":"paste.wysiwyg",function(){self.autoSaveFunction();});}
if(self.options.autoGrow){if(self.options.initialMinHeight!==null){self.ui.initialHeight=self.options.initialMinHeight;}else{self.ui.initialHeight=$(self.editorDoc).height();}
$(self.editorDoc.body).css("border","1px solid white");growHandler=function(){self.ui.grow();};$(self.editorDoc).keyup(growHandler);$(self.editorDoc).bind("editorRefresh.wysiwyg",growHandler);self.ui.grow();}
if(self.options.css){if(String===self.options.css.constructor){if($.browser.msie){stylesheet=self.editorDoc.createStyleSheet(self.options.css);$(stylesheet).attr({"media":"all"});}else{stylesheet=$("<link/>").attr({"href":self.options.css,"media":"all","rel":"stylesheet","type":"text/css"});$(self.editorDoc).find("head").append(stylesheet);}}else{self.timers.initFrame_Css=window.setTimeout(function(){$(self.editorDoc.body).css(self.options.css);},0);}}
if(self.initialContent.length===0){if("function"===typeof(self.options.initialContent)){self.setContent(self.options.initialContent());}else{self.setContent(self.options.initialContent);}}
if(self.options.maxLength>0){$(self.editorDoc).keydown(function(event){if($(self.editorDoc).text().length>=self.options.maxLength&&$.inArray(event.which,self.validKeyCodes)===-1){event.preventDefault();}});}
$.each(self.options.events,function(key,handler){$(self.editorDoc).bind(key+".wysiwyg",function(event){handler.apply(self.editorDoc,[event,self]);});});if($.browser.msie){$(self.editorDoc).bind("beforedeactivate.wysiwyg",function(){self.savedRange=self.getInternalRange();});}else{$(self.editorDoc).bind("blur.wysiwyg",function(){self.savedRange=self.getInternalRange();});}
$(self.editorDoc.body).addClass("wysiwyg");if(self.options.events&&self.options.events.save){saveHandler=self.options.events.save;$(self.editorDoc).bind("keyup.wysiwyg",saveHandler);$(self.editorDoc).bind("change.wysiwyg",saveHandler);if($.support.noCloneEvent){$(self.editorDoc).bind("input.wysiwyg",saveHandler);}else{$(self.editorDoc).bind("paste.wysiwyg",saveHandler);$(self.editorDoc).bind("cut.wysiwyg",saveHandler);}}
if(self.options.xhtml5&&self.options.unicode){var replacements={ne:8800,le:8804,para:182,xi:958,darr:8595,nu:957,oacute:243,Uacute:218,omega:969,prime:8242,pound:163,igrave:236,thorn:254,forall:8704,emsp:8195,lowast:8727,brvbar:166,alefsym:8501,nbsp:160,delta:948,clubs:9827,lArr:8656,Omega:937,Auml:196,cedil:184,and:8743,plusmn:177,ge:8805,raquo:187,uml:168,equiv:8801,laquo:171,rdquo:8221,Epsilon:917,divide:247,fnof:402,chi:967,Dagger:8225,iacute:237,rceil:8969,sigma:963,Oslash:216,acute:180,frac34:190,lrm:8206,upsih:978,Scaron:352,part:8706,exist:8707,nabla:8711,image:8465,prop:8733,zwj:8205,omicron:959,aacute:225,Yuml:376,Yacute:221,weierp:8472,rsquo:8217,otimes:8855,kappa:954,thetasym:977,harr:8596,Ouml:214,Iota:921,ograve:242,sdot:8901,copy:169,oplus:8853,acirc:226,sup:8835,zeta:950,Iacute:205,Oacute:211,crarr:8629,Nu:925,bdquo:8222,lsquo:8216,apos:39,Beta:914,eacute:233,egrave:232,lceil:8968,Kappa:922,piv:982,Ccedil:199,ldquo:8220,Xi:926,cent:162,uarr:8593,hellip:8230,Aacute:193,ensp:8194,sect:167,Ugrave:217,aelig:230,ordf:170,curren:164,sbquo:8218,macr:175,Phi:934,Eta:919,rho:961,Omicron:927,sup2:178,euro:8364,aring:229,Theta:920,mdash:8212,uuml:252,otilde:245,eta:951,uacute:250,rArr:8658,nsub:8836,agrave:224,notin:8713,ndash:8211,Psi:936,Ocirc:212,sube:8838,szlig:223,micro:181,not:172,sup1:185,middot:183,iota:953,ecirc:234,lsaquo:8249,thinsp:8201,sum:8721,ntilde:241,scaron:353,cap:8745,atilde:227,lang:10216,__replacement:65533,isin:8712,gamma:947,Euml:203,ang:8736,upsilon:965,Ntilde:209,hearts:9829,Alpha:913,Tau:932,spades:9824,dagger:8224,THORN:222,"int":8747,lambda:955,Eacute:201,Uuml:220,infin:8734,rlm:8207,Aring:197,ugrave:249,Egrave:200,Acirc:194,rsaquo:8250,ETH:208,oslash:248,alpha:945,Ograve:210,Prime:8243,mu:956,ni:8715,real:8476,bull:8226,beta:946,icirc:238,eth:240,prod:8719,larr:8592,ordm:186,perp:8869,Gamma:915,reg:174,ucirc:251,Pi:928,psi:968,tilde:732,asymp:8776,zwnj:8204,Agrave:192,deg:176,AElig:198,times:215,Delta:916,sim:8764,Otilde:213,Mu:924,uArr:8657,circ:710,theta:952,Rho:929,sup3:179,diams:9830,tau:964,Chi:935,frac14:188,oelig:339,shy:173,or:8744,dArr:8659,phi:966,iuml:239,Lambda:923,rfloor:8971,iexcl:161,cong:8773,ccedil:231,Icirc:206,frac12:189,loz:9674,rarr:8594,cup:8746,radic:8730,frasl:8260,euml:235,OElig:338,hArr:8660,Atilde:195,Upsilon:933,there4:8756,ouml:246,oline:8254,Ecirc:202,yacute:253,auml:228,permil:8240,sigmaf:962,iquest:191,empty:8709,pi:960,Ucirc:219,supe:8839,Igrave:204,yen:165,rang:10217,trade:8482,lfloor:8970,minus:8722,Zeta:918,sub:8834,epsilon:949,yuml:255,Sigma:931,Iuml:207,ocirc:244};self.events.bind("getContent",function(text){return text.replace(/&(?:amp;)?(?!amp|lt|gt|quot)([a-z][a-z0-9]*);/gi,function(str,p1){if(!replacements[p1]){p1=p1.toLowerCase();if(!replacements[p1]){p1="__replacement";}}
var num=replacements[p1];return String.fromCharCode(num);});});}};this.innerDocument=function(){var element=this.editor.get(0);if(element.nodeName.toLowerCase()==="iframe"){if(element.contentDocument){return element.contentDocument;}else if(element.contentWindow){return element.contentWindow.document;}
if(this.isDestroyed){return null;}
console.error("Unexpected error in innerDocument");}
return element;};this.insertHtml=function(szHTML){var img,range;if(!szHTML||szHTML.length===0){return this;}
if($.browser.msie){this.ui.focus();this.editorDoc.execCommand("insertImage",false,"#jwysiwyg#");img=this.getElementByAttributeValue("img","src","#jwysiwyg#");if(img){$(img).replaceWith(szHTML);}}else{if($.browser.mozilla){if(1===$(szHTML).length){range=this.getInternalRange();range.deleteContents();range.insertNode($(szHTML).get(0));}else{this.editorDoc.execCommand("insertHTML",false,szHTML);}}else{if(!this.editorDoc.execCommand("insertHTML",false,szHTML)){this.editor.focus();this.editorDoc.execCommand("insertHTML",false,szHTML);}}}
this.saveContent();return this;};this.parseControls=function(){var self=this;$.each(this.options.controls,function(controlName,control){$.each(control,function(propertyName){if(-1===$.inArray(propertyName,self.availableControlProperties)){throw controlName+'["'+propertyName+'"]: property "'+propertyName+'" not exists in Wysiwyg.availableControlProperties';}});});if(this.options.parseControls){return this.options.parseControls.call(this);}
return this.options.controls;};this.removeFormat=function(){if($.browser.msie){this.ui.focus();}
if(this.options.removeHeadings){this.editorDoc.execCommand("formatBlock",false,"<p>");}
this.editorDoc.execCommand("removeFormat",false,null);this.editorDoc.execCommand("unlink",false,null);if($.wysiwyg.rmFormat&&$.wysiwyg.rmFormat.enabled){if("object"===typeof(this.options.plugins.rmFormat.rmMsWordMarkup)){$.wysiwyg.rmFormat.run(this,{rules:{msWordMarkup:this.options.plugins.rmFormat.rmMsWordMarkup}});}else{$.wysiwyg.rmFormat.run(this,{rules:{msWordMarkup:{enabled:true}}});}}
return this;};this.ui.removeHoverClass=function(){$(this).removeClass("wysiwyg-button-hover");};this.resetFunction=function(){this.setContent(this.initialContent);};this.saveContent=function(){if(this.original){var content,newContent;content=this.getContent();if(this.options.rmUnwantedBr){content=content.replace(/<br\/?>$/,"");}
if(this.options.replaceDivWithP){newContent=$("<div/>").addClass("temp").append(content);newContent.children("div").each(function(){var element=$(this),p=element.find("p"),i;if(0===p.length){p=$("<p></p>");if(this.attributes.length>0){for(i=0;i<this.attributes.length;i+=1){p.attr(this.attributes[i].name,element.attr(this.attributes[i].name));}}
p.append(element.html());element.replaceWith(p);}});content=newContent.html();}
$(this.original).val(content);if(this.options.events&&this.options.events.save){this.options.events.save.call(this);}}
return this;};this.setContent=function(newContent){this.editorDoc.body.innerHTML=newContent;this.saveContent();return this;};this.triggerControl=function(name,control){var cmd=control.command||name,args=control["arguments"]||[];if(control.exec){control.exec.apply(this);}else{this.ui.focus();this.ui.withoutCss();try{this.editorDoc.execCommand(cmd,false,args);}catch(e){console.error(e);}}
if(this.options.autoSave){this.autoSaveFunction();}};this.triggerControlCallback=function(name){$(window).trigger("trigger-"+name+".wysiwyg",[this]);};this.ui.withoutCss=function(){var self=this.self;if($.browser.mozilla){try{self.editorDoc.execCommand("styleWithCSS",false,false);}catch(e){try{self.editorDoc.execCommand("useCSS",false,true);}catch(e2){}}}
return self;};this.wrapInitialContent=function(){var content=this.initialContent,found=content.match(/<\/?p>/gi);if(!found){return"<p>"+content+"</p>";}else{}
return content;};}
$.wysiwyg={messages:{noObject:"Something goes wrong, check object"},addControl:function(object,name,settings){return object.each(function(){var oWysiwyg=$(this).data("wysiwyg"),customControl={},toolbar;if(!oWysiwyg){return this;}
customControl[name]=$.extend(true,{visible:true,custom:true},settings);$.extend(true,oWysiwyg.options.controls,customControl);toolbar=$(oWysiwyg.options.toolbarHtml);oWysiwyg.ui.toolbar.replaceWith(toolbar);oWysiwyg.ui.toolbar=toolbar;oWysiwyg.ui.appendControls();});},clear:function(object){return object.each(function(){var oWysiwyg=$(this).data("wysiwyg");if(!oWysiwyg){return this;}
oWysiwyg.setContent("");});},console:console,destroy:function(object){return object.each(function(){var oWysiwyg=$(this).data("wysiwyg");if(!oWysiwyg){return this;}
oWysiwyg.destroy();});},"document":function(object){var oWysiwyg=object.data("wysiwyg");if(!oWysiwyg){return undefined;}
return $(oWysiwyg.editorDoc);},getContent:function(object){var oWysiwyg=object.data("wysiwyg");if(!oWysiwyg){return undefined;}
return oWysiwyg.getContent();},init:function(object,options){return object.each(function(){var opts=$.extend(true,{},options),obj;if(("textarea"!==this.nodeName.toLowerCase())||$(this).data("wysiwyg")){return;}
obj=new Wysiwyg();obj.init(this,opts);$.data(this,"wysiwyg",obj);$(obj.editorDoc).trigger("afterInit.wysiwyg");});},insertHtml:function(object,szHTML){return object.each(function(){var oWysiwyg=$(this).data("wysiwyg");if(!oWysiwyg){return this;}
oWysiwyg.insertHtml(szHTML);});},plugin:{listeners:{},bind:function(Wysiwyg){var self=this;$.each(this.listeners,function(action,handlers){var i,plugin;for(i=0;i<handlers.length;i+=1){plugin=self.parseName(handlers[i]);$(Wysiwyg.editorDoc).bind(action+".wysiwyg",{plugin:plugin},function(event){$.wysiwyg[event.data.plugin.name][event.data.plugin.method].apply($.wysiwyg[event.data.plugin.name],[Wysiwyg]);});}});},exists:function(name){var plugin;if("string"!==typeof(name)){return false;}
plugin=this.parseName(name);if(!$.wysiwyg[plugin.name]||!$.wysiwyg[plugin.name][plugin.method]){return false;}
return true;},listen:function(action,handler){var plugin;plugin=this.parseName(handler);if(!$.wysiwyg[plugin.name]||!$.wysiwyg[plugin.name][plugin.method]){return false;}
if(!this.listeners[action]){this.listeners[action]=[];}
this.listeners[action].push(handler);return true;},parseName:function(name){var elements;if("string"!==typeof(name)){return false;}
elements=name.split(".");if(2>elements.length){return false;}
return{name:elements[0],method:elements[1]};},register:function(data){if(!data.name){console.error("Plugin name missing");}
$.each($.wysiwyg,function(pluginName){if(pluginName===data.name){console.error("Plugin with name '"+data.name+"' was already registered");}});$.wysiwyg[data.name]=data;return true;}},removeFormat:function(object){return object.each(function(){var oWysiwyg=$(this).data("wysiwyg");if(!oWysiwyg){return this;}
oWysiwyg.removeFormat();});},save:function(object){return object.each(function(){var oWysiwyg=$(this).data("wysiwyg");if(!oWysiwyg){return this;}
oWysiwyg.saveContent();});},selectAll:function(object){var oWysiwyg=object.data("wysiwyg"),oBody,oRange,selection;if(!oWysiwyg){return this;}
oBody=oWysiwyg.editorDoc.body;if(window.getSelection){selection=oWysiwyg.getInternalSelection();selection.selectAllChildren(oBody);}else{oRange=oBody.createTextRange();oRange.moveToElementText(oBody);oRange.select();}},setContent:function(object,newContent){return object.each(function(){var oWysiwyg=$(this).data("wysiwyg");if(!oWysiwyg){return this;}
oWysiwyg.setContent(newContent);});},triggerControl:function(object,controlName){return object.each(function(){var oWysiwyg=$(this).data("wysiwyg");if(!oWysiwyg){return this;}
if(!oWysiwyg.controls[controlName]){console.error("Control '"+controlName+"' not exists");}
oWysiwyg.triggerControl.apply(oWysiwyg,[controlName,oWysiwyg.controls[controlName]]);});},support:{prop:supportsProp},utils:{extraSafeEntities:[["<",">","'",'"'," "],[32]],encodeEntities:function(str){var self=this,aStr,aRet=[];if(this.extraSafeEntities[1].length===0){$.each(this.extraSafeEntities[0],function(i,ch){self.extraSafeEntities[1].push(ch.charCodeAt(0));});}
aStr=str.split("");$.each(aStr,function(i){var iC=aStr[i].charCodeAt(0);if($.inArray(iC,self.extraSafeEntities[1])&&(iC<65||iC>127||(iC>90&&iC<97))){aRet.push('&#'+iC+';');}else{aRet.push(aStr[i]);}});return aRet.join('');}}};$.fn.wysiwyg=function(method){var args=arguments,plugin;if("undefined"!==typeof $.wysiwyg[method]){args=Array.prototype.concat.call([args[0]],[this],Array.prototype.slice.call(args,1));return $.wysiwyg[method].apply($.wysiwyg,Array.prototype.slice.call(args,1));}else if("object"===typeof method||!method){Array.prototype.unshift.call(args,this);return $.wysiwyg.init.apply($.wysiwyg,args);}else if($.wysiwyg.plugin.exists(method)){plugin=$.wysiwyg.plugin.parseName(method);args=Array.prototype.concat.call([args[0]],[this],Array.prototype.slice.call(args,1));return $.wysiwyg[plugin.name][plugin.method].apply($.wysiwyg[plugin.name],Array.prototype.slice.call(args,1));}else{console.error("Method '"+method+"' does not exist on jQuery.wysiwyg.\nTry to include some extra controls or plugins");}};$.fn.getWysiwyg=function(){return $.data(this,"wysiwyg");};})(jQuery);(function($,window,document){window.Plugin=function(element,options){this.element=element;this.options=$.extend({},this._defaults,options);};Plugin.prototype._defaults={};Plugin.register=function(pluginName,pluginClass){$.fn[pluginName]=function(options){return this.each(function(){if(!$(this).data('plugin_'+pluginName)){$(this).data('plugin_'+pluginName,new pluginClass(this,options));}});};};function Accordion(element,options){Plugin.call(this,element,options);this._activate=null;this.$headers=$(this.options.header,this.element);this.$contents=$(this.options.content,this.element);this.setContentByHeader();this._bindEvents();this.init();}
Accordion.prototype=new Plugin(null,{});Accordion.prototype._defaults={'active':false,'header':'h3','content':'div'};Accordion.prototype.init=function(){var $header;if(this.options.active!==false){if(typeof(this.options.active)=='object'){$header=$(this.options.active);}else{$header=$(this.$headers[0]);}}
if(window.location.hash){$header=this.$headers.filter(window.location.hash);}
if($header&&this.$headers.filter($header)){this.hideAllExcept(this.getContentByHeader($header));}};Accordion.prototype.hideAllExcept=function($elm){this.$contents.not($elm).hide();this._activate=$elm.show();};Accordion.prototype.setContentByHeader=function(){var self=this;this.$headers.each(function(indx,elm){$(this).data('content',self.$contents.eq(indx));});};Accordion.prototype.getContentByHeader=function($header){return $header.data('content');};Accordion.prototype._bindEvents=function(){var self=this;this.$headers.on('click',function(event){self.hideAllExcept(self.getContentByHeader($(this)));if(this.id){window.location.hash=this.id;}});};function CityMap(element,options){Plugin.call(this,element,options);this.markers=[];this.infoWindows=[];this.places=this.options.places;this._instanceMap();this.addPlaces();}
CityMap.prototype=new Plugin(null,{});CityMap.prototype._defaults={'center':null,'mapSettings':{'mapTypeId':google.maps.MapTypeId.HYBRID,'zoom':15,'zoomControlOptions':{'style':google.maps.ZoomControlStyle.LARGE}},'places':null};CityMap.prototype.addPlaces=function(){if(this.places){for(var i=0;i<this.places.length;i++){this.addPlace(this.places[i]);}}};CityMap.prototype.addPlace=function(place){var markerSettings={position:new google.maps.LatLng(place.latitude,place.longitude),title:place.title};if(place.category!==undefined){markerSettings.icon=place.category.icon;}
var marker=new google.maps.Marker(markerSettings);marker.setMap(this.map);this.markers.push(marker);if(place.content){this._attachMessage(marker,place.content);}
return marker;};CityMap.prototype._instanceMap=function(){var centerLatLng;if(this.options.center){centerLatLng=this.options.center;}else if(this.places){for(var i=0;i<this.places.length;i++){place=this.places[i];if(place.latitude&&place.longitude){centerLatLng=[place.latitude,place.longitude];break;}}}
if(centerLatLng){this.options.mapSettings.center=new google.maps.LatLng(centerLatLng[0],centerLatLng[1]);}
this.map=new google.maps.Map(this.element,this.options.mapSettings);};CityMap.prototype._attachMessage=function(marker,content){var self=this;var infoWindow=new google.maps.InfoWindow({content:content,height:450,maxWidth:300});this.infoWindows.push(infoWindow);google.maps.event.addListener(marker,'click',function(){for(var i=0;i<self.infoWindows.length;i++){self.infoWindows[i].close();}
infoWindow.open(self.map,marker);});};function TooltipMap(element,options){Plugin.call(this,element,options);this.$element=$(this.element);this.place={'title':this.$element.attr('data-place-title'),'latitude':this.$element.attr('data-place-latitude'),'longitude':this.$element.attr('data-place-longitude')};this._createMarkup();this._bindEvents();}
TooltipMap.prototype=new Plugin(null,{});TooltipMap.prototype._defaults={'height':180,'klass':'tooltip-map','mapSettings':{'mapTypeControl':false,'mapTypeId':google.maps.MapTypeId.HYBRID,'streetViewControl':false,'zoom':17,'zoomControl':false},'width':700};TooltipMap.prototype._createMarkup=function(){this.$tooltip=$('<div class="'+this.options.klass+'" '+'style="height: '+this.options.height+'px; '+'width: '+this.options.width+'px;">').hide();this.$element.data('place-tooltip',this.$tooltip);this.$element.parents('ul').after(this.$tooltip);};TooltipMap.prototype._bindEvents=function(){var self=this;this.$element.on('mouseenter',function(){$(this).data('place-tooltip').show(0,function(){if(!self.$tooltip.data('plugin_cityMap')){self._instanceMap();}});}).on('mouseleave',function(){$(this).data('place-tooltip').hide();});};TooltipMap.prototype._instanceMap=function(){this.$tooltip.cityMap({'places':[this.place],'mapSettings':this.options.mapSettings});};function FormMap(element,options){Plugin.call(this,element,options);if(!FormMap.geocoder){FormMap.geocoder=new google.maps.Geocoder();}
this.$address=this.options.address;this.$latitude=this.options.latitude;this.$longitude=this.options.longitude;this.$mapElm=$('<div class="map" '+'style="height: '+this.options.height+'px; '+'width: '+this.options.width+'px;">');this.options.after.after(this.$mapElm);this.map=this._instanceMap();this.marker=this._addMarker();this._addressChange();}
FormMap.prototype=new Plugin(null,{});FormMap.prototype._defaults={'after':$('#id_address'),'address':$('#id_address'),'complementAddress':'Schroeder, SC','center':['-26.428479','-49.06541'],'height':280,'latitude':$('#id_latitude'),'longitude':$('#id_longitude'),'mapSettings':{'mapTypeId':google.maps.MapTypeId.HYBRID,'zoom':16,'zoomControlOptions':{'style':google.maps.ZoomControlStyle.LARGE}},'width':695};FormMap.prototype._instanceMap=function(){this.$mapElm=this.$mapElm.cityMap({'center':this.options.center,'mapSettings':this.options.mapSettings});return this.$mapElm.data('plugin_cityMap');};FormMap.prototype._addMarker=function(){var self=this;var placeOptions={};var isVisible=false;var latitude=this.$latitude.val();var longitude=this.$longitude.val();if(latitude&&longitude){this.map.map.panTo(new google.maps.LatLng(latitude,longitude));placeOptions={'latitude':latitude,'longitude':longitude};isVisible=true;}else{placeOptions={'latitude':this.options.center[0],'longitude':this.options.center[1]};}
var marker=this.map.addPlace(placeOptions);marker.setVisible(isVisible);marker.setDraggable(true);google.maps.event.addListener(marker,'position_changed',function(){var position=marker.getPosition();self.options.latitude.val(position.lat());self.options.longitude.val(position.lng());});return marker;};FormMap.prototype._addressChange=function(){var self=this;this.$address.on('change',function(event){var fullAddress=$(this).val()+'. '+self.options.complementAddress;FormMap.geocoder.geocode({'address':fullAddress},function(results,status){if(status==google.maps.GeocoderStatus.OK){self.map.map.panTo(results[0].geometry.location);self.map.markers[0].setPosition(results[0].geometry.location);self.map.markers[0].setVisible(true);}});});};Plugin.register('accordion',Accordion);Plugin.register('cityMap',CityMap);Plugin.register('tooltipMap',TooltipMap);Plugin.register('formMap',FormMap);})(jQuery,window,document);(function($,window,document){App={};App.context=$('#content');App.settings={'baseURL':'/','latitude':'-26.41279837582538','longitude':'-49.07399306884764','textarea':{'height':250,'width':640},'wysiwyg':{'controls':{'bold':{'visible':true},'italic':{'visible':true},'insertUnorderedList':{'visible':true},'insertOrderedList':{'visible':true}},'initialContent':'','rmUnusedControls':true}};App.routes=[[/^\/$/,'index'],[/^\/busca\/$/,'placeList'],[/^\/classificados\/adicionar\/$/,'classifiedForm'],[/^\/locais\/$/,'placeList'],[/^\/locais\/meus-locais\/$/,'placeList'],[/^\/locais\/adicionar\/$/,'placeForm'],[/^\/locais\/[\w_\-]+\/$/,'placeList'],[/^\/locais\/[\w_\-]+\/[\w_\-]+\/$/,'placeDetail'],[/^\/locais\/[\w_\-]+\/[\w_\-]+\/editar\/$/,'placeForm'],[/^\/faq\/$/,'faq'],[/^\/ajuda\/$/,'help']];App.run=function(url,options){for(var i=0;i<this.routes.length;i++){var route=this.routes[i];if(route[0].test(url)!==false){this[route[1]](options);return false;}}};App._applyAccordion=function($elm){$elm.accordion({active:true,content:'section div',header:'section h2'});$elm.on('click','a[href^="#"]',function(event){var hash=this.href.split('#')[1];$('#'+hash,$elm).trigger('click');});};App.__instanceMap=function(places){var $map=$('<div id="map" class="map-canvas">');$('#highlights',App.context).before($map);var legends={};for(var i=0;i<places.length;i++){var category_slug=places[i].category.slug;legends[places[i].category.slug]=places[i].category.description;}
if(legends){var html='<div id="map-legend"><ul>';$.each(legends,function(indx,legend){html+='<li class="category-'+indx+'">'+'<span></span>'+legend+'</li>';});html+='</ul></div>';$map.after(html);}
$map.cityMap({center:[App.settings.latitude,App.settings.longitude],places:places});};App.index=function(){if(!google.maps){return false;}
$.ajax({async:true,dataType:'json',url:App.settings.baseURL+'locais/mapa.json',success:this.__instanceMap});};App.classifiedForm=function(){$('#id_details','#announcement-add-form').css(App.settings.textarea).wysiwyg(App.settings.wysiwyg);};App.placeDetail=function(options){if(options===undefined){return false;}
$.ajax({async:true,dataType:'json',url:App.settings.baseURL+'locais/'+options.category_slug+'/'+options.slug+'.json',success:function(place){var $map=$('<div id="place-map" class="map-canvas">');$('.place',this.$context).after($map);$map.cityMap({places:[place]});}});};App.placeForm=function(){$('.place-add, .place-edit',this.$context).find('form').formMap({'address':$('#id_address'),'after':$('#id_neighbourhood').parents('p'),'center':[App.settings.latitude,App.settings.longitude],'latitude':$('#id_latitude'),'longitude':$('#id_longitude')});$('#id_details',this.$context).css(App.settings.textarea).wysiwyg(App.settings.wysiwyg);};App.placeList=function(){$('.geomap a',this.$context).tooltipMap();};App.faq=function(){this._applyAccordion($('#faq',this.$context));};App.help=function(){var $help=$('#help',this.$context);this._applyAccordion($help);$('a[rel^="lightbox"]').fancybox({'titlePosition':'inside'});};})(jQuery,window,document);
