var phpjs=function(){var public={ucwords:function(str){return(str+'').replace(/^(.)|\s(.)/g,function($1){return $1.toUpperCase();});}};return public;}();(function($){$.fn.toco=function(runners,settings){function getRegexes(){var exprList=[];var chunk=[];for(var runner in runners){if(runner=='_length')continue;var rname=(runners[runner][4]).toLowerCase().replace("'","'?");chunk.push(rname);if(chunk.length>=config.regexLength){exprList.push(new RegExp(chunk.join("|"),'gi'));chunk=[];};};if(chunk.length){exprList.push(new RegExp(chunk.join("|"),'gi'));};return exprList;};function adaptContent(found,offset,subject){if(!found.match(/^[A-Z]/)||subject.toString().substring(offset+found.length,offset+found.length+1).match(/[a-z]/i)){return found;};numLinksAdded++;var key=found.toLowerCase().replace(/[^a-z ]/g,'');var descriptor='horse-racing|'+runners[key][1]+'|'+runners[key][0]+'-'+runners[key][2].replace('-','')+'|to-win';;var runner_idx=runners[key][3];var span='<span'+' class="'+config.highlightStyle+'"'+' rel="'+descriptor+'"'+' index="'+runner_idx+'"'+'>'+found+'</span>';return span;};function getScrollXY(){var scrOfX=0,scrOfY=0;if(typeof(window.pageYOffset)=='number'){scrOfY=window.pageYOffset;scrOfX=window.pageXOffset;}else if(document.body&&(document.body.scrollLeft||document.body.scrollTop)){scrOfY=document.body.scrollTop;scrOfX=document.body.scrollLeft;}else if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop)){scrOfY=document.documentElement.scrollTop;scrOfX=document.documentElement.scrollLeft;};return[scrOfX,scrOfY];};function getEventDisplayFromDescriptor(descriptor){descriptor=descriptor.split(/\|/);the_date=Date.parse(descriptor[1]).toString('dS MMM');the_event=descriptor[2].split('-');the_time=the_event.pop().replace(/^([0-9]{2})([0-9]{2})/,'$1:$2');the_course=phpjs.ucwords(the_event.join(' ')).substring(0,4);return the_date+' '+the_time+' '+the_course;};function getMoreData(ev){var runner;if(ev.srcElement){runner=ev.srcElement.getAttribute('rel');}else{runner=ev.currentTarget.getAttribute('rel');};$('#'+config.bubblPrefix+'MoreInfo').html('Loading...');$.getJSON(vhttpdir+'/data/runner.js.php?h='+escape(runner),function(data){var runner_info='<strong>Jockey:</strong> '+data.JockeyName+'<br />'+'<strong>Trainer:</strong> '+data.TrainerName+'<br />'+'<strong>Age/Wt:</strong> '+data.Age+'y '+data.Weight+'<br />'+'<strong>Form:</strong> '+data.RecentForm+'<br />'+'<strong>Days since last run:</strong> '+data.DaysSinceLastRun;if($('#'+config.bubblPrefix+'BubblBody H3').text()!=runner){return;};if($('#'+config.bubblPrefix+'BubblFoot').attr('src').match(/_tri.png/)){var t=parseInt($bubbl.css('top'))-58;$bubbl.animate({'top':t},500);};$('#'+config.bubblPrefix+'MoreInfo').animate({'height':'72px'},500,function(){$('#'+config.bubblPrefix+'MoreInfo').hide().html(runner_info).fadeIn();});});return false;};function buildBubbl(data){$bubbl_body=$('#'+config.bubblPrefix+'BubblBody');$bubbl_body.empty();if(data.Error||!data.Selections[0].Price||!data.Selections[0].Price.length){$bubbl_body.html("<h3>Oooh, fell at the final hurdle :(</h3><center>Unfortunately, we couldn't get prices for this runner. Please try again later.</center>");}else{runner=data.Selections[0];var the_horse=document.createElement('h3');the_horse.innerHTML=runner.OutcomeName;var the_event=document.createElement('p');the_event.innerHTML=getEventDisplayFromDescriptor(descriptor);var more_data=document.createElement('div');more_data.id=config.bubblPrefix+'MoreInfo';var more_data_link=document.createElement('a');more_data_link.href=vhttpdir+'/racing/search.php?txtSearch='+escape(runner);more_data_link.target='_blank';$(more_data_link).attr('rel',runner.OutcomeName).text('Click for horse statistics').click(getMoreData);more_data.appendChild(more_data_link);var the_bookie=document.createElement('img');the_bookie.id=config.bubblPrefix+'Bookie';the_bookie.src=config.imagePath+'/../bookmakers/grid/'+runner.Price[0].BookmakerID+'.png';the_bookie.alt=runner.Price[0].BookmakerName;var the_price=document.createElement('div');the_price.id=config.bubblPrefix+'Price';price_string=runner.Price[0].Numerator+'-'+runner.Price[0].Denominator;if(price_string=='0-0'){price_string='SP';}else if(price_string=='1-1'){price_string='EVENS';};$(the_price).text(price_string);var the_button=document.createElement('img');the_button.id=config.bubblPrefix+'Button';the_button.src=config.imagePath+'/../buttons/bet39x35.png';the_button.alt='Bet Now';var the_button_link=document.createElement('a');the_button_link.href=runner.Price[0].URL+'&source=toco';the_button_link.target='_blank';if(runner.Price[0].SlipWidth>0){the_button_link.onclick=function(){popup(this.href,runner.Price[0].SlipWidth,runner.Price[0].SlipHeight);return false;};};the_button_link.appendChild(the_button);var the_price_container=document.createElement('div');the_price_container.id=config.bubblPrefix+'Bet';the_price_container.appendChild(the_bookie);the_price_container.appendChild(the_price);the_price_container.appendChild(the_button_link);$bubbl.attr('rel',runner.OutcomeName);$bubbl_body.append(the_horse).append(the_event).append(more_data).append(the_price_container);};};function showBubbl(ev){clearTimeout(timeout);current_el=ev.target;timeout=setTimeout(function(){if($bubbl.attr('rel')==$(current_el).text()){positionAndShow(ev);return;};descriptor=$(current_el).attr('rel');runner_idx=$(current_el).attr('index');var pw='http://pricewise.gg.com/v3/?descriptor='+descriptor+'&runner='+runner_idx+'&bookmaker='+config.bookie+'&jsonp=?';$.getJSON(pw,function(data){buildBubbl(data);positionAndShow(ev);});},200);};function positionAndShow(ev){elXY=[ev.pageX,ev.pageY];docXY=getScrollXY();var ttTop=parseInt(elXY[1]-($bubbl.height()+5));var ttLeft=parseInt(elXY[0]-($bubbl.width()/2));if(ttTop-docXY[1]<0){ttTop+=$bubbl.height()+(current_el.offsetHeight+10);$('#'+config.bubblPrefix+'BubblHead').attr({'src':config.imagePath+'/top_tri.png','height':38});$('#'+config.bubblPrefix+'BubblFoot').attr({'src':config.imagePath+'/bottom.png','height':16});}else{$('#'+config.bubblPrefix+'BubblHead').attr({'src':config.imagePath+'/top.png','height':16});$('#'+config.bubblPrefix+'BubblFoot').attr({'src':config.imagePath+'/bottom_tri.png','height':38});};if($.browser.msie){$bubbl.css({'left':ttLeft,'top':ttTop}).show();}else{$bubbl.css({'left':ttLeft,'top':ttTop}).fadeIn(400);};};function hideBubbl(ev){clearTimeout(timeout);timeout=setTimeout(function(){if($.browser.msie){$bubbl.hide();}else{$bubbl.fadeOut(200);};},500);};function keepBubbl(){clearTimeout(timeout);};var slowNodeList=[];function seekNodesSlow(pNode){if(pNode.nodeType==3){if(pNode.length>=config.minNodeLength){slowNodeList.push(pNode);};}else if(pNode.hasChildNodes()){var childs=pNode.childNodes;for(var i=0;i<childs.length;i++){seekNodesSlow(childs[i]);};};};function getTextNodes(context){var nodeList=[];if(document.evaluate){var contentTextNodes=document.evaluate('.//text()[normalize-space(.) != ""]',context,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);for(var i=0,l=contentTextNodes.snapshotLength;i<l;i++){nodeList.push(contentTextNodes.snapshotItem(i));};}else{seekNodesSlow(context);nodeList=slowNodeList;};return nodeList;};var config={'minNodeLength':5,'forbiddenAncestors':["TEXTAREA","SCRIPT","STYLE","IFRAME","INPUT","SELECT","FORM"],'regexLength':30,'highlightStyle':'toco','bubblPrefix':'toco','imagePath':vimagedir+'/toco','bookie':-1};if(settings)$.extend(config,settings);var fish,frag,linksBefore;var $bubbl;var numLinksAdded=0;var timer,timeout;var re=getRegexes();this.each(function(){var contentTextNodes=getTextNodes(this);for(var i=0,n=contentTextNodes.length;i<n;i++){textNode=contentTextNodes[i];txtContent=textNode.data;if(txtContent.replace(/[^a-z]/gi,'').length<config.minNodeLength){continue;};forbidden=false;node=textNode;while(p=node.parentNode){if(p.tagName){if($.inArray(p.tagName.toUpperCase(),config.forbiddenAncestors)!=-1){forbidden=true;break;};if($(p).hasClass('toco')){forbidden=true;break;};};node=p;};if(forbidden)continue;txtContent=textNode.data.replace(/\s+/g,' ');linksBefore=numLinksAdded;for(var j=0,k=re.length;j<k;j++){txtContent=txtContent.replace(re[j],adaptContent);};if(linksBefore!=numLinksAdded){if(!fish){fish=document.createElement('div');};fish.innerHTML=txtContent;var frag=document.createDocumentFragment();for(var j=0;j<fish.childNodes.length;j++){fishNode=fish.childNodes[j].cloneNode(true);frag.appendChild(fishNode);};textNode.data="";textNode.parentNode.insertBefore(frag,textNode.nextSibling);};};});$('.'+config.highlightStyle).mouseenter(showBubbl).mouseleave(hideBubbl);var bubbl=document.createElement('div');bubbl.id=config.bubblPrefix+'Bubbl';bubblHead=document.createElement('img');bubblHead.id=config.bubblPrefix+'BubblHead';bubblHead.src=config.imagePath+'/top.png';bubblBody=document.createElement('div');bubblBody.id=config.bubblPrefix+'BubblBody';bubblBody.innerHTML='Loading...';bubblFoot=document.createElement('img');bubblFoot.id=config.bubblPrefix+'BubblFoot';bubblFoot.src=config.imagePath+'/bottom_tri.png';$bubbl=$(bubbl).append(bubblHead).append(bubblBody).append(bubblFoot).hide().appendTo('BODY').hover(keepBubbl,hideBubbl);return this;};})(jQuery);$(function(){if(parent.location.protocol=='http:'&&!tocodisable){$.getJSON(vhttpdir+'/data/racing.js.php',function(data){var bookie=(typeof iOddsBookie!="undefined")?iOddsBookie:oddsbookie;if((typeof forcebookie!="undefined")&&forcebookie)bookie=forcebookie;$('#Content,#content,#pageBody').toco(data,{'bookie':bookie});});};});
