/****
Homepage specific javascript
****/

      $(document).ready(function() {
        // size customer strip width appropriately, and set max width
        var maxWidth = ( 302 * $(".customer").length ) - 906;
        $("#scrollcontainer ul").width( 302 * $(".customer").length );

        // get initial position of customer strip
        var currentPos = $("#scrollcontainer").scrollLeft();

        // show & enable customer strip prev / next buttons 
        $("#nextlink").show("fast");
        $("#prevlink").show("fast");
        $("#nextlink").click(function () {
          currentPos = currentPos + 302;
          if (currentPos > maxWidth) currentPos = 0;
          $("#scrollcontainer").animate({scrollLeft: currentPos}, 1000);
        });
        $("#prevlink").click(function () {
          currentPos = currentPos - 302;
          if (currentPos < 0) currentPos = maxWidth;
          $("#scrollcontainer").animate({scrollLeft: currentPos}, 1000);
        });

        // get number of news items
        var newsCount = $(".newsitem").length;

        // show & enable news next / prev button behaviour
        $("#nextnews").css("display", "inline");
        $("#prevnews").css("display", "inline");
        $("#nextnews").click( function () {
          var currentNews = $("#newsitems .current");
          var nextNews;
          if ( currentNews.is(".newsitem:last-child") ) {
            nextNews = $(".newsitem:first-child");
          } else {
            nextNews = currentNews.next();
          }
          currentNews.fadeOut("slow", function () {
            currentNews.removeClass("current");
            nextNews.addClass("current");
            nextNews.fadeIn("slow");
          });
        })
        $("#prevnews").click( function () {
          var currentNews = $("#newsitems .current");
          var prevNews;
          if ( currentNews.is(".newsitem:first-child") ) {
            prevNews = $(".newsitem:last-child");
          } else {
            prevNews = currentNews.prev();
          }
          currentNews.fadeOut("slow", function () {
            currentNews.removeClass("current");
            prevNews.addClass("current");
            prevNews.fadeIn("slow");
          });
        })

        // set the news up so that it switches stories every 8 seconds
        var newsloop = setInterval('$("#nextnews").click()',8000);

        // stop the news when the mouse enters
        $("#newsitems").bind("mouseenter", function(){
          clearInterval(newsloop);
        });

        // start the news again when the mouse leaves
        $("#newsitems").bind("mouseleave", function(){
          newsloop = setInterval('$("#nextnews").click()',8000);
        });
        

      });      


