     
    var inprogress = false;
     
    function loadnews() { changenewsbox(1); }    
    
    function changenewsbox(boxnum) {
    
        //$(".popoutbox").animate({"height": "0px", "padding-bottom": "0px"}, 500);
        $("#latestnewshead").removeClass('latestnewson');
        $("#eventshead").removeClass('eventson');
        $("#articleshead").removeClass('articleson');
        $("#opportunitieshead").removeClass('opportunitieson');
        
        if (boxnum == 1) {
            $("#newsbox").animate({"height": "235px", "padding-bottom": "20px"}, 500);
            $("#eventsbox").animate({"height": "0px", "padding-bottom": "0px"}, 500);
            $("#articlesbox").animate({"height": "0px", "padding-bottom": "0px"}, 500);
            $("#oppsbox").animate({"height": "0px", "padding-bottom": "0px"}, 500);
            
            $("#latestnewshead").addClass('latestnewson');
        } else if (boxnum == 2) {
            $("#eventsbox").animate({"height": "235px", "padding-bottom": "20px"}, 500);
            $("#newsbox").animate({"height": "0px", "padding-bottom": "0px"}, 500);
            $("#articlesbox").animate({"height": "0px", "padding-bottom": "0px"}, 500);
            $("#oppsbox").animate({"height": "0px", "padding-bottom": "0px"}, 500);
            
            $("#eventshead").addClass('eventson');
        } else if (boxnum == 3) {
            $("#articlesbox").animate({"height": "235px", "padding-bottom": "20px"}, 500);
            $("#newsbox").animate({"height": "0px", "padding-bottom": "0px"}, 500);
            $("#eventsbox").animate({"height": "0px", "padding-bottom": "0px"}, 500);
            $("#oppsbox").animate({"height": "0px", "padding-bottom": "0px"}, 500);
            
            $("#articleshead").addClass('articleson');
        } else if (boxnum == 4) {
            $("#oppsbox").animate({"height": "235px", "padding-bottom": "20px"}, 500);
            $("#newsbox").animate({"height": "0px", "padding-bottom": "0px"}, 500);
            $("#eventsbox").animate({"height": "0px", "padding-bottom": "0px"}, 500);
            $("#articlesbox").animate({"height": "0px", "padding-bottom": "0px"}, 500);
            
            $("#opportunitieshead").addClass('opportunitieson');
        }
    
    }

    function changebanner(action) {
    
    if (inprogress == false) {
        inprogress = true;
        
        if (action == "next") {
            curbanner = curbanner + 1;
            if (totalbanners == curbanner) { curbanner = 0; }
            if (image1) {
                $('#bannerimage1').css({ 'left': '581px' });
                thisimage = "bannerimage1";
            } else {
                $('#bannerimage2').css({ 'left': '581px' });
                thisimage = "bannerimage2";
            }
            newpos = "-581px";
        } else {
            curbanner = curbanner - 1;
            if (curbanner < 0) { curbanner = (totalbanners - 1); }
            if (image1) {
                $('#bannerimage1').css({ 'left': '-581px' });
                thisimage = "bannerimage1";
            } else {
                $('#bannerimage2').css({ 'left': '-581px' });
                thisimage = "bannerimage2";
            }
            newpos = "581px";
        }
        
        bannerurl = 'features_images/'+bannerimage[curbanner];
        
        
        $('#bannerlink').fadeOut('fast');
        $('#btext').fadeOut('fast', function() {
            document.getElementById('btext').innerHTML=bannertext[curbanner];
            document.getElementById('bannerlink').href=bannerlink[curbanner];
            if (bannerlink[curbanner] == "") { document.getElementById('bannerlink').innerHTML = ''; } else {  document.getElementById('bannerlink').innerHTML = 'Read more about it'; $('#bannerlink').fadeIn('slow'); }
            $('#btext').fadeIn('slow');
        });
        
        document.getElementById(thisimage).src = bannerurl;
        
        if (image1) {
            image1 = false;
            image2 = true;
            $("#bannerimage2").animate({"left": newpos}, 500, function() { inprogress= false; });     
            $("#bannerimage1").animate({"left": "0px"}, 500);       
        } else {
            image1 = true;
            image2 = false;
            $("#bannerimage1").animate({"left": newpos}, 500, function() { inprogress= false; });
            $("#bannerimage2").animate({"left": "0px"}, 500);
        }
        
        } //inprogress check
    }
    
   $(document).ready(function() {
      setTimeout('loadnews()',500);
      var BannerTimer = setInterval(function() { if (inprogress == false) { changebanner('next'); } } ,4000);
      if ($('#bannerlink').html() == "") { $('#bannerlink').fadeOut('fast'); }
   });
