
$(document).ready(function(){$('#additional-content').addClass('active');$('#additional-content li:first-child .collapse').show();$('#additional-content h3').click(function(){$(this).parent().toggleClass('open');$(this).parent().children('.collapse').slideToggle(100,function(){$('#additional-content .overlay-bottom').css('bottom',0);});});$('#events-multiview .choose-view a').click(function(){var clicked=$(this).attr('class');var current=$('#events-multiview .open').attr('id');if((clicked=='list'&&current=='events-list')||(clicked=='calendar'&&current=='events-cal')){return false;}
$('#events-multiview #events-cal, #events-multiview #events-list').toggleClass('open').toggle();});$('#partners .container').each(function(){if($(this).find('.expand-me').length>0){$(this).addClass('active');}});$('#partners .slides, #broadcast-partners .slides').addClass('active');$('#partners .slides li:first-child, #broadcast-partners .slides li:first-child').show();$('#partners .active h2, #partners .active .view-more').click(function(){var expander=$(this).parent().children('.expand-me');var to_change=$(this).parent().find('.view-more span');if(expander.is(':visible')){expander.slideUp(100);to_change.text("Show more");return;}
$('#partners .expand-me').slideUp(100);$('#partners .view-more span').text("Show more");$(this).parent().children('.expand-me').slideDown(100);to_change.text("Hide");});$('#top10').addClass('active');$('#top10 a.view-more').click(function(){$('#top10 table').toggle();$(this).children('span').text(($(this).children('span').text()=="Top 10 Women")?"Top 10 Men":"Top 10 Women");});$('.result_search_dropdown').change(function(){search_value=$(this).val();if(search_value!=''){$('#search_races_form').submit();}});$('#poll_form').submit(function(){post_url='/polls/poll_ajax/'+$('#poll_slug').val();$.ajax({type:'POST',url:post_url,data:$(this).serialize(),success:function(){$('.poll_result_line').show();$('#poll_form').hide();}});return false;});$('.ajax-cal th a').live('click',function(){var ajax_url=$(this).attr('href');$.ajax({type:'GET',url:ajax_url,success:function(data){$('.ajax-cal').html(data);$('.calendar_event').tooltipper();}});return false;});$('.slideshow').gallery();$('#events-home').gallery({pause:10000});$('#home-hero').gallery({controls:'hero',pause:5000});$('#partners .container, #broadcast-partners').gallery({controls:false,pause:2000,fade:1000});$('#sidebar-right #sponsors').gallery({pause:5000});$('.shop .slideshow').gallery({controls:false});$('#latest-news').categoriser();$('#rowing-home').categoriser({auto:true});$('.calendar_event').tooltipper();$('#world-best-times tbody tr').tooltipper();$('.tabbed').tabber();});

jQuery.fn.gallery=function(options){var defaults={fade:500,pause:3000,method:'fade',auto:true,controls:true};var options=$.extend(defaults,options);this.each(function(){that=$(this);var current=1;var interval;var slideshow=that.find(".slides");var slides=slideshow.children("li");var number=slides.length;if(number<2){return;}
that.find(".paging").remove();if(options.controls=='hero'){that.find(".controls").remove();slideshow.after("<ul class='controls'></ul>");controls=that.find('.controls');for(var i=1;i<=number;i++){var text=$(slides[i-1]).find('h2 span').text();var url=$(slides[i-1]).find('a').attr('href');if(i==1){controls.append("<li class='current'><a href='"+url+"'>"+text+"</a></li>");}else{controls.append("<li><a href='"+url+"'>"+text+"</a></li>");}}
controls.find("li a").mouseover(function(){var pos=$(this).parent().index()+1;options.auto=false;change(pos);});}else if(options.controls){slideshow.after("<ul class='paging'></ul>");var controls=that.find(".paging");for(var i=1;i<=number;i++){controls.append((i==1)?"<li class='current'><a>"+i+"</a></li>":"<li><a>"+i+"</a></li>");}
controls.find("li a").click(function(){if(options.auto='semi'){options.auto=false;}
change(parseInt($(this).text()));});}
function change(next){if(next==current){return;}
if(!next){var next=(current===number)?1:current+1;}
var slide_now=$(slides[current-1]);var slide_next=$(slides[next-1]);slide_next.css('zIndex',5).show();if(options.method=="slide"){slide_now.css('zIndex',10).slideUp(options.fade);}else{slide_now.css('zIndex',10).fadeOut(options.fade);}
if(options.controls){controls.children('li').removeClass('current');controls.children('li:nth-child('+next+')').addClass('current');}
current=next;timer();}
function timer(){clearInterval(interval);if(!options.auto){return;}
interval=setInterval(function(){change();},options.pause+options.fade);}
timer();});return this;};

jQuery.fn.categoriser=function(options){var defaults={fade:500,pause:5000,auto:false};var options=$.extend(defaults,options);this.each(function(){that=$(this);var current=1;var interval;var slideshow=that.find(".slides");var slides=slideshow.children("li");var number=slides.length;if(number<2){return false;}
var controls=that.find(".categories");controls.find("li a").click(function(){var pos=$(this).parent().index()+1;if(options.auto='semi'){options.auto=false;}
change(pos);});function change(next){if(next==current){return;}
if(!next){var next=(current===number)?1:current+1;}
var slide_now=$(slides[current-1]);var slide_next=$(slides[next-1]);slide_next.css('zIndex',5).show();slide_now.css('zIndex',10).fadeOut(options.fade);controls.children('li').removeClass('current');controls.children('li:nth-child('+next+')').addClass('current');current=next;timer();}
function timer(){clearInterval(interval);if(!options.auto){return;}
interval=setInterval(function(){change();},options.pause+options.fade);}
timer();});return this;};

jQuery.fn.tooltipper=function(options){var defaults={targ:'body',to_clone:false};var options=$.extend(defaults,options);this.each(function(){$(this).hover(function(){var to_clone=(options.to_clone)?$(this).find(options.to_clone):$(this);to_clone.clone().appendTo($(options.targ)).attr('class','tooltip');$('.tooltip td').each(function(){$(this).replaceWith("<div class='td'>"+$(this).html()+"</div>");});$('.tooltip').replaceWith("<div class='tooltip'>"+$('.tooltip').html()+"</div>").hide();$('body').mousemove(function(e){$('.tooltip').css({'left':e.pageX,'top':e.pageY}).show();});},function(){$('.tooltip').remove();$('body').unbind('mousemove');});});return this;};

jQuery.fn.tabber=function(options){var defaults={tab_position:'after',tab_element:'.content h2',tab_label:'h3',leave_label:true};var options=$.extend(defaults,options);this.each(function(){that=$(this);var tabs=that.find('.tab');var tab_count=$(tabs).length;if(tab_count<2){return;}
$(tabs).hide();$(tabs[0]).show();var tab_ele="<ul class='tabs'></ul>";var targ_ele=that.find(options.tab_element);if(options.tab_position=='after'){$(targ_ele).after(tab_ele);}else if(options.tab_position=='before'){$(targ_ele).before(tab_ele);}else if(options.tab_position=='start'){$(targ_ele).prepend(tab_ele);}else{$(targ_ele).append(tab_ele);}
tab_ele=that.find('ul.tabs');$(tabs).each(function(){var label=$(this).find(options.tab_label+':first-child').text();label=(label)?label:'Unlabelled';tab_ele.append('<li><span>'+label+'</span></li>');if(!options.leave_label){$(this).find(options.tab_label).remove();}});tab_ele.children('li').click(function(){$(tabs).hide();pos=$(this).index();$(tabs[pos]).show();});});return this;};

