/**
 * @desc JS helper functions under the PP namespace. Uses jQuery.
 */

/**
 * Fire slideshow when page is ready
 */
$().ready(function() {
	$('#coda-slider-1').codaSlider();

    setTimeout("slideSwitch(1)", (Math.floor(Math.random()*7001)+2000));
    setTimeout("slideSwitch(2)", (Math.floor(Math.random()*7001)+2000));
    setTimeout("slideSwitch(3)", (Math.floor(Math.random()*7001)+2000));
    setTimeout("slideSwitch(4)", (Math.floor(Math.random()*7001)+2000));
    setTimeout("slideSwitch(5)", (Math.floor(Math.random()*7001)+2000));
    
    /* Partner tooltip */
    $('#button-partner').bind('mouseenter', function(){
    		togglePartnerTooltip(this, true);
    	});
    $('#button-partner').bind('mouseleave', function(){
		togglePartnerTooltip(this, false);
	});
    
    DD_belatedPNG.fix('li, img, div, a, span, h4, h3, h2, h1');
});

function slideSwitch(id) {
    var active = $('#sponsor-list-' + id + ' li.active');

    if ($(active).length == 0) $(active) = $('#sponsor-list-' + id + ' li:last-child');

    var next = $(active).next().length ? $(active).next() : $('#sponsor-list-' + id + ' li:first-child');

    $(active).addClass('last-active');
    $(active).fadeOut(2000, function(){
    	$(next).fadeIn(2000, function(){
    	    setTimeout( "slideSwitch(" + id + ")", (Math.floor(Math.random()*2001)+1000));
    	}).addClass('active');
    	$(active).removeClass('active last-active');
    });
    
}

function togglePartnerTooltip(el, over)
{
	el = $(el);
	
    if (over) {
    	el.find('.tooltip').addClass('over');
    }
    else 
    {   
    	el.find('.tooltip').removeClass('over');
    }
}