/* 
 * jQuery scripts for homepage
 */

jQuery.noConflict();
jQuery(document).ready(function($){
    // Gets the rotator started
//    Rotator();
//    $('#small-features .small-feature').click(function(){ stopRotator(this); });
    
    // Add "first" class to left feature block (to remove margin)
    $('div.feature:first').addClass('first');
    $('div.news-item:last').addClass('last');           
});

var rotateCounter = 0;

function Rotator(){  
    setRotateCounter();    
    $('#small-features img.display').removeClass('display');
    var img = $('#small-features #feature-'+rotateCounter+' img');
    img.addClass('display');
    var src = $(img).attr('src');
    var href = $(img).attr('href');
    $('#main-feature img').attr('src', src);
    $('#main-feature a').attr('href', href);   
    setTimeout('Rotator()', 5000);        
}

function setRotateCounter(){  
    rotateCounter = (rotateCounter == 3 ? 1 : rotateCounter + 1);
}

function stopRotator(div){
    var div_id = $(div).attr('id');
    var id = div_id.substring(div_id.length - 1, div_id.length);    
    Rotator(id);
    clearTimeout('Rotator');
}
