/* content from:
 * http://github.com/akzhan/jwysiwyg/raw/master/jwysiwyg/jquery.wysiwyg.js
 * closure compiled 2010-09-28 */
(function(a){var h=function(b,d){this.init(b,d)},i=function(b){b=a(b).get(0);if(b.nodeName.toLowerCase()=="iframe")return b.contentWindow.document;return b},k=function(){var b=this.get(0);return b.contentWindow.document.selection?b.contentWindow.document.selection.createRange().text:b.contentWindow.getSelection().toString()};a.fn.wysiwyg=function(b){if(arguments.length>0&&arguments[0].constructor==String){var d=arguments[0].toString(),e=[];if(d=="enabled")return this.data("wysiwyg")!==null;for(var c=
1;c<arguments.length;c++)e[c-1]=arguments[c];var f=null;this.each(function(){a.data(this,"wysiwyg").designMode();f=h[d].apply(this,e)});return f}if(this.data("wysiwyg"))return this;c={};if(b&&b.controls){c=b.controls;delete b.controls}b=a.extend({},a.fn.wysiwyg.defaults,b);b.controls=a.extend(true,b.controls,a.fn.wysiwyg.controls);for(var g in c)if(g in b.controls)a.extend(b.controls[g],c[g]);else b.controls[g]=c[g];return this.each(function(){new h(this,b)})};a.fn.wysiwyg.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">STYLE_SHEET</head><body style="margin: 0px;">INITIAL_CONTENT</body></html>',
formTableHtml:'<form class="wysiwyg"><fieldset><legend>Insert table</legend><label>Count of columns: <input type="text" name="colCount" value="3" /></label><label><br />Count of rows: <input type="text" name="rowCount" value="3" /></label><input type="submit" class="button" value="Insert table" /> <input type="reset" value="Cancel" /></fieldset></form>',formImageHtml:'<form class="wysiwyg"><fieldset><legend>Insert Image</legend><label>Image URL: <input type="text" name="url" value="http://" /></label><label>Image Title: <input type="text" name="imagetitle" value="" /></label><label>Image Description: <input type="text" name="description" value="" /></label><input type="submit" class="button" value="Insert Image" /> <input type="reset" value="Cancel" /></fieldset></form>',
formWidth:440,formHeight:270,tableFiller:"Lorem ipsum",css:{},debug:false,autoSave:true,rmUnwantedBr:true,brIE:true,iFrameClass:null,messages:{nonSelection:"select the text you wish to link"},events:{},controls:{},resizeOptions:false};a.fn.wysiwyg.controls={bold:{visible:true,tags:["b","strong"],css:{fontWeight:"bold"},tooltip:"Bold"},italic:{visible:true,tags:["i","em"],css:{fontStyle:"italic"},tooltip:"Italic"},strikeThrough:{visible:true,tags:["s","strike"],css:{textDecoration:"line-through"},
tooltip:"Strike-through"},underline:{visible:true,tags:["u"],css:{textDecoration:"underline"},tooltip:"Underline"},justifyLeft:{visible:true,groupIndex:1,css:{textAlign:"left"},tooltip:"Justify Left"},justifyCenter:{visible:true,tags:["center"],css:{textAlign:"center"},tooltip:"Justify Center"},justifyRight:{visible:true,css:{textAlign:"right"},tooltip:"Justify Right"},justifyFull:{visible:true,css:{textAlign:"justify"},tooltip:"Justify Full"},indent:{groupIndex:2,visible:true,tooltip:"Indent"},outdent:{visible:true,
tooltip:"Outdent"},subscript:{groupIndex:3,visible:true,tags:["sub"],tooltip:"Subscript"},superscript:{visible:true,tags:["sup"],tooltip:"Superscript"},undo:{groupIndex:4,visible:true,tooltip:"Undo"},redo:{visible:true,tooltip:"Redo"},insertOrderedList:{groupIndex:5,visible:true,tags:["ol"],tooltip:"Insert Ordered List"},insertUnorderedList:{visible:true,tags:["ul"],tooltip:"Insert Unordered List"},insertHorizontalRule:{visible:true,tags:["hr"],tooltip:"Insert Horizontal Rule"},createLink:{groupIndex:6,
visible:true,exec:function(){var b=k.call(a(this.editor));if(b&&b.length>0)if(a.browser.msie){this.focus();this.editorDoc.execCommand("createLink",true,null)}else{if((b=prompt("URL","http://"))&&b.length>0){this.editorDoc.execCommand("unlink",false,null);this.editorDoc.execCommand("createLink",false,b)}}else this.options.messages.nonSelection&&alert(this.options.messages.nonSelection)},tags:["a"],tooltip:"Create link"},insertImage:{visible:true,exec:function(){var b=this;if(a.modal)a.modal(a.fn.wysiwyg.defaults.formImageHtml,
{onShow:function(c){a("input:submit",c.data).click(function(f){f.preventDefault();f=a('input[name="url"]',c.data).val();var g=a('input[name="imagetitle"]',c.data).val(),j=a('input[name="description"]',c.data).val();b.insertHtml("<img src='"+f+"' title='"+g+"' alt='"+j+"' />");a.modal.close()});a("input:reset",c.data).click(function(f){f.preventDefault();a.modal.close()})},maxWidth:a.fn.wysiwyg.defaults.formWidth,maxHeight:a.fn.wysiwyg.defaults.formHeight,overlayClose:true});else if(a.fn.dialog){var d=
a(a.fn.wysiwyg.defaults.formImageHtml).appendTo("body");d.dialog({modal:true,width:a.fn.wysiwyg.defaults.formWidth,height:a.fn.wysiwyg.defaults.formHeight,open:function(){a("input:submit",a(this)).click(function(c){c.preventDefault();c=a('input[name="url"]',d).val();var f=a('input[name="imagetitle"]',d).val(),g=a('input[name="description"]',d).val();b.insertHtml("<img src='"+c+"' title='"+f+"' alt='"+g+"' />");a(d).dialog("close")});a("input:reset",a(this)).click(function(c){c.preventDefault();a(d).dialog("close")})},
close:function(){a(this).dialog("destroy")}})}else if(a.browser.msie){this.focus();this.editorDoc.execCommand("insertImage",true,null)}else{var e=prompt("URL","http://");e&&e.length>0&&this.editorDoc.execCommand("insertImage",false,e)}},tags:["img"],tooltip:"Insert image"},insertTable:{visible:true,exec:function(){var b=this;if(a.fn.modal)a.modal(a.fn.wysiwyg.defaults.formTableHtml,{onShow:function(f){a("input:submit",f.data).click(function(g){g.preventDefault();g=a('input[name="rowCount"]',f.data).val();
var j=a('input[name="colCount"]',f.data).val();b.insertTable(j,g,a.fn.wysiwyg.defaults.tableFiller);a.modal.close()});a("input:reset",f.data).click(function(g){g.preventDefault();a.modal.close()})},maxWidth:a.fn.wysiwyg.defaults.formWidth,maxHeight:a.fn.wysiwyg.defaults.formHeight,overlayClose:true});else if(a.fn.dialog){var d=a(a.fn.wysiwyg.defaults.formTableHtml).appendTo("body");d.dialog({modal:true,width:a.fn.wysiwyg.defaults.formWidth,height:a.fn.wysiwyg.defaults.formHeight,open:function(){a("input:submit",
a(this)).click(function(f){f.preventDefault();f=a('input[name="rowCount"]',d).val();var g=a('input[name="colCount"]',d).val();b.insertTable(g,f,a.fn.wysiwyg.defaults.tableFiller);a(d).dialog("close")});a("input:reset",a(this)).click(function(f){f.preventDefault();a(d).dialog("close")})},close:function(){a(this).dialog("destroy")}})}else{var e=prompt("Count of columns","3"),c=prompt("Count of rows","3");this.insertTable(e,c,a.fn.wysiwyg.defaults.tableFiller)}},tags:["table"],tooltip:"Insert table"},
h1:{visible:true,groupIndex:7,className:"h1",command:a.browser.msie||a.browser.safari?"FormatBlock":"heading",arguments:a.browser.msie||a.browser.safari?"<h1>":"h1",tags:["h1"],tooltip:"Header 1"},h2:{visible:true,className:"h2",command:a.browser.msie||a.browser.safari?"FormatBlock":"heading",arguments:a.browser.msie||a.browser.safari?"<h2>":"h2",tags:["h2"],tooltip:"Header 2"},h3:{visible:true,className:"h3",command:a.browser.msie||a.browser.safari?"FormatBlock":"heading",arguments:a.browser.msie||
a.browser.safari?"<h3>":"h3",tags:["h3"],tooltip:"Header 3"},cut:{groupIndex:8,visible:false,tooltip:"Cut"},copy:{visible:false,tooltip:"Copy"},paste:{visible:false,tooltip:"Paste"},increaseFontSize:{groupIndex:9,visible:false,tags:["big"],tooltip:"Increase font size"},decreaseFontSize:{visible:false,tags:["small"],tooltip:"Decrease font size"},removeFormat:{visible:true,exec:function(){a.browser.msie&&this.focus();this.editorDoc.execCommand("formatBlock",false,"<P>");this.editorDoc.execCommand("removeFormat",
false,null);this.editorDoc.execCommand("unlink",false,null)},tooltip:"Remove formatting"},html:{groupIndex:10,visible:false,exec:function(){if(this.viewHTML){this.setContent(a(this.original).val());a(this.original).hide();a(this.editor).show()}else{var b=a(this.editor);this.saveContent();a(this.original).css({width:a(this.element).outerWidth()-6,height:a(this.element).height()-a(this.panel).height()-6,resize:"none"}).show();b.hide()}this.viewHTML=!this.viewHTML},tooltip:"View source code"},rtl:{visible:false,
exec:function(){var b=a(this.editor).documentSelection();b=a("<div />").append(b).children().length>0?a(b).attr("dir","rtl"):a("<div />").attr("dir","rtl").append(b);this.editorDoc.execCommand("inserthtml",false,a("<div />").append(b).html())},tooltip:"Right to Left"},ltr:{visible:false,exec:function(){var b=a(this.editor).documentSelection();b=a("<div />").append(b).children().length>0?a(b).attr("dir","ltr"):a("<div />").attr("dir","ltr").append(b);this.editorDoc.execCommand("inserthtml",false,a("<div />").append(b).html())},
tooltip:"Left to Right"}};a.extend(h,{insertImage:function(b,d){var e=a.data(this,"wysiwyg");if(e.constructor==h&&b&&b.length>0){a.browser.msie&&e.focus();if(d){e.editorDoc.execCommand("insertImage",false,"#jwysiwyg#");if(e=e.getElementByAttributeValue("img","src","#jwysiwyg#")){e.src=b;for(var c in d)e.setAttribute(c,d[c])}}else e.editorDoc.execCommand("insertImage",false,b)}return this},createLink:function(b){var d=a.data(this,"wysiwyg");if(d.constructor==h&&b&&b.length>0){var e=k.call(a(d.editor));
if(e&&e.length>0){a.browser.msie&&d.focus();d.editorDoc.execCommand("unlink",false,null);d.editorDoc.execCommand("createLink",false,b)}else d.options.messages.nonSelection&&alert(d.options.messages.nonSelection)}return this},insertHtml:function(b){a.data(this,"wysiwyg").insertHtml(b);return this},insertTable:function(b,d,e){a.data(this,"wysiwyg").insertTable(b,d,e);return this},getContent:function(){return a.data(this,"wysiwyg").getContent()},setContent:function(b){var d=a.data(this,"wysiwyg");d.setContent(b);
d.saveContent();return this},clear:function(){var b=a.data(this,"wysiwyg");b.setContent("");b.saveContent();return this},removeFormat:function(){a.data(this,"wysiwyg").removeFormat();return this},save:function(){a.data(this,"wysiwyg").saveContent();return this},document:function(){var b=a.data(this,"wysiwyg");return a(b.editorDoc)},destroy:function(){a.data(this,"wysiwyg").destroy();return this}});var l=function(){a(this).addClass("wysiwyg-button-hover")},m=function(){a(this).removeClass("wysiwyg-button-hover")};
a.extend(h.prototype,{original:null,options:{},element:null,editor:null,removeFormat:function(){a.browser.msie&&this.focus();this.editorDoc.execCommand("removeFormat",false,null);this.editorDoc.execCommand("unlink",false,null);return this},destroy:function(){a(this.element).closest("form").unbind("submit",this.autoSaveFunction).unbind("reset",this.resetFunction);a(this.element).remove();a.removeData(this.original,"wysiwyg");a(this.original).show();return this},focus:function(){this.editor.get(0).contentWindow.focus();
return this},init:function(b,d){var e=this;this.editor=b;this.options=d||{};a.data(b,"wysiwyg",this);var c=b.width||b.clientWidth||0,f=b.height||b.clientHeight||0;if(b.nodeName.toLowerCase()=="textarea"){this.original=b;if(c===0&&b.cols){c=b.cols*8+21;b.cols=0}if(f===0&&b.rows){f=b.rows*16+16;b.rows=0}this.editor=a(location.protocol=="https:"?'<iframe src="javascript:false;"></iframe>':"<iframe></iframe>").attr("frameborder","0");if(d.iFrameClass)this.editor.addClass(iFrameClass);else{this.editor.css({minHeight:(f-
6).toString()+"px",width:(c-8).toString()+"px"});a.browser.msie&&this.editor.css("height",f.toString()+"px")}this.editor.attr("tabindex",a(b).attr("tabindex"))}var g=this.panel=a('<ul role="menu" class="panel"></ul>');this.appendControls();this.element=a("<div></div>").addClass("wysiwyg").append(g).append(a("<div><!-- --\></div>").css({clear:"both"})).append(this.editor);d.iFrameClass||this.element.css({width:c>0?c.toString()+"px":"100%"});a(b).hide().before(this.element);this.viewHTML=false;this.initialHeight=
f-8;this.initialContent=a(b).val();this.initFrame();this.autoSaveFunction=function(){e.saveContent()};this.resetFunction=function(){e.setContent(e.initialContent);e.saveContent()};this.options.resizeOptions&&a.fn.resizable&&this.element.resizable(a.extend(true,{alsoResize:this.editor},this.options.resizeOptions));c=a(b).closest("form");this.options.autoSave&&c.submit(e.autoSaveFunction);c.bind("reset",e.resetFunction)},initFrame:function(){var b=this,d="";if(this.options.css&&this.options.css.constructor==
String)d='<link rel="stylesheet" type="text/css" media="screen" href="'+this.options.css+'" />';this.editorDoc=i(this.editor);this.editorDoc_designMode=false;this.designMode();this.editorDoc.open();this.editorDoc.write(this.options.html.replace(/INITIAL_CONTENT/,function(){return b.initialContent}).replace(/STYLE_SHEET/,function(){return d}));this.editorDoc.close();a.browser.msie&&window.setTimeout(function(){a(b.editorDoc.body).css("border","none")},0);a(this.editorDoc).click(function(c){b.checkTargets(c.target?
c.target:c.srcElement)});a(this.original).focus(function(){a(this).filter(":visible")||b.focus()});if(a.browser.msie)this.options.brIE&&a(this.editorDoc).keydown(function(c){if(c.keyCode==13){c=b.getRange();c.pasteHTML("<br />");c.collapse(false);c.select();return false}return true});else a(this.editorDoc).keydown(function(c){if(c.ctrlKey)switch(c.keyCode){case 66:this.execCommand("Bold",false,false);return false;case 73:this.execCommand("Italic",false,false);return false;case 85:this.execCommand("Underline",
false,false);return false}return true});if(this.options.autoSave){var e=function(){b.saveContent()};a(this.editorDoc).keydown(e).keyup(e).mousedown(e).bind(a.support.noCloneEvent?"input":"paste",e)}this.options.css&&window.setTimeout(function(){b.options.css.constructor!=String&&a(b.editorDoc).find("body").css(b.options.css)},0);this.initialContent.length===0&&this.setContent("");a.each(this.options.events,function(c,f){a(b.editorDoc).bind(c,f)});a(this.editorDoc.body).addClass("wysiwyg");if(this.options.events&&
this.options.events.save){e=this.options.events.save;a(b.editorDoc).bind("keyup",e);a(b.editorDoc).bind("change",e);if(a.support.noCloneEvent)a(b.editorDoc).bind("input",e);else{a(b.editorDoc).bind("paste",e);a(b.editorDoc).bind("cut",e)}}},designMode:function(){var b=3,d,e=this,c=this.editorDoc;d=function(){if(i(e.editor)!==c)e.initFrame();else{try{c.designMode="on"}catch(f){}b--;b>0&&a.browser.mozilla&&setTimeout(d,100)}};d();this.editorDoc_designMode=true},getSelection:function(){return window.getSelection?
window.getSelection():document.selection},getRange:function(){var b=this.getSelection();if(!b)return null;return b.rangeCount>0?b.getRangeAt(0):b.createRange?b.createRange():null},getContent:function(){return a(i(this.editor)).find("body").html()},setContent:function(b){a(i(this.editor)).find("body").html(b);return this},insertHtml:function(b){if(b&&b.length>0)if(a.browser.msie){this.focus();this.editorDoc.execCommand("insertImage",false,"#jwysiwyg#");var d=this.getElementByAttributeValue("img","src",
"#jwysiwyg#");d&&a(d).replaceWith(b)}else this.editorDoc.execCommand("insertHTML",false,b);return this},insertTable:function(b,d,e){if(!(isNaN(d)||isNaN(b)||d===null||b===null)){b=parseInt(b,10);d=parseInt(d,10);if(e===null)e="&nbsp;";e="<td>"+e+"</td>";var c=['<table border="1" style="width: 100%;"><tbody>'];for(d=d;d>0;d--){c.push("<tr>");for(var f=b;f>0;f--)c.push(e);c.push("</tr>")}c.push("</tbody></table>");return this.insertHtml(c.join(""))}},saveContent:function(){if(this.original){var b=this.getContent();
if(this.options.rmUnwantedBr)b=b.substr(-4)=="<br>"?b.substr(0,b.length-4):b;a(this.original).val(b);this.options.events&&this.options.events.save&&this.options.events.save.call(this)}return this},withoutCss:function(){if(a.browser.mozilla)try{this.editorDoc.execCommand("styleWithCSS",false,false)}catch(b){try{this.editorDoc.execCommand("useCSS",false,true)}catch(d){}}return this},appendMenu:function(b,d,e,c,f){var g=this;d=d||[];return a('<li role="menuitem" UNSELECTABLE="on">'+(e||b)+"</li>").addClass(e||
b).attr("title",f).hover(l,m).click(function(){if(c)c.apply(g);else{g.focus();g.withoutCss();g.editorDoc.execCommand(b,false,d)}g.options.autoSave&&g.saveContent();this.blur()}).appendTo(this.panel)},appendMenuSeparator:function(){return a('<li role="separator" class="separator"></li>').appendTo(this.panel)},parseControls:function(){if(this.options.parseControls)return this.options.parseControls.call(this);return this.options.controls},appendControls:function(){var b=this.parseControls(),d=0,e=true,
c;for(c in b){var f=b[c];if(f.groupIndex&&d!=f.groupIndex){d=f.groupIndex;e=false}if(f.visible){if(!e){this.appendMenuSeparator();e=true}this.appendMenu(f.command||c,f.arguments||"",f.className||f.command||c||"empty",f.exec,f.tooltip||f.command||c||"")}}},checkTargets:function(b){for(var d in this.options.controls){var e=this.options.controls[d],c=e.className||e.command||d||"empty";a("."+c,this.panel).removeClass("active");if(e.tags){var f=b;do{if(f.nodeType!=1)break;a.inArray(f.tagName.toLowerCase(),
e.tags)!=-1&&a("."+c,this.panel).addClass("active")}while(f=f.parentNode)}if(e.css){f=a(b);do{if(f[0].nodeType!=1)break;for(var g in e.css)f.css(g).toString().toLowerCase()==e.css[g]&&a("."+c,this.panel).addClass("active")}while(f=f.parent())}}},getElementByAttributeValue:function(b,d,e){b=this.editorDoc.getElementsByTagName(b);for(var c=0;c<b.length;c++){var f=b[c].getAttribute(d);if(a.browser.msie)f=f.substr(f.length-e.length);if(f==e)return b[c]}return false}})})(jQuery);