(function(a){a.fn.document=function(){var c=this.get(0);if(c.nodeName.toLowerCase()=="iframe"){return c.contentWindow.document}return this};a.fn.documentSelection=function(){var c=this.get(0);if(c.contentWindow.document.selection){return c.contentWindow.document.selection.createRange().text}else{return c.contentWindow.getSelection().toString()}};a.fn.wysiwyg=function(d){if(arguments.length>0&&arguments[0].constructor==String){var f=arguments[0].toString();var h=[];for(var e=1;e<arguments.length;e++){h[e-1]=arguments[e]}if(f in b){return this.each(function(){a.data(this,"wysiwyg").designMode();b[f].apply(this,h)})}else{return this}}var c={};if(d&&d.controls){var c=d.controls;delete d.controls}d=a.extend({html:'<?xml version="1.0" encoding="UTF-8"?><!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>',css:{},debug:false,autoSave:true,rmUnwantedBr:true,brIE:true,controls:{},messages:{}},d);d.messages=a.extend(true,d.messages,b.MSGS_EN);d.controls=a.extend(true,d.controls,b.TOOLBAR);for(var g in c){if(g in d.controls){a.extend(d.controls[g],c[g])}else{d.controls[g]=c[g]}}return this.each(function(){b(this,d)})};function b(d,c){return this instanceof b?this.init(d,c):new b(d,c)}a.extend(b,{insertImage:function(f,e){var d=a.data(this,"wysiwyg");if(d.constructor==b&&f&&f.length>0){if(a.browser.msie){d.focus()}if(e){d.editorDoc.execCommand("insertImage",false,"#jwysiwyg#");var c=d.getElementByAttributeValue("img","src","#jwysiwyg#");if(c){c.src=f;for(var g in e){c.setAttribute(g,e[g])}}}else{d.editorDoc.execCommand("insertImage",false,f)}}},createLink:function(e){var c=a.data(this,"wysiwyg");if(c.constructor==b&&e&&e.length>0){var d=a(c.editor).documentSelection();if(d.length>0){if(a.browser.msie){c.focus()}c.editorDoc.execCommand("unlink",false,[]);c.editorDoc.execCommand("createLink",false,e)}else{if(c.options.messages.nonSelection){alert(c.options.messages.nonSelection)}}}},insertHtml:function(c){var e=a.data(this,"wysiwyg");if(e.constructor==b&&c&&c.length>0){if(a.browser.msie){e.focus();e.editorDoc.execCommand("insertImage",false,"#jwysiwyg#");var d=e.getElementByAttributeValue("img","src","#jwysiwyg#");if(d){a(d).replaceWith(c)}}else{e.editorDoc.execCommand("insertHTML",false,c)}}},setContent:function(c){var d=a.data(this,"wysiwyg");d.setContent(c);d.saveContent()},clear:function(){var c=a.data(this,"wysiwyg");c.setContent("");c.saveContent()},MSGS_EN:{nonSelection:"select the text you wish to link"},TOOLBAR:{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"},separator00:{visible:true,separator:true},justifyLeft:{visible:true,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"},separator03:{visible:true,separator:true},undo:{visible:true,tooltip:"Undo"},redo:{visible:true,tooltip:"Redo"},separator05:{separator:true},createLink:{visible:true,exec:function(){var d=a(this.editor).documentSelection();if(d.length>0){if(a.browser.msie){this.focus();this.editorDoc.execCommand("createLink",true,null)}else{var c=prompt("URL","http://");if(c&&c.length>0){this.editorDoc.execCommand("unlink",false,[]);this.editorDoc.execCommand("createLink",false,c)}}}else{if(this.options.messages.nonSelection){alert(this.options.messages.nonSelection)}}},tags:["a"],tooltip:"Create link"},insertImage:{visible:true,exec:function(){if(a.browser.msie){this.focus();this.editorDoc.execCommand("insertImage",true,null)}else{var c=prompt("URL","http://");if(c&&c.length>0){this.editorDoc.execCommand("insertImage",false,c)}}},tags:["img"],tooltip:"Insert image"},separator06:{separator:true},insertSmile01:{visible:true,exec:function(){this.editorDoc.execCommand("insertImage",false,"/images/smileys/01.gif")},tags:["img"],tooltip:"Вставить смайлик"},insertSmile02:{visible:true,exec:function(){this.editorDoc.execCommand("insertImage",false,"/images/smileys/02.gif")},tags:["img"],tooltip:"Вставить смайлик"},insertSmile04:{visible:true,exec:function(){this.editorDoc.execCommand("insertImage",false,"/images/smileys/04.gif")},tags:["img"],tooltip:"Вставить смайлик"},insertSmile05:{visible:true,exec:function(){this.editorDoc.execCommand("insertImage",false,"/images/smileys/05.gif")},tags:["img"],tooltip:"Вставить смайлик"},insertSmile06:{visible:true,exec:function(){this.editorDoc.execCommand("insertImage",false,"/images/smileys/06.gif")},tags:["img"],tooltip:"Вставить смайлик"},insertSmile07:{visible:true,exec:function(){this.editorDoc.execCommand("insertImage",false,"/images/smileys/07.gif")},tags:["img"],tooltip:"Вставить смайлик"},insertSmile08:{visible:true,exec:function(){this.editorDoc.execCommand("insertImage",false,"/images/smileys/08.gif")},tags:["img"],tooltip:"Вставить смайлик"},insertSmile09:{visible:true,exec:function(){this.editorDoc.execCommand("insertImage",false,"/images/smileys/09.gif")},tags:["img"],tooltip:"Вставить смайлик"},insertSmile10:{visible:true,exec:function(){this.editorDoc.execCommand("insertImage",false,"/images/smileys/10.gif")},tags:["img"],tooltip:"Вставить смайлик"},insertSmile11:{visible:true,exec:function(){this.editorDoc.execCommand("insertImage",false,"/images/smileys/11.gif")},tags:["img"],tooltip:"Вставить смайлик"},insertSmile00:{visible:true,exec:function(){this.editorDoc.execCommand("insertImage",false,"/images/smileys/00.gif")},tags:["img"],tooltip:"Вставить смайлик"},insertSmileangry:{visible:true,exec:function(){this.editorDoc.execCommand("insertImage",false,"/images/smileys/angry.gif")},tags:["img"],tooltip:"Вставить смайлик"},insertSmilecheese:{visible:true,exec:function(){this.editorDoc.execCommand("insertImage",false,"/images/smileys/cheese.gif")},tags:["img"],tooltip:"Вставить смайлик"},insertSmileblank:{visible:true,exec:function(){this.editorDoc.execCommand("insertImage",false,"/images/smileys/blank.gif")},tags:["img"],tooltip:"Вставить смайлик"},insertSmilekiss:{visible:true,exec:function(){this.editorDoc.execCommand("insertImage",false,"/images/smileys/kiss.gif")},tags:["img"],tooltip:"Вставить смайлик"},insertSmilelol:{visible:true,exec:function(){this.editorDoc.execCommand("insertImage",false,"/images/smileys/lol.gif")},tags:["img"],tooltip:"Вставить смайлик"},insertSmileohh:{visible:true,exec:function(){this.editorDoc.execCommand("insertImage",false,"/images/smileys/ohh.gif")},tags:["img"],tooltip:"Вставить смайлик"},insertSmileohoh:{visible:true,exec:function(){this.editorDoc.execCommand("insertImage",false,"/images/smileys/ohoh.gif")},tags:["img"],tooltip:"Вставить смайлик"},insertSmilerolleyes:{visible:true,exec:function(){this.editorDoc.execCommand("insertImage",false,"/images/smileys/rolleyes.gif")},tags:["img"],tooltip:"Вставить смайлик"},insertSmilesick:{visible:true,exec:function(){this.editorDoc.execCommand("insertImage",false,"/images/smileys/sick.gif")},tags:["img"],tooltip:"Вставить смайлик"},insertSmilesmirk:{visible:true,exec:function(){this.editorDoc.execCommand("insertImage",false,"/images/smileys/smirk.gif")},tags:["img"],tooltip:"Вставить смайлик"}}});a.extend(b.prototype,{original:null,options:{},element:null,editor:null,focus:function(){a(this.editorDoc.body).focus()},init:function(f,e){var d=this;this.editor=f;this.options=e||{};a.data(f,"wysiwyg",this);var j=f.width||f.clientWidth;var i=f.height||f.clientHeight;if(f.nodeName.toLowerCase()=="textarea"){this.original=f;if(j==0&&f.cols){j=(f.cols*8)+21}if(i==0&&f.rows){i=(f.rows*16)+16}var g=this.editor=a('<iframe src="javascript:false;"></iframe>').css({minHeight:(i-6).toString()+"px",width:(j-8).toString()+"px"}).attr("id",a(f).attr("id")+"IFrame").attr("frameborder","0");this.editor.attr("tabindex",a(f).attr("tabindex"));if(a.browser.msie){this.editor.css("height",(i).toString()+"px")}}var c=this.panel=a('<ul role="menu" class="panel"></ul>');this.appendControls();this.element=a("<div></div>").css({width:(j>0)?(j).toString()+"px":"100%"}).addClass("wysiwyg").append(c).append(a("<div><!-- --></div>").css({clear:"both"})).append(g);a(f).hide().before(this.element);this.viewHTML=false;this.initialHeight=i-8;this.initialContent=a(f).val();this.initFrame();if(this.initialContent.length==0){this.setContent("")}var h=a(f).closest("form");if(this.options.autoSave){h.submit(function(){d.saveContent()})}h.bind("reset",function(){d.setContent(d.initialContent);d.saveContent()})},initFrame:function(){var c=this;var 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=a(this.editor).document();this.editorDoc_designMode=false;try{this.editorDoc.designMode="on";this.editorDoc_designMode=true}catch(f){a(this.editorDoc).focus(function(){c.designMode()})}this.editorDoc.open();this.editorDoc.write(this.options.html.replace(/INITIAL_CONTENT/,function(){return c.initialContent}).replace(/STYLE_SHEET/,function(){return d}));this.editorDoc.close();this.editorDoc.contentEditable="true";if(a.browser.msie){setTimeout(function(){a(c.editorDoc.body).css("border","none")},0)}a(this.editorDoc).click(function(e){c.checkTargets(e.target?e.target:e.srcElement)});a(this.original).focus(function(){if(!a.browser.msie){c.focus()}});if(this.options.autoSave){a(this.editorDoc).keydown(function(){c.saveContent()}).keyup(function(){c.saveContent()}).mousedown(function(){c.saveContent()})}if(this.options.css){setTimeout(function(){if(c.options.css.constructor==String){}else{a(c.editorDoc).find("body").css(c.options.css)}},0)}a(this.editorDoc).keydown(function(g){if(a.browser.msie&&c.options.brIE&&g.keyCode==13){var e=c.getRange();e.pasteHTML("<br />");e.collapse(false);e.select();return false}return true})},designMode:function(){if(!(this.editorDoc_designMode)){try{this.editorDoc.designMode="on";this.editorDoc_designMode=true}catch(c){}}},getSelection:function(){return(window.getSelection)?window.getSelection():document.selection},getRange:function(){var c=this.getSelection();if(!(c)){return null}return(c.rangeCount>0)?c.getRangeAt(0):c.createRange()},getContent:function(){return a(a(this.editor).document()).find("body").html()},setContent:function(c){a(a(this.editor).document()).find("body").html(c)},saveContent:function(){if(this.original){var c=this.getContent();if(this.options.rmUnwantedBr){c=(c.substr(-4)=="<br>")?c.substr(0,c.length-4):c}a(this.original).val(c)}},withoutCss:function(){if(a.browser.mozilla){try{this.editorDoc.execCommand("styleWithCSS",false,false)}catch(c){try{this.editorDoc.execCommand("useCSS",false,true)}catch(c){}}}},appendMenu:function(h,d,f,e,g){var c=this;d=d||[];a("<li></li>").append(a('<a role="menuitem" tabindex="-1" href="javascript:;">'+(f||h)+"</a>").addClass(f||h).attr("title",g)).click(function(){if(e){e.apply(c)}else{c.withoutCss();c.editorDoc.execCommand(h,false,d)}if(c.options.autoSave){c.saveContent()}}).appendTo(this.panel)},appendMenuSeparator:function(){a('<li role="separator" class="separator"></li>').appendTo(this.panel)},appendControls:function(){for(var c in this.options.controls){var d=this.options.controls[c];if(d.separator){if(d.visible!==false){this.appendMenuSeparator()}}else{if(d.visible){this.appendMenu(d.command||c,d.arguments||[],d.className||d.command||c||"empty",d.exec,d.tooltip||d.command||c||"")}}}},checkTargets:function(e){for(var d in this.options.controls){var g=this.options.controls[d];var f=g.className||g.command||d||"empty";a("."+f,this.panel).removeClass("active");if(g.tags){var h=e;do{if(h.nodeType!=1){break}if(a.inArray(h.tagName.toLowerCase(),g.tags)!=-1){a("."+f,this.panel).addClass("active")}}while((h=h.parentNode))}if(g.css){var h=a(e);do{if(h[0].nodeType!=1){break}for(var c in g.css){if(h.css(c).toString().toLowerCase()==g.css[c]){a("."+f,this.panel).addClass("active")}}}while((h=h.parent()))}}},getElementByAttributeValue:function(e,c,f){var h=this.editorDoc.getElementsByTagName(e);for(var d=0;d<h.length;d++){var g=h[d].getAttribute(c);if(a.browser.msie){g=g.substr(g.length-f.length)}if(g==f){return h[d]}}return false}})})(jQuery);$(function(){$("#wysiwyg").wysiwyg()});