var BlipBB=(function(f,o){var g=navigator.userAgent.toLowerCase(),clientVer=parseInt(navigator.appVersion),is_ie=((g.indexOf('msie')!=-1)&&(g.indexOf('opera')==-1)),is_nav=((g.indexOf('mozilla')!=-1)&&(g.indexOf('spoofer')==-1)&&(g.indexOf('compatible')==-1)&&(g.indexOf('opera')==-1)&&(g.indexOf('webtv')==-1)&&(g.indexOf('hotjava')==-1)),is_win=((g.indexOf('win')!=-1)||(g.indexOf('16bit')!=-1)),is_mac=(g.indexOf('mac')!=-1);function caretPosition(){var a=null,end=null}var h=function(a){this.box=a};h.prototype.insert=function(v){return this.bb_style("["+v+"]","[/"+v+"]")};h.prototype.mozWrap=function(a,b){var c=this.box.textLength,selStart=this.box.selectionStart,selEnd=this.box.selectionEnd,scrollTop=this.box.scrollTop;if(selEnd==1||selEnd==2)selEnd=c;var d=(this.box.value).substring(0,selStart),s2=(this.box.value).substring(selStart,selEnd),s3=(this.box.value).substring(selEnd,c);this.box.value=d+a+s2+b+s3;this.box.selectionStart=selEnd+a.length+b.length;this.box.selectionEnd=this.box.selectionStart;this.box.focus();this.box.scrollTop=scrollTop;return this};h.prototype.storeCaret=function(){if(this.box.createTextRange)this.box.caretPos=document.selection.createRange().duplicate()};h.prototype.getCaretPosition=function(){var a=new caretPosition();if(this.box.selectionStart||this.box.selectionStart==0){a.start=this.box.selectionStart;a.end=this.box.selectionEnd}else if(document.selection){var b=document.selection.createRange();var c=document.body.createTextRange();c.moveToElementText(this.box);var d;for(d=0;c.compareEndPoints('StartToStart',b)<0;d++)c.moveStart('character',1);a.start=d;a.end=d}return a};h.prototype.setCaretPosition=function(a){if(!isNaN(this.box.selectionStart)){this.box.selectionStart=a.start;this.box.selectionEnd=a.start}else if(document.selection){var b=this.box.createTextRange();b.move("character",a.start);b.select();this.box.storeCaret()}};h.prototype.insert_text=function(a,b,c){if(b)a=' '+a+' ';if(!isNaN(this.box.selectionStart)){var d=this.box.selectionStart,sel_end=this.box.selectionEnd;this.mozWrap(a,'');this.box.selectionStart=d+a.length;this.box.selectionEnd=sel_end+a.length}else if(this.box.createTextRange&&this.box.caretPos){var e=this.box.caretPos;e.text=e.text.charAt(e.text.length-1)==' '?e.text+a+' ':e.text+a}else{this.box.value=this.box.value+a}this.box.focus()};h.prototype.bb_style=function(a,b){var c=false;this.box.focus();if((clientVer>=4)&&is_ie&&is_win){c=document.selection.createRange().text;if(c){document.selection.createRange().text=a+c+b;this.box.focus();var d=this.getCaretPosition().start+(a+c+b).length;var e=this.box.createTextRange();e.move("character",d);e.select();this.box.storeCaret();this.box.focus();c='';return}}else if(this.box.selectionEnd&&(this.box.selectionEnd-this.box.selectionStart>0)){this.mozWrap(a,b);this.box.focus();c='';return}var d=this.getCaretPosition().start+(a.length||b.length);this.insert_text(a+b);if(!isNaN(this.box.selectionStart)){this.box.selectionStart=d;this.box.selectionEnd=d}else if(document.selection){var e=this.box.createTextRange();e.move("character",d);e.select();this.box.storeCaret()}this.box.focus();return};h.prototype.insert_url=function(){var a=((clientVer>=4)&&is_ie&&is_win)?document.selection.createRange().text:(this.box.value.substring(this.box.selectionStart,this.box.selectionEnd));var b=prompt("Enter the web address of the page you would like to link to:","http://");if(!b)return;b=b.replace('http://http://','http://');var c=a||prompt("Enter the text that you want to show for the link:","");if(!c)return;if(a){this.bb_style("[url="+b+"]","[/url]")}else{this.bb_style('',"[url="+b+"]"+c+"[/url]")}};h.prototype.insert_video=function(){var a=prompt("Enter the web address of the Vimeo or YouTube video:","http://");if(!a)return;var b=prompt("Enter the aspect ratio of the video:","4:3");if(!b)return;a="[vid="+b+"]"+a+"[/vid]";this.bb_style('',a)};h.prototype.insert_image=function(a){var b=[].slice.call(arguments),a=b.length?b[0]:null,alt=b.length>1?b[1]:null,large=b.length>2?b[2]:null;if(!a){a=prompt("Enter the web address of the image:","http://");if(!a)return}if(!alt){alt=prompt("Enter a short description for the image:","");if(!alt)alt=''}if(large===null){large=prompt("Show a large version of the image?","Yes").toLowerCase()=='yes'}large=large?'large-':'';a="["+large+"img="+a+"]"+alt+"[/"+large+"img]";this.bb_style('',a)};return h})();
