// JavaScript Document
$(document).ready(function() {
    $('.tabSelection ul > li:last').addClass("last");
    $('.tabSelection ul > li:last').addClass("active");
    
    $('.tabContent').find('.item:last').addClass("on");

    //$('.tabWrapper .tabContent > .item:first').addClass("on");

    $('.tabSelection ul > li').click(function() {

        //adding the tracking code for the tab and should be removed after race finish
        if ($(this)[0] == $('.tabSelection ul > li')[0]) pageTracker._trackPageview('/sydney-running-festival/training-tab')
        else if ($(this)[0] == $('.tabSelection ul > li')[1]) pageTracker._trackPageview('/sydney-running-festival/social-tab');

        var itemClassName = $(this).attr("class").split(" ");
        $('.tabSelection ul > li').removeClass("active");

        $(this).addClass("active");
        $('.tabContent .item').removeClass("on");
        $('.tabContent').find('.' + itemClassName[0] + 'Content').parent().addClass("on");
    });

});

/************************************************************************************************
quickTipsmonials Rotator
*************************************************************************************************/
$(document).ready(function() {
    var $curr = $(".frameRotator  ul.rotatorList li:first.rotatorItem").fadeIn();
    var $totSlide = $('.frameRotator  ul.rotatorList li.rotatorItem').size();

    function setNavButtons() {
        if ($curr.index() > 0 && $curr.index() < ($totSlide - 1)) {
            $(".quickTipsNavigation span.prev").show();
            $(".quickTipsNavigation span.next").show();
        }
        else if ($curr.index() == 0) {
            $(".quickTipsNavigation span.prev").hide();
            $(".quickTipsNavigation span.next").show();
        }
        else if ($curr.index() == ($totSlide - 1)) {
            $(".quickTipsNavigation span.prev").show();
            $(".quickTipsNavigation span.next").hide();
        }
    }
    $('.quickTips .quickTipsNavigation')
		  	.prepend('<span class="pngFix prev" title="Prev">Prev</span>')
    		.append('<span class="pngFix next" title="Next">Next</span>');

    $(".quickTipsNavigation span.prev").click(function() {
        $curr = $curr.prev();
        if ($curr.index() == -1) return false;

        $(".frameRotator  ul.rotatorList li.rotatorItem").fadeOut("slow").removeClass("active");
        $curr.fadeIn("slow").addClass("active");

        setNavButtons();
    });
    $(".quickTipsNavigation span.next").click(function() {
        $curr = $curr.next();
        $(".frameRotator  ul.rotatorList li.rotatorItem").fadeOut("slow").removeClass("active");
        $curr.fadeIn("slow").addClass("active");
        setNavButtons();
    });

    if ($totSlide > 1) {
        $(".quickTipsNavigation span.next").show();
    } else {
        $(".quickTipsNavigation span.next").hide();
    }

    if ($curr.index() == 0) {
        $(".quickTipsNavigation span.prev").hide();
    }

});
