var csrf_token = '';
var alli =
{
    banner  : {
        refresh : function(size, url, id) {
            $("#" + id).load("/ajax/reloadBanner?size=" + size + "&url=" + url);
        }
    },
    rating  : {
        submit : function(rating, type, id) {
            var args = '?rating=' + rating + '&type=' + type + '&id=' + id; 
            $('#guff').load("/ajax/rate" + args);
        }
    },
    gallery  : {
        show : function(show, max, id) {
            $('#gallery_start_' + id).hide();
            for(var i = 0; i <= max; i++) {
                $('#gallery_slide_' + i + '_' + id).hide();
            }
            $('#gallery_slide_' + show + '_' + id).show();
        }

    },
    tourSidebar: {
        update : function(args, listid) {
            $("#" + listid).load("/ajax/tourSidebar" + args);
        }
    },
    related : {
        update : function(args, listid) {
            $("#" + listid).load("/ajax/relatedList" + args);
        }
    },
    homepage: {
        update : function(args, listid) {
            $("#" + listid).load("/ajax/homepageList" + args);
        }
    },
    highlights: {
        update : function(args, listid) {
            $("#" + listid).load("/ajax/highlightList" + args);
        }
    },
    articles : {
        update : function(args, listid) {
            $("#" + listid).load("/ajax/articleList" + args);
        }
    },
    mmvs: {
        update : function(args, listid) {
            $("#" + listid).load("/ajax/mmvList" + args);
        }
    },
    galleries : {
        update : function(args, listid) {
            $("#" + listid).load("/ajax/galleryList" + args);
        }
    },
    videos: {
        update : function(args, listid) {
            $("#" + listid).load("/ajax/videoList" + args);
        },
        changeVideo: function (video_id, embed, track_img, type, track_id, title) {
           /* Note we don't use jquery goodness here - stupid ooyala */
           document.getElementById(video_id).setQueryStringParameters({embedCode:embed, wmode: 'transparent'});
           
           /* Also update the url of our tracking pixel */
           $('#' + track_img).attr("src", "/track?type=" + type + "&i=" + track_id);
           $('#video_title').html(title);
        },
        videoCallback: function(playerId, eventName, eventArgs) {
            switch(eventName) {
                case 'adStarted':
                $('#other_video_tracking_pixel').html('<img src="http://b.scorecardresearch.com/b?c1=1&c2=3000055&c3=10136657&c5=010000"/>');
/*
                    COMSCORE.beacon({
                     c1:1,
                     c2:'3000055',
                     c3:'10136657',
                     c5:'010000'
                    });
*/
                    break;
                case 'embedCodeChanged':
                case 'stateChanged':
                    if(eventArgs.state == 'playing' &&
                     document.getElementById(playerId).getPlayheadTime() == 0) {
/*
                        COMSCORE.beacon({
                         c1:1,
                         c2:'3000055',
                         c3:'10136657',
                         c5:'020000'
                        });
*/
                $('#other_video_tracking_pixel').html('<img src="http://b.scorecardresearch.com/b?c1=1&c2=3000055&c3=10136657&c5=020000"/>');
                    }
                    break;
            }
        }
    },
    search :
    {
        searchBox : function(placeholder, index) {
            var $boxes = $('.search-field');
 
            $boxes.each(function (i, box){
                var placeholder = box.placholder || box.value || box.title || placeholder;
                $(box)
                    .bind('focus', onFocus)
                    .bind('blur', onBlur)
                    .bind('keypress', updateLastPressed)
                    .data('placeholder', placeholder);

                $('body').click(function(e) {
                    $('#ajax-search-results').hide();
                });
            });
    
            function onFocus(e)
            {
                var $input = $(this),
                placeholder = $input.data('placeholder'),
                ajax_box = $input.parent().next();
                if ($input.val() == placeholder) {
                    $input.val('');
                }
                $input.data('last_pressed_interval', setInterval(function() { checkAndSearch($input.get(0),ajax_box); },500));}
    
            function onBlur(e) 
            {
                var $input = $(this),
                placeholder = $input.data('placeholder'),
                last_pressed_interval = $input.data('last_pressed_interval');
                if ($input.val() == '') {
                    $input.val(placeholder);
                }
                if (last_pressed_interval) {
                    clearInterval(last_pressed_interval);
                }
            }

            function updateLastPressed()
            {
                var $input = $(this);
        
                $input
                    .data('last_pressed', now())
                    .data('ajax_fetched', false);
            }
    
            function now(){ return new Date().getTime(); }
    
            function checkAndSearch(input, ajax_box)
            {
                var $input = $(input);
                if ($input.val() == '') {
                    return;
                }
        
                var diff = now() - $input.data('last_pressed'),
                threshold = 1000;
                if (diff >= threshold && !$input.data('ajax_fetched')){
                    fetchSearchResults($input.val(), 'search_box', ajax_box);
                    $input.data('ajax_fetched', true);
                }
            }
    
            function fetchSearchResults(term, display_type, obj)
            {
                $.ajax({
                    type: "GET",
                    url: "/ajax/Search/fetchSearchResults",
                    data: {'term' : term, 'index' : index},
                    dataType: "json",
                    success: function(data) {
                        var errors = $('#errorpanel');
                        if(data.success == true) {
                            if (display_type == 'search_box') {
                                displayResultsSearchBox(data.data, obj);
                            }
                            errors.text('');
                            errors.hide();
                        } else {
                            errors.text(data.error.join(' '));
                            errors.show();
                        }
                    }
                });
            }
    
            // fancy results in search box container
            function displayResultsSearchBox(data, obj)
            {
                var results = data.results,
                    out = '',
                    list = [],
                    len = results.length,
                    x = 0
                    ;
        
                if (len === 0) {
                    list.push('<div class="suggestion" style="color:#999;text-align:left;padding:5px;">No matches found</div>');
                }
                while ( x<len ) {
                    if (x % 2 === 1) {
                        list.push( ['<div class="suggestion-pad"></div><div class="suggestion alt-color">','<a href="',results[x]['link'],'">',results[x]['text'],'</a><br/><span>',results[x]['type'],'</span>','</div>'].join('') );
                    } else {
                        list.push( ['<div class="suggestion-pad"></div><div class="suggestion">','<a href="',results[x]['link'],'">',results[x]['text'],'</a><br/><span>',results[x]['type'],'</span>','</div>'].join('') );
                    }
                    x++;
                }
                out = list.join('');
                obj.html(out).show();
            }
        },
        displayResults : function(term, index) {
            $("input[name='search_results_view']").click(function() {
                var $view = $(this).attr('value');
                
                $.ajax(
                {
                    type: "GET",
                    url: "/ajax/Search/fetchSearchResults",
                    data: {'term' : term, 'index' : index, 'filter' : $view},
                    dataType: "json",
                    success: function(data) {
                        var errors = $('#errorpanel');
                        if(data.success == true) {
                            displayResultsPage(data.data);
                            updatePagination(data.data);
                            errors.text('');
                            errors.hide();
                        } else {
                            errors.text(data.error.join(' '));
                            errors.show();
                        }
                    }
                });

                function updatePagination(data)
                {
                    if($('ul.pager').length) {
                        $('ul.pager').remove();
                    }
                    if (data.pagination.length) {
                        $(data.pagination).insertAfter('#search-results');
                    }
                    var out = 'Showing ' + data.start + ' &mdash; ' + data.finish + ' of     ' + data.num_results + ' results.';
                    $('#left-col > p').html(out);   
                }
                function displayResultsPage(data)
                {
                    var results = data.results;
                    var out = '',
                    list = [],
                    len = results.length,
                    x = 0
                    ;

                    while ( x<len ) {
                        if (x % 2 === 1) {
                        list.push(['<li class="alt">','<a href="',results[x]['link'],'">',results[x]['text'],'</a>','<span>',results[x]['type'],'</span>','<p>',results[x]['summary'],'</p>','</li>'].join(''));
                        } else {
                        list.push(['<li>','<a href="',results[x]['link'],'">',results[x]['text'],'</a>','<span>',results[x]['type'],'</span>','<p>',results[x]['summary'],'</p>','</li>'].join(''));
                        }
                        x++;
                    }
                    out = list.join('');
                    $('#search-results > ul').html(out);
                }
            });
        }
    },
    allitv : {
        update : function(args, list_id, list_url) {
            $("#" + list_id).load("/ajax/AlliTv/" + list_url + args);
        }
    },
    presence :
    {
        init : function(csrf) {
            csrf_token = csrf;
            bindAjaxSetup();

            function bindAjaxSetup() {
                $.ajaxSetup({
                    data: {'csrf_token': csrf_token},
                    dataType: 'json'
                });
            }

            $(document).ajaxComplete(function(event, xhr, options) {
                var data = $.httpData(xhr,options.dataType);
                if (data.csrf_token) {
                    csrf_token = data.csrf_token;
                    bindAjaxSetup();
                }
            });
        }
    },
    form :
    {
        init : function(form_obj) {
            $(document).ready(function() {
                jQuery.validator.addMethod("remote", function(value, element, param) {
                    if ( this.optional(element) )
                        return "dependency-mismatch";
                
                    var previous = this.previousValue(element);
                    if (!this.settings.messages[element.name] )
                        this.settings.messages[element.name] = {};
                    previous.originalMessage = this.settings.messages[element.name].remote;
                    this.settings.messages[element.name].remote = previous.message;
                    
                    param = typeof param == "string" && {url:param} || param; 
                
                    if ( previous.old !== value ) {
                        previous.old = value;
                        var validator = this;
                        this.startRequest(element);
                        var data = {};
                        data[element.name] = value;
                        $.ajax($.extend(true, {
                            url: param,
                            mode: "abort",
                            port: "validate" + element.name,
                            dataType: "json",
                            data: data,
                            success: function(response) {
                                validator.settings.messages[element.name].remote = previous.originalMessage;
                                var valid = response.success === true;
                                if ( valid ) {
                                    var submitted = validator.formSubmitted;
                                    validator.prepareElement(element);
                                    validator.formSubmitted = submitted;
                                    validator.successList.push(element);
                                    validator.showErrors();
                                } else {
                                    var errors = {};
                                    var message = (previous.message = response.message || validator.defaultMessage( element, "remote" ));
                                    errors[element.name] = $.isFunction(message) ? message(value) : message;
                                    validator.showErrors(errors);
                                }
                                previous.valid = valid;
                                validator.stopRequest(element, valid);
                            }
                        }, param));
                        return "pending";
                    } else if( this.pending[element.name] ) {
                        return "pending";
                    }
                
                    return previous.valid;
                }, 'Error retrieving information from server');

                // validate signup form on keyup and submit
                var validator = $("#" + form_obj.id + "").validate({
                    onkeyup: false,
                    focusCleanup: true,
                    rules: form_obj.rules,
                    messages: form_obj.messages,
                    // Zend Form uses unordered lists for errors, tell validate to use it too
                    errorElement: "li",
                    errorPlacement: function(error, element) {
                        // do we have a next ul?
                        var ul = element.next('ul:last');
                        if (ul.length == 0) {
                            ul = $('<ul class="error"/>').appendTo(element.parent());
                        }
                        error.appendTo(ul);
                    }
                });
            });
        }
    }
}

////////////////////////////////////////////////////////  
//Client:	Alli Sports
//Project: 2010 Redesign
//Author:	Jessica Brown http://omniti.com/
//Date:	3.1.10


//CLEAR DEFAULT VALUES FOR INPUT FIELDS
////////////////////////////////////////////////////////
$.fn.cleardefault = function() {
	
	return this.focus(function() {
		
		if ( this.value == this.defaultValue ) {
		this.value = "";
		
		//console.log("clear my defaults dammit");
		
		}
		
	}).blur(function() {
			
		if ( !this.value.length ) {
		this.value = this.defaultValue;
		
		}
		
	});
};

////////////////////////////////////////////////////////
//IMAGE BTTN FADES & ROUNDED CORNERS
////////////////////////////////////////////////////////
this.bttns = function(){	
	
	$(".bttn-image").hover(function(e){
		
		$(this).css("opacity", .6);	
    },
	
	function(){
		
		$(this).css("opacity", 1);
    });
    
    $(".bttn-round").append("<div class='bttn-round-image left'></div><div class='bttn-round-image right'></div>");	
				
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//HOME NAV
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
this.homenav = function(){

	$("#section-nav li").hover(function(e){
	
		var $this = $(this); //li
		//console.log('hover', $this, $this.find("> ul li"));
		if ($this.find("> ul li").length){
			//console.log('found ', $this.find("> ul li").length, $this.find("> ul li").get());
			$this.addClass("active").children(".sub-nav").show();
			$this.addClass("active").children(".sub-nav-shop").show();
			$("ul.sub-nav li").removeClass("active");
			$("ul.sub-nav-shop li").removeClass("active"); //Shop Sub-Nav
		
		}
	},
	
	function(){
		
		$(this).removeClass("active").children(".sub-nav").hide();
		$(this).removeClass("active").children(".sub-nav-shop").hide(); //Shop Sub-Nav
	
	});
	
	$("#section-nav .sub-nav li").hover(function(e){
	
		var newposition = "-" + $(this).children(".tertiary-nav").width();
	
		$(this).addClass("active").children(".tertiary-nav").css("right", newposition + "px").show();
		$("ul.tertiary li").removeClass("active");
	},
	
	function(){
		
		$(this).removeClass("active").children(".tertiary-nav").hide();
	
	});
	
    if ($("ul.sub-nav").length > 0) {
        $("ul.sub-nav").corner("br");
    }
	
	if ($("ul.sub-nav-shop").length > 0) {
        $("ul.sub-nav-shop").corner("br");
    }
	
    if ($("ul.sub-nav li:last-child").length > 0) {
        $("ul.sub-nav li:last-child").corner("br");
    }
    
	if ($("ul.sub-nav-shop li:last-child").length > 0) {
        $("ul.sub-nav-shop li:last-child").corner("br");
    }
	
    if ($("ul.tertiary-nav").length > 0) {
        $("ul.tertiary-nav").corner("br");
    }
	
	//$("ul.sub-nav").corner("br");
	
	//$("ul.sub-nav li.last").corner("br");
	
	//$("ul.tertiary-nav").corner("br");
	
};

	

////////////////////////////////////////////////////////
//ATHLETE NAV
////////////////////////////////////////////////////////
this.athletenav = function(){

	$(".athlete-nav li.athlete-letters").hover(function(e){
	
		$(this).addClass("active").children("ul").show();
		$(".athlete-nav ul").after("<img class='arrow' src='/images/arrow_athlete-nav.gif' alt='arrow_athlete-nav' width='19' height='10' />");
		
	},
	
	function(){
		
		$(this).removeClass("active").children("ul").hide();
		$(".arrow").remove();
	
	});
	
    if ($(".athlete-nav ul").length > 0) {
        $(".athlete-nav ul").corner("br");
    }
		
};



////////////////////////////////////////////////////////
//ATHLETE TABS
////////////////////////////////////////////////////////
/*
this.athletetabs = function() {

	//tab parameters
	var tabOptsAth = {

		fx: {
			opacity: "toggle",
			duration: "fast" 
		}, 
	  
		selected: 0

	};

	//tab the cta
    if ($("#athlete-tabs").length > 0) {
        $("#athlete-tabs").tabs(tabOptsAth);
    }

};
*/
////////////////////////////////////////////////////////
//STAR RATING SYSTEM
////////////////////////////////////////////////////////
this.rating = function() {
	$(".rating-stars .none").click(function(e){
        if($(this).attr('rel') == 'noclick') { return; }
		var postdata = $(this).attr("name");
		$(this).prevAll().andSelf().addClass("rated");
		//remove click event, move to ajax success handler
		$(this).siblings().andSelf().removeClass("none").unbind("click");
	});
	$(".rating-stars .none").hover(function(e){
        if($(this).attr('rel') == 'noclick') { return; }
		$(this).prevAll(".none").andSelf().addClass("over");
	}, function(e){
        if($(this).attr('rel') == 'noclick') { return; }
		$(this).prevAll(".none").andSelf().removeClass("over");
	});
};
////////////////////////////////////////////////////////
//LEADING IMAGE TEXT
////////////////////////////////////////////////////////
$.fn.resize = function() {
	
	if ($("#leading-image").hasClass("left-align") || $("#leading-image").hasClass("right-align")) {
	
		var imageHeight = $("#leading-image img").height();
		//remove padding
		var adjustHeight = imageHeight - 20;
		
		$("#leading-image span").height(adjustHeight);
		
	} 
		
};
////////////////////////////////////////////////////////
//HOME CTA
////////////////////////////////////////////////////////
this.ctahome = function() {
	// let's make sure we actually HAVE a cta-home
	if ($('#cta-home').length == 0) {
	    return;
	}


$('#cta-nav').hoverscroll({
            fixedArrows: false,
            rtl: false
        });
        // Starting the movement automatically at loading
        // @param direction: right/bottom = 1, left/top = -1
        // @param speed: Speed of the animation (scrollPosition += direction * speed)
        var direction = -1,
            speed = 3;
        $("#cta-nav")[0].startMoving(direction, speed);	


	//tab parameters
	var tabOpts = {

		fx: {
			opacity: "toggle",
			duration: "fast" 
		}, 
	  
		selected: 0

	};

	//tab the cta
	$("#cta-home").tabs(tabOpts).tabs("rotate", 5000);
;
	
	$(".cta-home-panel span").append("<a class='nav-up'><img src='/images/bttn_cta-home-up.png' alt='Up' width='17' height='9' /></a><a class='nav-down'><img src='/images/bttn_cta-home-down.png' alt='Down' width='17' height='9' /></a>");
		
	//hide thumbs
	//$(".cta-home-panel span").css("bottom", "129px");
	//$("#cta-nav").css("bottom", "0");
	
	
	
	//For when the CTA first loads
	$(".cta-home-panel span").animate({
		
			bottom: "4"}, 300);
			
		$(".hoverscroll").animate({
		
			bottom: "-125px"}, 300);
			
		$(".listcontainer .hoverscroll").animate({
		
			bottom: "0px"}, 300);
		$("#cta-nav").animate({
		
			bottom: "0px"}, 300);
	
	//slide thumbs up
	$("a.nav-up").click(function(e){
	
		$(".cta-home-panel span").animate({
		
			bottom: "129px"}, 300);
			
		$(".hoverscroll").animate({
		
			bottom: "0"}, 300);
			
		$(".listcontainer .hoverscroll").animate({
		
			bottom: "0px"}, 300);
		$("#cta-nav").animate({
		
			bottom: "0"}, 320);
			
	});
	
	
	//slide thumbs back down
	$("a.nav-down").click(function(e){
	
		$(".cta-home-panel span").animate({
		
			bottom: "4"}, 300);
			
		$(".hoverscroll").animate({
		
			bottom: "-125px"}, 400);
			
		$(".listcontainer .hoverscroll").animate({
		
			bottom: "0px"}, 300);
			
			
	});


	
};

////////////////////////////////////////////////////////
//LOGIN BOX POP UP - prob TEMP functionality 
////////////////////////////////////////////////////////

this.getlogin = function() {

	$(".user-login-bttn").click(function(e){
	
		$.get("/core/ajaxLogin", function(data) {
	
			//alert("BOX CONTENT= " + data);
			var formcontent = $(data).find("#user-login-box");
			
			$("body").append(data);
			
			$("#user-login-box").animate({
				
				opacity: 1}, 300);
	
		});
	});
	
	$(".#close-login").live("click", function(e){
	
		//alert("close the login!!");
		$("#user-login-box").remove();
		
	});
	
};





////////////////////////////////////////////////////////  
//Author:	Terence Hegarty
//Date:	6.2.10
//Handle the CONVERTIBLE EVENT NAV when the event 
//link at the top of the page is clicked
////////////////////////////////////////////////////////

function display_events()
{
	if( $('#convertible_event_nav').length != 0 )
	{
			if( $("#convertible_event_nav").css("display") == 'none' )
			{
				$("#convertible_event_nav").css("display","block");
			}
			else
			{
				$("#convertible_event_nav").css("display","none");
			}
	}
	else
	{
		return false;
	}
}


/////////////////////////////////////////////////////////////////////////////////////////////////////
//Author:	Terence Hegarty
//Date:	9.28.10
//Calls Athlete related content - captures the event from featuredContent.phtml on athlete pages only
/////////////////////////////////////////////////////////////////////////////////////////////////////


function athlete_content_dislpay(tab)
{
	
	var content_tabs = ['tab-features','tab-bio','tab-results','tab-news','tab-photos','tab-videos','tab-tweets'];
			
	$.each(content_tabs, 
		function(key,value)
		{
				
			$('#'+value).css('display','none');
				
		}
	);

			
	if( tab != 'tab-photos' && tab != 'tab-videos' && tab != 'tab-news' )
	{
		//$('#athlete_gallery').css('display','none');
	}
			
	$('#'+tab).css('display','block');
			
	
}



function athlete_content_call(type, content, id)
{
	$('html, body').animate({scrollTop: '0px'}, 500);

	$('#athlete_gallery').css('display','block');
	$('#athlete_gallery').css('overflow','hidden');
	$('#athlete_gallery').html('<img src="/static/images/loader-black.gif" id="preloader" />');
	
	if( type == 'photos' )
	{

		$.ajax(
		{
			type: "GET",
			timeout: 8000,
			url: "/alli/athlete/photogallery/ajax/"+id,		
			dataType: "html",
						
			success: function(data)
			{	
				if(data && data!='undefined')
				{
					$('#athlete_gallery').html(data);
                                        $('div.content').css('display', 'block');
                                    
                                        // Hide the thumbnail panel for a later date
                                        $('.thumbs-container').hide();
                                        $('#related-content').hide();
                                    
                                        //Click function to show the thumbnail panel, swap title attr
                                        $('#show-thumbs').click(function() { 
                                            $('.thumbs-container').slideToggle('fast', function() {
                                                if($('.thumbs-container').is(':visible')) {
                                                    $('#show-thumbs').attr('title', 'Hide Thumbnails');
                                                } else {
                                                    $('#show-thumbs').attr('title', 'Show Thumbnails');
                                                }
                                            });
                                            
                                            return false;
                                        });
                                    
                                        //Click function to show the related content panel, swap button title
                                        $('#show-related').click(function(){
                                            $('#related-content').slideToggle('fast', function() {
                                                if($('#related-content').is(':visible')) {
                                                    $('#show-related').html('Hide Related Content');
                                                } else {
                                                    $('#show-related').html('View Related Content');
                                                }
                                            });
                                            
                                            return false;
                                        });
                                    
                                        //Closes thumb panel on thumb selection
                                        $('.thumb').click(function(e) {
                                            $('#show-thumbs').attr('title', 'Show Thumbnails');
                                            $('.thumbs-container').slideUp();
                                        });
                                    
                                        // Initially set opacity on thumbs and add
                                        // additional styling for hover effect on thumbs
                                        var onMouseOutOpacity = 0.57;
                                        $('#thumbs ul.thumbs li').opacityrollover({
                                            mouseOutOpacity:   onMouseOutOpacity,
                                            mouseOverOpacity:  1.0,
                                            fadeSpeed:         'fast',
                                            exemptionSelector: '.selected'
                                        });
                                    
                                        // Initialize Advanced Galleriffic Gallery
                                        var gallery = $('#thumbs').galleriffic({
                                            delay:                     2500,
                                            numThumbs:                 54,
                                            preloadAhead:              -1,
                                            enableTopPager:            false,
                                            enableBottomPager:         false,
                                            imageContainerSel:         '#slideshow',
                                            controlsContainerSel:      '#controls',
                                            captionContainerSel:       '#caption',
                                            loadingContainerSel:       '#loading',
                                            renderSSControls:          true,
                                            renderNavControls:         true,
                                            playLinkText:              'Play Slideshow',
                                            pauseLinkText:             'Pause Slideshow',
                                            prevLinkText:              '&lsaquo;',
                                            nextLinkText:              '&rsaquo;',
                                            nextPageLinkText:          'Next',
                                            prevPageLinkText:          'Previous',
                                            enableHistory:             false,
                                            autoStart:                 false,
                                            syncTransitions:           true,
                                            defaultTransitionDuration: 900,
                                            onSlideChange:             function(prevIndex, nextIndex) {
                                                // 'this' refers to the gallery, which is an extension of $('#thumbs')
                                                this.find('ul.thumbs').children()
                                                    .eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
                                                    .eq(nextIndex).fadeTo('fast', 1.0);
                                    
                                                // Update the photo index display
                                                this.$captionContainer.find('div.photo-index')
                                                    .html((nextIndex+1) +' of '+ this.data.length);
                                                                                
                                    
                                            },
                                            onPageTransitionOut:       function(callback) {
                                                this.fadeTo('fast', 0.0, callback);
                                            },
                                            onPageTransitionIn:        function() {
                                                var prevPageLink = this.find('a.prev').css('visibility', 'hidden');
                                                var nextPageLink = this.find('a.next').css('visibility', 'hidden');
                                                
                                                // Show appropriate next / prev page links
                                                if (this.displayedPage > 0)
                                                    prevPageLink.css('visibility', 'visible');
                                    
                                                var lastPage = this.getNumPages() - 1;
                                                if (this.displayedPage < lastPage)
                                                    nextPageLink.css('visibility', 'visible');
                                    
                                                this.fadeTo('fast', 1.0);
                                                                        
                                            }
                                        });
                                    
                                        /**************** Event handlers for custom next / prev page links **********************/
                                    
                                        gallery.find('a.prev').click(function(e) {
                                            gallery.previousPage();
                                            e.preventDefault();
                                        });
                                    
                                        gallery.find('a.next').click(function(e) {
                                            gallery.nextPage();
                                            e.preventDefault();
                                        });

				}			
			}
						
		});
	}
	

	if( type == 'video' )
	{
	
		$.ajax(
		{
			type: "GET",
			timeout: 8000,
			url: "/alli/athlete/video/ajax/"+id,		
			dataType: "json",
						
			success: function(data)
			{	
				if(data && data!='undefined')
				{
				
					embed = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="ooyalaPlayer_9421q_gewvo2bj" width="640" height="370" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab"><param name="movie" value="http://player.ooyala.com/player.swf?embedCode='+data.embed_code+'&version=2" /><param name="bgcolor" value="#000000" /><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><param name="flashvars" value="embedType=directObjectTag&embedCode='+data.embed_code+'" /><embed src="http://player.ooyala.com/player.swf?embedCode='+data.embed_code+'&version=2" bgcolor="#000000" width="640" height="370" name="ooyalaPlayer_9421q_gewvo2bj" align="middle" play="true" loop="false" allowscriptaccess="always" allowfullscreen="true" type="application/x-shockwave-flash" flashvars="&embedCode='+data.embed_code+'" pluginspage="http://www.adobe.com/go/getflashplayer"></embed></object>';
				
					$('#athlete_gallery').html(embed);
				}			
			}			
		});
	}
	
}








////////////////////////////////////////////////////////
//DOC READY
////////////////////////////////////////////////////////
$(document).ready(function(){

		

//forcing zend_forms to obey my styling desires 
	$(".zend_form input[type='submit']").addClass("standard-form-submit");
	
	//clear the inputs
	$("input.clear-default").cleardefault();
	
	//article leading images text effects
	$("#leading-image").resize();
	
	//add icons
	//$(".video").added();
	
	//fading hovers on image buttons
	bttns();
	
	//rating stars
	rating();
	
	//cta homepage
	ctahome();
	
	//homepage navigation
	homenav();
	
	//athlete alphabet nav 
	athletenav();
	
	//athlete bio tabs
	//athletetabs();
	
	//open up the login box form
	getlogin();
		
		
		
	
		
		
	//browser fixes that css just couldnt handle
	if ($.browser.msie && $.browser.version.substr(0,1)<=7) {
    
  		$('<span class="ie-rule" />').insertAfter('dl dd');
  		
  		$('form input:radio, form input:checkbox').addClass('ie-radio-check');
  	  
  	}
  	
  	//browser fixes that css just couldnt handle
	if ($.browser.msie) {
	      		
  		$('form input:checkbox, form input:radio').addClass('ie-radio-check');
  	  
  	}

	//error and success messages
	
	if($("#flashed:has(p)")){
		
			setTimeout(function(){
    		
    			$("#flashed p").fadeOut('fast');
			
			}, 1000);
		
		}
		
		
	if( $(".content p:has(img)") && $(".content p:has(text)")) {
	
		$(".content p img").each(function() {
        
        	$(this).parent().addClass("show-inline");
        	 
		});    			
	}




	//Handles the convertible event nav - Terence
	$('#events_link').click(function() 
	{
		display_events();
	}); 
	
	
	
		
	
});


