$(function(){var $ctr=$('#container'),priorityArray=[],priority='',$ctx='',spanClassName='',firstBreakVar='',classArray=[],spanLength=null,phraseLog=$('#phraseLog'),phraseArray=[],isTerm=false,topArray=[];var $mostCommWords=$('#dispWords h3'),$userPhraseList=$('#dispWords h4'),$myDispWordSelectors=$('#dispWords h3,#dispWords h4');var $dispWords=$('#dispWords'),$dispStats=$('#dispStats'),$dispWhat=$('#dispWhat'),$tabMenuLink=$('#tabMenu a');$dispWords.data('currentState','on');$dispStats.data('currentState','off');$dispWhat.data('currentState','off');$mostCommWords.data('currentState','on');$userPhraseList.data('currentState','off');var $nickText=$('#container p.text_nick'),$gordonText=$('#container p.text_gordon'),$davidText=$('#container p.text_david');Array.prototype.remove=function(from,to){var rest=this.slice((to||from)+1||this.length);this.length=from<0?this.length+from:from;return this.push.apply(this,rest)};function indexInArray(arr,val){for(var i=0;i<arr.length;i++){if(arr[i]==val){return i}}return-1}function getColor(p){color=p.css('background-color');if(color=='transparent'||color==''||color=='rgba(0, 0, 0, 0)'){color=p.css('color')}return color}function changePriority(p,width){priorityArray=[];getColor(p);augment(color,width)}function addDots(width){if($('span.dot').is(':visible')){$('span.dot').remove()}priority.append("<span class='dot' />");$('span.dot').css({"left":width})}function addCanvas(){$ctx=$('#augment');if($ctx.is(':visible')){$ctx.remove();$ctr.append('<canvas id="augment"></canvas>');$ctx=$('#augment')}else{$ctr.append('<canvas id="augment"></canvas>');$ctx=$('#augment')}$ctr=$('#container');var $ctxW=$ctr.width(),$ctxH=$ctr.height();$ctx.attr('height',$ctxH);$ctx.attr('width',$ctxW)}function mapTerm(width){wMaker=((width/2)+3);jQuery.each(priority,function(index,priority){position=$(this).position();var top=position.top,left=position.left;left=left+wMaker;top=top-2;priorityArray.push(left,top);topArray.push(top)});addDots(wMaker);scrollTop=$(window).scrollTop()}function mapBeziers(ctx){for(i=0;i<1;i++){var o1=priorityArray[i],o2=priorityArray[i+1];if(o1){ctx.moveTo(o1,o2)}}for(i=0;i<priorityArray.length;i++){var c1='',c2='';var o1=priorityArray[i],o2=priorityArray[i+1];rnd2p=Math.floor(Math.random()*30);rnd3p=Math.floor(Math.random()*200);rnd4p=Math.floor(Math.random()*1000);if((rnd4p)>500){c1=Math.floor((o1)+(rnd2p));c2=Math.floor((o2)-(rnd3p))}else{c1=Math.floor((o1)-(rnd3p));c2=Math.floor((o2)+(rnd2p))}if(priorityArray[i+2]!==undefined){o3=priorityArray[i+2]}else{o3=o1;c1=o1}if(priorityArray[i+3]!==undefined){o4=priorityArray[i+3]}else{o4=o2;c2=o2}ctx.bezierCurveTo(o1,o2,c1,c2,o3,o4);i=i+1}}function drawBeziers(canvas,color){if(canvas){canvas.width=canvas.width;if(canvas.getContext){var ctx=canvas.getContext('2d');ctx.lineWidth=0.8;ctx.globalAlpha=1;ctx.strokeStyle=color;if(color=="rgb(51, 51, 51)"){ctx.strokeStyle='#999999'}ctx.lineJoin="round";ctx.beginPath();mapBeziers(ctx);ctx.stroke()}else{if(!$('#ieBox').length){ieMsg='<div id="ieBox"><p>Hello, we notice that you\'re using Internet Explorer. Unfortunately this site doesn\'t  work fully in IE as it uses the latest web technologies that Microsoft currently don\'t support.</p><p> We\'re working hard to support it, but in the meantime you have three options...</p><ol><li> You might like to try a modern standards-based browser such as <a href="http://www.firefox.com">Firefox</a> or <a href="http://www.google.com/chrome">Chrome</a>.<br/></li><li> Alternatively you could try a bit of software, made by Google, that integrates into Internet Explorer called Google Chrome Frame. In Google\'s own words it &ldquo;seamlessly brings Google Chrome\'s open web technologies and speedy JavaScript engine to Internet Explorer &rdquo;. <a href="#" id="chromeMe">Click here to try it</a><br/></li> <li>If either of the above sound a little terrifying you can continue to view the site without the pretty bezier curves, and no guarantee that anything will work, by <a href="" id="continueAnyway">clicking here</a>.<br/></li> </ol> <div id="closeBox">x</div></div>';$('body').prepend(ieMsg);$('#ieBox').slideDown(250);$('#continueAnyway').click(function(e){e.preventDefault();$('#ieBox').slideUp(250);$('#container').fadeIn();$('#docInfo').fadeIn();$('#what').fadeIn()});$('#chromeMe').click(function(e){e.preventDefault();$('#ieBox').slideUp(250);CFInstall.check({mode:"inline"})});$('#closeBox').click(function(e){e.preventDefault()})}}}}function hideShowLinkage(canvas){if((canvas).is(':visible')){canvas.fadeOut(300)}else{canvas.fadeIn(300)}}function augment(color,width){mapTerm(width);var canvas=document.getElementById('augment');drawBeziers(canvas,color)}function clearCanvas(){var canvas=document.getElementById('augment');if(canvas){canvas.width=canvas.width}}$('#hideShowLinkage').click(function(){hideShowLinkage($ctx);return false});$('#closeInfo').click(function(){if(($(this).html())=="x"){$dHeight=$('#docInfo').height();$('#docInfo').animate({height:25});$(this).html('*').css({"background":"#099F1E"})}else{$('#docInfo').animate({height:$dHeight});$(this).html('x').css({"background":"red"})}return false});$('#whatExpander').toggle(function(e){e.preventDefault();$(this).parent().animate({bottom:'255px'},500,'easeOutExpo')},function(){$(this).parent().animate({bottom:'0px'},250,'easeOutExpo')});$myDispWordSelectors.click(function(e){var myTarg=$(e.target);if(myTarg.text()==$mostCommWords.text()){$comeSlideWithMe=$('#mostCommon')}else if(myTarg.text()==$userPhraseList.text()){$comeSlideWithMe=$('#phraseLog, #phraseForm')}if(myTarg.data('currentState')=='on'){myTarg.data('currentState','off');$comeSlideWithMe.slideUp(350)}else if(myTarg.data('currentState')=='off'){myTarg.data('currentState','on');$comeSlideWithMe.slideDown(350)}});$tabMenuLink.click(function(e){e.preventDefault();var myNewMenuTab=$(e.target),myNewPaneContent=myNewMenuTab.attr('href'),myNewPaneContent=$('#'+myNewPaneContent+''),currSelTab=$tabMenuLink.parent().find('.selected'),currSelPaneContent=currSelTab.attr('href'),currSelPaneContent=$('#'+currSelPaneContent+'');if(myNewPaneContent.data('currentState')=='off'){currSelTab.removeClass();currSelPaneContent.data('currentState','off').fadeOut(150);myNewMenuTab.addClass('selected');myNewPaneContent.data('currentState','on').delay(150).fadeIn(250)}});function leaderVerbosity(){nickArray=$nickText.text().split(" ");gordonArray=$gordonText.text().split(" ");daveArray=$davidText.text().split(" ");var dontgetthis=/\w/;nickArray=$.map(nickArray,function(a){return(a.match(dontgetthis)?a:null)});gordonArray=$.map(gordonArray,function(a){return(a.match(dontgetthis)?a:null)});daveArray=$.map(daveArray,function(a){return(a.match(dontgetthis)?a:null)});var nCount=nickArray.length,gCount=gordonArray.length,dCount=daveArray.length,tCount=nCount+gCount+dCount,nCPerc=(nCount/tCount)*100,gCPerc=(gCount/tCount)*100,dCPerc=(dCount/tCount)*100;function wordCount(idx){var nickTop=nCount+' words<br />'+nCPerc+'%',gordonTop=gCount+' words<br />'+gCPerc+'%',davidTop=dCount+' words<br />'+dCPerc+'%',tooltips=[nickTop,gordonTop,davidTop];return tooltips[idx]}var countPie=new RGraph.Pie('verbiosity',[nCount,gCount,dCount]);countPie.Set('chart.gutter',35);countPie.Set('chart.colors',['#fdb82f','#dc281e','#1c99cf']);countPie.Set('chart.tooltips',wordCount);countPie.Set('chart.tooltips.effect','fade');countPie.Draw()}function goFindBreak(spanClassName){$firstOccurance=$('#container p .'+spanClassName+':first').position();var firstOccTop=$firstOccurance.top,firstOccLeft=$firstOccurance.left;$('html,body').animate({scrollTop:firstOccTop},500,'easeOutExpo')}function breakDown(spanClassName){if($('#breakdown').length||$('#totals').length){$('#totals').remove();$('#breakdown').remove()}var whichTerm='.'+spanClassName,$nickText=$('#container p.text_nick'),$gordonText=$('#container p.text_gordon'),$davidText=$('#container p.text_david'),nicknack=$(whichTerm,$nickText).size(),gordy=$(whichTerm,$gordonText).size(),davo=$(whichTerm,$davidText).size(),totals=nicknack+gordy+davo,multiplier=250/(totals),nicperc=Math.floor(nicknack*multiplier),gorperc=Math.floor(gordy*multiplier),davperc=Math.floor(davo*multiplier);if(totals===0){dataSquizzer='<div id="totals"> ('+totals+') </div>';$('#dispArea .menu_'+spanClassName).parent().append(dataSquizzer);return false}else{dataSquizzer='<div id="totals"> ('+totals+') <a href="#'+spanClassName+'" id="goFindBreak">jump to first instance&gt;&gt;</a></div> <div id="breakdown"><div class="nicBar" style="width:'+nicperc+'px;">'+nicknack+'&nbsp;</div><div class="gorBar" style="width:'+gorperc+'px;">'+gordy+'&nbsp;</div><div class="davBar" style="width:'+davperc+'px;">'+davo+'&nbsp;</div></div>';$('#dispArea .menu_'+spanClassName).parent().append(dataSquizzer);$('#goFindBreak').click(function(e){e.preventDefault();goFindBreak(spanClassName)})}}function firstTermBreakdown(){var debateNumber=$('#debateMenu ul li a.selected').parent().index();if(debateNumber==0){firstBreakVar='priority_9';priority=$('span.priority_9')}if(debateNumber==1){firstBreakVar='priority_3';priority=$('span.priority_3')}if(debateNumber==2){firstBreakVar='priority_5';priority=$('span.priority_5')}if(debateNumber==3){firstBreakVar='x';priority=$('span.priority_x')}spanLength=priority.width()}firstTermBreakdown();function findAndReplace(searchText,replacement,searchNode){if(!searchText||typeof replacement==='undefined'){return}var regex=typeof searchText==='string'?new RegExp(searchText,'gi'):searchText,childNodes=(searchNode||document.body).childNodes,cnLength=childNodes.length,excludes='html,head,style,title,link,meta,script,object,iframe,h1,h2,h3,h4,h5,h6';while(cnLength--){var currentNode=childNodes[cnLength];if(currentNode.nodeType===1&&(excludes+',').indexOf(currentNode.nodeName.toLowerCase()+',')===-1){arguments.callee(searchText,replacement,currentNode)}if(currentNode.nodeType!==3||!regex.test(currentNode.data)){continue}var parent=currentNode.parentNode,frag=(function(){var html=currentNode.data.replace(regex,replacement),wrap=document.createElement('div'),frag=document.createDocumentFragment();wrap.innerHTML=html;while(wrap.firstChild){frag.appendChild(wrap.firstChild)}return frag})();parent.insertBefore(frag,currentNode);parent.removeChild(currentNode)}}function checkPhraseLog(phrase){if($.inArray(phrase,phraseArray)!==-1){alert('The phrase "'+phrase+'" is already listed');return false}else{phraseArray.push(phrase);return true}}function addPhrase(phrase){var phrase=phrase.replace(/^\s+|\s+$/g,""),phrase=phrase.replace(/\s+/g," ");if(checkPhraseLog(phrase)){if(phrase.length>=3){ndxIn=indexInArray(phraseArray,phrase);findAndReplace('\\b'+phrase+'\\b',function(term){isTerm=true;return'<span class="userPriority_'+ndxIn+'">'+term+'</span>'},(document.getElementById('container')))}if(phrase.length<3){alert("Please search for word(s) containing three letters or more...");return false}rm='<a class="menu_removePhrase" href="#">x</a>';spCls="userPriority_"+ndxIn;priority=$('span.'+spCls);spanLength=priority.width();if(isTerm){phraseLog.append('<li><span class="menu_'+spCls+'">'+phrase+'</span>'+rm+'</li>');breakDown(spCls);changePriority(priority,spanLength)}else{phraseLog.append('<li class="notFound"><span class="menu_'+spCls+'">'+phrase+' not found</span>'+rm+'</li>')}isTerm=false}}$('#phraseForm').submit(function(phrase){phrase=$('#phrase').val();addPhrase(phrase);$('#phrase').val('');return false});$('.menu_removePhrase').live('click',function(){$span=$(this).parent().find("span");cls=$span.attr("class");txt=$span.text();clsAr=cls.split('_');ndxToRemove=clsAr[2];toMash=$(".userPriority_"+ndxToRemove);toMash.replaceWith(txt);phraseArray.remove(ndxToRemove);$(this).parent().remove();clearCanvas();return false});$('span').live('click',function(e){var $targ=$(e.target);cls=$targ.attr("class");parCls=$targ.parent().attr('class');if(parCls!='notFound'){classArray=cls.split('_');ind=classArray[0];if(ind==="menu"){if(classArray[1]==="removePhrase"){return false}spanClassName=classArray[1]+"_"+classArray[2]}else{spanClassName=this.className}priority=$('span.'+spanClassName);breakDown(spanClassName);spanLength=$(this).width();changePriority(priority,spanLength)}});color=getColor(priority);$('h1').fadeIn("slow",function(){addCanvas();augment(color,spanLength);breakDown(firstBreakVar)})});
