/*
 * JavaScript for DEDTA
 **/

$(document).ready(function(){
   
    //Show / hide the departmental menu on mouse enter / leave
    $('#department').mouseenter(function(event){
        
        //Show the menu
        $(this).children('#department-submenu').show();
        $(this).children('.dpt').addClass('open');
        
    }).mouseleave(function(event){
        
        //Hide the menu
        $(this).children('#department-submenu').hide();
        $(this).children('.dpt').removeClass('open');
        
    });
    
    
    //Grab all the info needed to set up the news sliders
    var newsWrapperSize = $("#newsBoxContainer").width();
   var newsAmt = $("#newsBoxScroller > div").size();
   var newsItemSize=$("#newsBoxScroller > div").outerWidth(true);
   
   //calculate the size of the scroll area and how many articles are visible at once
   var scrollerSize = newsAmt*newsItemSize;
   var articlesVisible = Math.round(newsWrapperSize / newsItemSize);
   
   //set the width of the scroller area
   $("#newsBoxScroller").css("width",scrollerSize+"px");
   
   //Build the scroller navigation
   $('#statusContainer ul').append('<li id="scrollerLeftArrow">&#60;</li>');
   
   for(var i=0; i<newsAmt; i++){
        if(i<articlesVisible)
            $('#statusContainer ul').append('<li class="dotBg on"></li>');
        else
           $('#statusContainer ul').append('<li class="dotBg"></li>');
   }
    
    $('#statusContainer ul').append('<li id="scrollerRightArrow">&#62;</li>');
    
    //start the scroller at position 0
    var currPos = 0;
    
    //then we shuffle to the left...
    $('#scrollerLeftArrow').click(function(e){
            if(currPos>0){
                currPos--;
                $("#newsBoxScroller").animate({left:'+='+newsItemSize});
                 $('#statusContainer li.on').first().prev().addClass('on');
                 $('#statusContainer li.on').last().removeClass('on');
            }
    });

    //and to the right!
    $('#scrollerRightArrow').click(function(e){
            if(currPos<newsAmt-articlesVisible){
                currPos ++;
                 $("#newsBoxScroller").animate({left:'-='+newsItemSize});
                 $('#statusContainer li.on').last().next().addClass('on');
                 $('#statusContainer li.on').first().removeClass('on');
            }
    });
    
    
    //rotate those banners!
    setInterval( "bannerSwitch()", 5000 );


    

});

 function bannerSwitch() {
    var $active = $('#hdrContainer IMG.active');

    if ( $active.length == 0 ) $active = $('#hdrContainer IMG:last');

    var $next =  $active.next().length ? $active.next()
        : $('#hdrContainer IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

function pdffix(){
// Adobe service is down!
}
