/*

  ----------------------------------------------------------------------------------------------------
  Accessible News Slider
  ----------------------------------------------------------------------------------------------------

  Author:
  Brian Reindel

  Author URL:
  http://blog.reindel.com

  License:
  Unrestricted. This script is free for both personal and commercial use.

*/


jQuery.fn.accessNews = function( settings ) {
  settings = jQuery.extend({
    speed : "fast",
    slideBy : 1
    }, settings);
    return this.each(function() {
    jQuery.fn.accessNews.run( jQuery( this ), settings );
    });
};
jQuery.fn.accessNews.run = function( $this, settings ) {
  jQuery( ".javascript_css", $this ).css( "display", "none" );
  var ul = jQuery( "ul:eq(0)", $this );
  var li = ul.children();
  if (settings.slideBy=1){
       ul.css( "width", ( 310 ) );
    };
  if ( li.length > settings.slideBy ) {
    var $next = jQuery( ".next > a", $this );
    var $back = jQuery( ".back > a", $this );
    var liWidth = jQuery( li[0] ).width();
    var animating = false;
    ul.css( "width", ( li.length * liWidth ) );
    $next.click(function() {

      var reg = new RegExp("\\w([0-9]{1,2})");
      arr = reg.exec($next.attr('id'));

      _next_num = $next.attr('id').replace(arr[1], '')
      _img_num = _next_num.replace('next', 'img');
      img_num = arr[1];
      num = parseInt(img_num) + 1;
      $next.attr('id', _next_num + num);

      if(jQuery('#'+_img_num+img_num).attr('src') == '/design/images/1x1.gif')
        jQuery('#'+_img_num+img_num).attr('src', jQuery('#'+_img_num+img_num).attr('src1'))

      if ( !animating ) {
        animating = true;
        offsetLeft = parseInt( ul.css( "left" ) ) - ( liWidth * settings.slideBy );
        if ( offsetLeft + ul.width() > 0 ) {
          $back.css( "display", "block" );
          ul.animate({
            left: offsetLeft
          }, settings.speed, function() {
            if ( parseInt( ul.css( "left" ) ) + ul.width()-2*liWidth <= liWidth * settings.slideBy) {
              $next.css( "display", "none" );
            }
            animating = false;
          });
        } else {
          animating = false;
        }
      }
      return false;
    });
    $back.click(function() {
      if ( !animating ) {
        animating = true;
        offsetRight = parseInt( ul.css( "left" ) ) + ( liWidth * settings.slideBy );
        if ( offsetRight + ul.width() <= ul.width() ) {
          $next.css( "display", "block" );
          ul.animate({
            left: offsetRight
          }, settings.speed, function() {
            if ( parseInt( ul.css( "left" ) ) == 0 ) {
              $back.css( "display", "none" );
            }
            animating = false;
          });
        } else {
          animating = false;
        }
      }
      return false;
    });
    $next.css( "display", "block" )
    jQuery( ".view_all > a, .skip_to_news > a", $this ).click(function() {
      var skip_to_news = ( jQuery( this ).html() == "Skip to News" );
      if ( jQuery( this ).html() == "view all" || skip_to_news ) {
        ul.css( -60+"px", "auto" ).css( "left", "0" );
        $next.css( "display", "none" );
        $back.css( "display", "none" );
        if ( !skip_to_news ) {
          jQuery( this ).html( "view less" );
        }
      } else {
        if ( !skip_to_news ) {
          jQuery( this ).html( "view all" );
        }
        ul.css( "width", ( li.length * liWidth ) );
        $next.css( "display", "block" );
      }
      return false;
    });
  }
};






