var butns_code=(function(){var $=function(){var elements=[];for(var i=0;i<arguments.length;i++){var element=arguments[i];if(typeof element=='string'){element=document.getElementById(element)}if(arguments.length==1){return element}elements.push(element)}return elements};return{target_name:"butns_codetarget",target_element:null,query_name:"butns_query",query_element:null,userlink_query_name:"butns_userlinkquery",userlink_query_element:null,links:[],reset:function(){try{links.clear()}catch(err){}},firefoxFix:function(){element=document.getElementById("form_main");if((navigator.userAgent.indexOf("Firefox")!=-1)||(navigator.userAgent.indexOf("Mozilla")!=-1)){element.setAttribute("autocomplete","off")}},insertQuotes:function(){var quotes=[["'Butns, Changing the common understanding of what a hyperlink is'","Quote via twitter"],["'butns.com enables multiple choice for hyperlinks. Will it revolutionize the blogging world?'","Quote via twitter"],["'This is an interesting idea, multiple links in one hyperlink'","Quote via twitter"],["'... cool startup Butns.com - More intelligent Hyperlinks ...'","Quote via twitter"],["'Butns - very cool new app...lets you add more destinations to links for more info'","Quote from brainpicker via twitter"],["'Looking forward to trying out butns.com on my blog'","Quote via twitter"]];var elements=[[document.getElementById("quotebox1"),document.getElementById("quotebox1_sig")],[document.getElementById("quotebox2"),document.getElementById("quotebox2_sig")],[document.getElementById("quotebox3"),document.getElementById("quotebox3_sig")]];for(var i=0;i<3;i++){var randIndex=Math.floor(Math.random()*quotes.length);elements[i][0].innerHTML=quotes[randIndex][0];elements[i][1].innerHTML=quotes[randIndex][1];quotes.splice(randIndex,1)}},randomLogo:function(){var logos=[["http://www.butns.com/images/wordpress_logo_frontpage.png","plugins.html"],];var element=document.getElementById("random_logo");var randIndex=Math.floor(Math.random()*logos.length);element.innerHTML='<a href="'+logos[randIndex][1]+'"><img style="position:relative;top:20px;border:none;" src="'+logos[randIndex][0]+'"/></a>'},clearQueryField:function(){if(!butns_code.query_element){butns_code.query_element=$(butns_code.query_name)}if(butns_code.query_element.value=="Paste word here"){butns_code.query_element.value=""}},clearUserlinkField:function(){if(!butns_code.userlink_query_element){butns_code.userlink_query_element=$(butns_code.userlink_query_name)}if(butns_code.userlink_query_element.value=="Enter specific link"){butns_code.userlink_query_element.value=""}},startMovie:function(){var movieTitleElement=$("butns_movieTitle");var movieElement=$("butns_movie");movieTitleElement.style.display="none";movieElement.style.display="block"},hideMovie:function(){var movieTitleElement=$("butns_movieTitle");var movieElement=$("butns_movie");movieTitleElement.style.display="block";movieElement.style.display="none"},toggleDisplay:function(elementName){element=$(elementName);if(element.style.display=='none'){element.style.display='block'}else if(element.style.display=='block'){element.style.display='none'}},textToInput:function(inputElement,textElement){var newElementInput=document.createElement('input');newElementInput.type='text';newElementInput.value=unescape(inputElement.value);newElementInput.style.width='10em';textElement.innerHTML="<br/>";textElement.appendChild(newElementInput)},printLinkObject:function(linkObject){var icon=linkObject.icon;var label=linkObject.label;var output=linkObject.link;if(icon!=""&&label!=""){output+="{icon:="+icon+",label:="+label+"}"}else if(icon!=""){output+="{icon:="+icon+"}"}else if(label!=""){output+="{label:="+linkObject.label+"}"}return output},parseLinkString:function(link){var label="";var icon="";if(link[link.length-1]=='}'){var pos=link.lastIndexOf('{');if(pos!=-1){var modifiers=link.substr(pos+1,link.length-pos-2);var modifierList=modifiers.split(',');for(var i=0;i<modifierList.length;i++){var modifierPair=modifierList[i].split(":=");var modifier=modifierPair[0];var modifierValue=modifierPair[1];if(modifier=="label"){label=modifierValue}else if(modifier=="icon"){icon=modifierValue}}link=link.substr(0,pos)}}return{link:link,label:label,icon:icon}},formatLabel:function(label){var skipSize=12;var breakIndex=0;while(true){breakIndex+=skipSize;if(breakIndex>label.length)break;label=label.substr(0,breakIndex)+'<br>'+label.substr(breakIndex);breakIndex+=4}return label},addLink:function(element){setTimeout(function(){butns_code.addLink_inner(element)},1)},addLink_inner:function(element){var link=element.value;var label=element.value;label=label.replace("http://","");label=label.replace("www.","");var icon="";label=butns_code.formatLabel(label);var linkNoModifier=link;var splitLink=butns_code.parseLinkString(linkNoModifier);if(splitLink.label=="")splitLink.label=label;linkNoModifier=splitLink.link;icon=splitLink.icon;label=splitLink.label;if(linkNoModifier!=""&&!link.match("http://")){link="http://"+link;linkNoModifier="http://"+linkNoModifier}if(icon===""){icon='http://www.google.com/s2/favicons?domain_url='+linkNoModifier}if(label[label.length-1]=='}'){var pos=label.lastIndexOf('{');if(pos!=-1){label=label.substr(0,pos)}}link=link.replace(/"/g,'\\"');var parent=$('linkbox_userlink_inner');var newElement=document.createElement('div');var newElementInner1=document.createElement('div');newElementInner1.style.cssFloat='left';newElementInner1.style.styleFloat='left';var newElementInput=document.createElement('input');newElementInput.style.verticalAlign='middle';newElementInput.type='checkbox';newElementInput.name="checkbox_link";newElementInput.id="checkbox_link";newElementInput.value=escape(link);newElementInput.checked=true;newElementInput.onclick=function(){butns_code.update(this)};newElementInner1.appendChild(newElementInput);var space=document.createTextNode('\u00a0');var space2=document.createTextNode('\u00a0');newElementInner1.appendChild(space);var newElementImg=document.createElement('img');newElementImg.style.verticalAlign='middle';newElementImg.src=icon;if(icon!="none")newElementInner1.appendChild(newElementImg);newElementInner1.appendChild(space2);var newElementInner2=document.createElement('div');newElementInner2.style.paddingTop='3px';newElementInner2.style.paddingBottom='3px';newElementInner2.style.cssFloat='left';newElementInner2.style.styleFloat='left';newElementInner2.innerHTML=label;var newElementInner3=document.createElement('div');newElementInner3.style.paddingTop='3px';newElementInner3.style.paddingBottom='3px';newElementInner3.style.cssFloat='right';newElementInner3.style.styleFloat='right';try{newElementInner3.style.cursor="pointer"}catch(eOldIEVersion){newElementInner3.style.cursor="hand"}var newElementInner3_img=document.createElement('img');newElementInner3_img.style.paddingTop='3px';newElementInner3_img.src="http://www.butns.com/images/button_rename.png";newElementInner3.appendChild(newElementInner3_img);newElement.appendChild(newElementInner1);newElement.appendChild(newElementInner2);newElement.appendChild(newElementInner3);newElement.style.clear='both';newElement.style.position='relative';newElement.style.backgroundColor='green';parent.appendChild(newElement);var newElement2=document.createElement('div');newElement2.style.display='none';var newElement2Inner=document.createElement('input');newElement2Inner.type="text";newElement2Inner.value="";newElement2Inner.style.width="12em";newElement2.appendChild(newElement2Inner);var newElement2Inner2=document.createElement('div');newElement2Inner2.style.paddingTop='3px';newElement2Inner2.style.paddingBottom='3px';newElement2Inner2.style.cssFloat='right';newElement2Inner2.style.styleFloat='right';try{newElement2Inner2.style.cursor="pointer"}catch(eOldIEVersion){newElement2Inner2.style.cursor="hand"}var newElement2Inner2_img=document.createElement('img');newElement2Inner2_img.style.paddingTop='3px';newElement2Inner2_img.src="http://www.butns.com/images/enter_button.gif";newElement2Inner2.appendChild(newElement2Inner2_img);newElement2.appendChild(newElement2Inner2);parent.appendChild(newElement2);newElementInput.checked=true;newElementInner3.onclick=function(){newElement2.style.display="block";splitLink=butns_code.parseLinkString(unescape(newElementInput.value));if(splitLink.label==""){newElement2Inner.value=unescape(newElementInput.value)}else{newElement2Inner.value=splitLink.label}newElement2Inner.select();newElement2Inner.focus();newElementInner3.style.display="none";newElementInner2.innerHTML="Change link label:";var index=butns_code.links.indexOf(newElementInput.value);butns_code.links.splice(index,1)};var f=function(){newElement2.style.display="none";splitLink=butns_code.parseLinkString(unescape(newElementInput.value));splitLink.label=newElement2Inner.value;newElementInput.value=butns_code.printLinkObject(splitLink);newElementInner3.style.display="block";newElementInner2.innerHTML=butns_code.formatLabel(splitLink.label);setTimeout(function(){element.focus();butns_code.update(newElementInput)},50)};newElement2Inner2.onclick=f;newElement2Inner.onchange=f;element.value="Enter specific link";setTimeout(function(){element.focus();butns_code.update(newElementInput)},50)},update:function(element){var i;elementValue=element.value;elementName=element.name;if(elementName){elementsSameName=document.getElementsByName(elementName);for(i=0;i<elementsSameName.length;i++){elementSameName=elementsSameName[i];if(element!==elementSameName&&elementSameName.value==element.value){elementSameName.checked=element.checked}}}if(!butns_code.target_element){butns_code.target_element=$(butns_code.target_name)}if(!butns_code.query_element){butns_code.query_element=$(butns_code.query_name)}if(!butns_code.userlink_query_element){butns_code.userlink_query_element=$(butns_code.userlink_query_name)}if(!(butns_code.query_element.value=="Paste word here"||butns_code.query_element.value==="")){var queryComplete=escape(butns_code.query_element.value);var queryShort=queryComplete;var regExp=new RegExp('href="[^"]*"[^>]*>([^<]*)<','i');var linkMatch=regExp.exec(butns_code.query_element.value);if(linkMatch){queryShort=linkMatch[1]}var queryShortList=unescape(queryShort).split(" ");var queryShortHtml='<span style="white-space:nowrap;">'+queryShort;if(queryShortList.length>1)queryShortHtml=queryShortList.slice(0,-1).join(" ")+' <span style="white-space:nowrap;">'+queryShortList.slice(-1);var style="";radio_style_elements=document.getElementsByName('radio_style');for(i=0;i<radio_style_elements.length;i++){if(radio_style_elements[i].checked){style=radio_style_elements[i].value}}if(butns_code.links.length===0){var linkArray={};checkbox_link_elements=document.getElementsByName('checkbox_link');for(i=0;i<checkbox_link_elements.length;i++){var value=checkbox_link_elements[i].value;if(!linkArray[value]&&checkbox_link_elements[i].checked){butns_code.links.push(value);linkArray[value]=true}}}else if(element.name==="checkbox_link"){var value=element.value;var index=-1;for(var j=0;j<butns_code.links.length;j++){if(butns_code.links[j]==value){index=j}}if(index===-1){butns_code.links.push(value)}else{butns_code.links.splice(index,1)}}var linkCounter=butns_code.links.length;var linkStr=butns_code.links.join(",");for(var j=0;j<butns_code.links.length;j++){if(unescape(butns_code.links[j])[0]=="{"){linkCounter-=1}}output='<a class="butns" href="http://www.butns.com?q='+queryComplete+'&amp;l='+escape(linkStr)+'&amp;d='+style+'">'+queryShortHtml+'<script type="text/javascript" language="javascript" src="http://www.butns.com/butns.js"></script><iframe style="height:12px;width:'+(linkCounter*(8+2)+2+1)+'px" scrolling="no" frameborder="0" src="http://www.butns.com/noscript.php?q='+escape(butns_code.query_element.value)+'&amp;l='+escape(linkStr)+'"></iframe></span></a>';butns_code.target_element.value=output;butns_code.target_element.focus();butns_code.target_element.select();butns_code.example=$('butns_example');butns_code.example.innerHTML="Your butns link:<br /><center>"+output+"</center><br />";setTimeout(function(){butns.findTags()},50)}else{butns_code.target_element.value=""}},update_box:function(element){children=element.parentNode.childNodes;for(var i=0;i<children.length;i+=1){if(children[i].name=="checkbox_link"){if(children[i].checked){children[i].checked=false}else{children[i].checked=true}butns_code.update(children[i])}else if(children[i].name=="radio_style"){children[i].checked=true;butns_code.update(children[i])}}}}})();function onYouTubePlayerReady(playerId){var ytplayer=document.getElementById("myytplayer");ytplayer.addEventListener("onStateChange","onYouTubeVideoStop");ytplayer.playVideo()}function onYouTubeVideoStop(state){if(state===0){butns_code.hideMovie()}}
