jQuery.fn.accessNews = function(settings) {
    settings = jQuery.extend({
        newsHeadline: "",
        newsSpeed: ""
    }, settings);
    return this.each(function(i) {
        aNewsSlider.itemWidth = parseInt(jQuery(".item:eq(" + i + ")",".news_slider").css("width")) + parseInt(jQuery(".item:eq(" + i + ")",".news_slider").css("margin-right"));
        aNewsSlider.init(settings,this);
    });
};
var aNewsSlider = {

    itemWidth: 0,
    init: function(s,p) {
        itemLength = jQuery(".item",p).length;
      //  if (jQuery(".view_all",p).width() == null) {
              // - - - - - (  dynamically write out alternative navigation, using the heading passed as a comma delimited list  ) - - - -       
              var str, splitStr;
              splitStr = s.newsHeadline.split(",")
              for(var i = 0 ; i < itemLength ; i ++){
                if(i==0){str =  '<li class="a' + i + '"><a href="#" class="altNav"  title="" id="' + parseInt(i) +'">' + splitStr[i]  + '</a></li>';}
                else{str = str + '<li class="a' + i + '"><a href="#" class="altNav"  title="" id="' + parseInt(i) +'">' + splitStr[i] + '</a></li>';}
              }
             jQuery("#altNavCont").append('<ul id="altNavList">' + str +'</ul>');        
              // - - - - - (  dynamically write out alternative navigation, using the heading passed as a comma delimited list  ) - - - -      
     //   }
        newsContainerWidth = itemLength * aNewsSlider.itemWidth;
        jQuery(".container",p).css("width",newsContainerWidth + "px");
        animating = false;
  /*      
        jQuery(".next",p).click(function() {
            if (animating == false) {
                animating = true;       
               animateLeft = parseInt(jQuery(".container",p).css("left")) - (aNewsSlider.itemWidth); 
                if (animateLeft + parseInt(jQuery(".container",p).css("width")) > 0) {
                    jQuery(".container",p).animate({left: animateLeft}, s.newsSpeed, function() {
                        jQuery(this).css("left",animateLeft);
                        animating = false;
                    });
                } else {
                    animating = false;
                }
            }
            return false;
        });
        
        jQuery(".prev",p).click(function() {
            if (animating == false) {
                animating = true;               
                animateLeft = parseInt(jQuery(".container",p).css("left")) + (aNewsSlider.itemWidth ); 
                if ((animateLeft + parseInt(jQuery(".container",p).css("width"))) <= parseInt(jQuery(".container",p).css("width"))) {
                    jQuery(".container",p).animate({left: animateLeft}, s.newsSpeed, function() {
                        jQuery(this).css("left",animateLeft);
                        animating = false;
                    });  
                } else {
                    animating = false;
                } 
            }
            return false;
        });
        
*/
      // - - - - - (  alternative navigation onclick ) - - - - 

        
        $("a.altNav").click(function() {

         if (animating == false) {
         animating = true;
        // - - - - - (  remove selected class fom all elems ) - - - -
        for(var i = 0 ; i < $("a.altNav").length ; i++){
            $("a.altNav").removeClass("thisOne");
        }
            // - - - - - (  add selected class to selected elm ) - - - -
            $(this).addClass("thisOne");
            var   pos = $(this).attr("id");
                    animateLeft = parseInt(-(aNewsSlider.itemWidth*pos));
                    jQuery(".container",p).animate({left: animateLeft}, s.newsSpeed, function() {
                        jQuery(this).css("left",animateLeft);
                        animating = false;
                    }); 
                }else{
                    return false;                
                   }
            });

      // - - - - - (  alternative navigation onclick ) - - - - 
        
        
        
    },
    vAll: function(s,p) {
        var o = p;
        while (p) {
            p = p.parentNode;
            if (jQuery(p).attr("class") != undefined && jQuery(p).attr("class").indexOf("news_slider") != -1) {
                break;
            }
        }
    }
};
