EmbedCommon=function(c,b,a){EmbedCommon.options={};EmbedCommon.options.textareaID=c;EmbedCommon.options.initialEditorText="<p>Please add your content here.</p>";EmbedCommon.options.editorHasFocus=false;EmbedCommon.options.embedPlaceHolderSrc="http://www.kontain.com/server/javascript/vendor/tiny_mce_3_2_4_1/themes/advanced/skins/kontain/img/embedPlaceholder.png";EmbedCommon.EditorOldHeight=EmbedCommon.EditorHeight=0;EmbedCommon.setOptions(b);EmbedCommon.setContentEditor(c,a)};EmbedCommon.setOptions=function(a){for(var b in a){EmbedCommon.options[b]=a[b]}};EmbedCommon.setContentEditor=function(c,b){var a=EmbedCommon.getEditorOptions(b);a.plugins=EmbedCommon.getSupportedPlugins();EmbedCommon.tinyEditor=new tinymce.Editor(c,a);EmbedCommon.setDefaultBoundEvents()};EmbedCommon.getEditorOptions=function(b){var a={theme:"advanced",skin:"kontain",mode:"exact",height:"160",width:"100%",auto_resize:false,object_resizing:false,advimagescale_noresize_all:true,noneditable_noneditable_class:"externalEmbedWrapper",cleanup_on_startup:true,convert_urls:false,extended_valid_elements:"param[id|name|type|value]",gecko_spellcheck:true,media_strict:false,paste_block_drop:true,paste_remove_styles:true,theme_advanced_buttons1:"bold, italic, underline, link, unlink, bullist, numlist, justifyleft, justifycenter, justifyright, undo, redo, externalEmbed, image",theme_advanced_buttons2:"",theme_advanced_buttons3:"",theme_advanced_toolbar_location:"top",theme_advanced_toolbar_align:"left",theme_advanced_source_editor_wrap:true};for(var c in b){a[c]=b[c]}return a};EmbedCommon.getSupportedPlugins=function(){var a="paste, noneditable, advimagescale";if($.browser.msie){a="media, paste, noneditable, advimagescale"}else{if((navigator.userAgent.indexOf("AppleWebKit")!==-1)){a="paste, noneditable"}}return a};EmbedCommon.addButton=function(c,e,b){var d={};var a=EmbedCommon.displayEmbedForm;switch(c){case"link":d.title="Insert hyperlink";break;case"externalEmbed":d.title="Embed external video";break;case"image":d.title="Embed external image";break}if(typeof e==="function"){b=(b===true)?true:false;if(!b){a=function(f){EmbedCommon.displayEmbedForm(f);e.call("",f)}}else{a=e}}d.onclick=function(){a.call("",c);return false};EmbedCommon.tinyEditor.addButton(c,d)};EmbedCommon.setDefaultBoundEvents=function(){var a=EmbedCommon.tinyEditor;EmbedCommon.addEvent("onInit",function(){$(EmbedCommon.options.fieldsetID).addClass("autoSize");$(a.getBody()).css("overflow","hidden");$(a.getBody()).css("overflow-x","auto");$("div.createEntryFormWrapper").addClass("autoSize");$(EmbedCommon.options.fieldsetID).addClass("autoSize");$(a.getContainer()).outerClick(function(){$(a.getContainer()).removeClass("active");EmbedCommon.autoClearTinyMCE("blur")});$(a.getContainer()).find("iframe").attr("allowTransparency","true");$("body").click();EmbedCommon.autoClearTinyMCE("blur");EmbedCommon.refreshEditorHeight(true)});EmbedCommon.addEvent("onClick",function(){$(a.getContainer()).addClass("active");$(a.getContainer()).find("iframe body").addClass("active");EmbedCommon.autoClearTinyMCE("focus");$("#externalEmbed, #urlEmbed, #imageEmbed").remove();EmbedCommon.refreshEditorHeight()});EmbedCommon.addEvent("onKeyUp",function(b,c){if(c.keyCode===13||c.keyCode===8||c.keyCode===46){EmbedCommon.refreshEditorHeight()}});EmbedCommon.addEvent("onNodeChange",function(){if($.browser.msie){EmbedCommon.storedSelection=EmbedCommon.tinyEditor.selection.getBookmark()}});if(EmbedCommon.options.submitButton!==undefined){$(EmbedCommon.options.submitButton).mouseover(function(){EmbedCommon.updateTextArea()})}};EmbedCommon.updateTextArea=function(b){EmbedCommon.findOrphanedEmbedElements();var a=(b!==undefined)?b:EmbedCommon.tinyEditor.getContent();$("#"+EmbedCommon.options.textareaID).text(a).val(a)};EmbedCommon.findOrphanedEmbedElements=function(){var c,a,d,b;$(EmbedCommon.tinyEditor.dom.select("p")).each(function(){c=$(this);d=c.find("embed");b=c.find("object");a=c.find("img.placeHolderImage");if(d.length>0){if(a.length<=0){d.remove();b.remove()}}if(a.length>0){if(d.length<=0||b.length<=0){a.remove()}}})};EmbedCommon.addEvent=function(b,c,a){a=(a===undefined)?false:true;EmbedCommon.tinyEditor[b].add(c)};EmbedCommon.autoClearTinyMCE=function(d){var b=EmbedCommon.tinyEditor;if(d==="focus"){try{if(b.getContent()===EmbedCommon.options.initialEditorText){b.focus();b.setContent("<p></p>");b.selection.select(b.dom.select("p")[0])}EmbedCommon.options.editorHasFocus=true}catch(c){}}else{if(d==="blur"){try{if(b.getContent()===""){b.setContent(EmbedCommon.options.initialEditorText)}EmbedCommon.options.editorHasFocus=false}catch(a){}}}};EmbedCommon.refreshEditorHeight=function(d){EmbedCommon.EditorOldHeight=EmbedCommon.EditorHeight;var a=0;var c=120;var b=$(EmbedCommon.tinyEditor.dom.select("p"));$(b).each(function(){a+=$(this).height()});a=(a>c)?a:c;a+=20;$(EmbedCommon.options.iframeID).height(a);EmbedCommon.EditorHeight=a;$.columnHeightChange();if(EmbedCommon.EditorOldHeight<EmbedCommon.EditorHeight){setTimeout(function(){EmbedCommon.refreshEditorHeight()},1000)}};EmbedCommon.displayEmbedForm=function(e){var c=EmbedCommon.tinyEditor;var h,a,b,g,d,f;if(!$.browser.msie){EmbedCommon.storedSelection=c.selection.getBookmark()}EmbedCommon.removeEmbedForms();switch(e){case"link":$("body").append('<form id="urlEmbed" action="#"><span class="roundedInputField"><span><label class="prefill">http://</label><input id="urlEmbedLinkInput" type="text" class="yellow" name="embedCode" /></span></span><span class="genericButton" href="#"><span class="plus"><input type="submit" value="Add" /></span></span></form>');h=$("form#urlEmbed");b=EmbedCommon.EmbedLogic.Link;d="right";break;case"image":$("body").append('<form id="imageEmbed" action="#"><span class="roundedInputField"><span><label class="prefill">Enter image link</label><input id="imageLinkEmbedField" type="text" class="yellow" name="embedCode" /></span></span><span class="genericButton" href="#"><span class="plus"><input type="submit" value="Add" /></span></span><p class="services"><span>Enter image URL from </span><span class="servicesLogos">Flickr, Photobucket, Google</span><span> and more!</span></p></form>');h=$("form#imageEmbed");b=EmbedCommon.EmbedLogic.Media;d="left";break;case"externalEmbed":$("body").append('<form id="externalEmbed" action="#"><span class="roundedInputField"><span><label class="prefill">Enter embed code</label><input id="embedCodeInputField" type="text" class="yellow" name="embedCode" /></span></span><span class="genericButton" href="#"><span class="plus"><input type="submit" value="Add" /></span></span><p class="services"><span>Enter URL or embed code from </span><span class="servicesLogos">Youtube, Vimeo, Hulu, Flickr</span><span> and more!</span></p></form>');h=$("form#externalEmbed");b=EmbedCommon.EmbedLogic.Media;d="left";break}g="#"+EmbedCommon.options.textareaID+"_"+e;f=EmbedCommon.getPopUpPosition(g,d,h);h.css({top:parseInt(f[0],10)+"px",left:parseInt(f[1],10)+"px"});$("span.genericButton",h).click(function(){$(h).submit()});$("input, .genericButton",h).click(function(i){i.stopImmediatePropagation()});h.find(".roundedInputField input").focus();$(h).submit(function(){b(h.find("input[type=text]").inputField().val(),e);h.remove();EmbedCommon.refreshEditorHeight();$.columnHeightChange();return false});h.parent().outerClick(function(){h.remove()})};EmbedCommon.removeEmbedForms=function(){$("#externalEmbed, #urlEmbed, #imageEmbed").remove()};EmbedCommon.getPopUpPosition=function(b,e,f){var a=$(b).offset().top;var d;var c;if(e==="right"){d=-28}else{d=f.outerWidth()}c=$(b).offset().left-d;a-=11;return[a,c]};EmbedCommon.EmbedLogic={};EmbedCommon.EmbedLogic.Link=function(b){var c=EmbedCommon.tinyEditor;c.selection.moveToBookmark(EmbedCommon.storedSelection);var f=c.selection.getContent();var d=f.split("<p>").join("").split("</p>").join("").split("http://").join("").split("https://").join("");var a=b.split("<p>").join("").split("</p>").join("").split("http://").join("").split("https://").join("");var e="http://";if(b.indexOf("https://")!==-1){e="https://"}a=e+a;c.selection.setContent('<a target="_blank" href="'+a+'">'+f+"</a>")};EmbedCommon.EmbedLogic.Media=function(c,j){if(!EmbedCommon.EmbedLogic.isValidInput(c,j)){return}var f=EmbedCommon.tinyEditor;var k=f.getContent();var h=EmbedCommon.EmbedLogic.getBookmark();var b=EmbedCommon.EmbedLogic.EmbedContent(j,c)[0];var n=EmbedCommon.EmbedLogic.EmbedContent(j,c)[1];var e=EmbedCommon.EmbedLogic.EmbedContent(j,c)[2];var m=(EmbedCommon.options.embedPlaceHolderImageClass!==undefined)?" "+EmbedCommon.options.embedPlaceHolderImageClass:"";if(h===true){if(k===EmbedCommon.options.initialEditorText){var l=$("<div><p>"+b+'<img class="embeddedImage'+n+m+'" /></p></div>');var d=l.find("img");d.attr("src",e).load(function(){EmbedCommon.onImageLoadComplete()});f.setContent(l.html()+"<p></p>")}else{var a=$(f.selection.getNode());if(a[0].nodeName==="P"){if(a.next("p").length===0){a.after("<p>&nbsp;</p>")}}var l=$("<div>"+b+'<img class="embeddedImage'+n+m+'" /></div>');var d=l.find("img");d.attr("src",e).load(function(){EmbedCommon.onImageLoadComplete()});if(a.html()==""||a.html()=="<br>"||a.html()=="<br/>"||a.html()=="<br />"){f.selection.setContent(l.html())}else{var g=a.after("<p></p>").next("p");g.append(l.html())}}}else{var l=$("<div><p>"+b+'<img class="embeddedImage'+n+m+'" /></p></div>');var d=l.find("img");d.attr("src",e).load(function(){EmbedCommon.onImageLoadComplete()});if(k!==EmbedCommon.options.initialEditorText){f.setContent(k+l.html())}else{f.setContent("<p></p>"+l.html()+"<p></p>")}}if($.browser.msie){setTimeout(function(){f.nodeChanged();var i=f.dom.select("img");$(i).each(function(){if($(this).hasClass("mceItemFlash")===false){$(this).removeAttr("width").removeAttr("height")}})},500)}setTimeout(function(){EmbedCommon.tinyEditor.save();try{AccountBlogSingleEntry.includeQuoteHTML();$("#commentForm input:submit").mouseover()}catch(i){}},300)};EmbedCommon.EmbedLogic.getBookmark=function(){var a=EmbedCommon.tinyEditor;var b;if($.browser.msie){b=a.selection.moveToBookmark(EmbedCommon.storedSelection)}else{b=(a.selection.getContent()==="")}if(EmbedCommon.options.editorHasFocus===false){b=false}return b};EmbedCommon.onImageLoadComplete=function(){EmbedCommon.refreshEditorHeight()};EmbedCommon.EmbedLogic.isValidInput=function(a,b){if(b==="image"&&!EmbedCommon.EmbedLogic.isValidImageInput(a)){alert("Please enter a valid image URL\nExample: http://www.website.com/photo.jpg");return false}else{if(b==="externalEmbed"&&!EmbedCommon.EmbedLogic.isValidEmbedInput(a)){}}return true};EmbedCommon.EmbedLogic.isValidImageInput=function(a){var d=(a.indexOf("<")!==-1);var c=(a.indexOf(">")!==-1);var b=(a.indexOf("http://")===-1);if(d||c||b){return false}return true};EmbedCommon.EmbedLogic.isValidEmbedInput=function(a){return true};EmbedCommon.EmbedLogic.EmbedContent=function(e,a){var g="";var h="";var c="";var f=undefined;if(typeof(AccountBlogSingleEntry)==="object"){f=540}if(e==="externalEmbed"){var d;var b=(a.substring(0,4)==="http");if(b===true){g=VideoEmbedGenerator.embedVideoFromURL(a)}else{g=EmbedUtils.returnSanitizedEmbedString(a,f)}g=g.replace(/<p>.*<\/p>/i,"");h=" placeHolderImage";a=EmbedCommon.options.embedPlaceHolderSrc}return[g,h,a]};EmbedCommon.getEditor=function(){return EmbedCommon.tinyEditor};$(window).resize(function(){EmbedCommon.removeEmbedForms()});