/* JavaScript for mainNav Widget */

$(document).ready(function(){
    // Rollovers
    $('.mainNav a img').mouseover(function(){
        $(this).attr('src', $(this).attr('src').replace('_off', '_on'));
    });
    $('.mainNav a img').mouseout(function(){
        if (!$(this).hasClass('active')){
            $(this).attr('src', $(this).attr('src').replace('_on', '_off'));
        }
    });

    // Set active nav
    var docid = window.location.href;
    docid = docid.replace(/^.*id=([0-9]+).*$/, '$1');
    
    $('.mainNav a').each(function(){
        var regex = new RegExp('id='+docid);
        if ($(this).attr('href').match(regex)){
            $(this).find('img').addClass('active');
        }
    });
    
    var obj = $('.mainNav a img.active');
    if (obj.length > 0){
        $(obj).attr('src', $(obj).attr('src').replace('_off', '_on'));
    }
});