jQuery.fn.accessNews = function(settings) { settings = jQuery.extend({ newsHeadline: "Top Stories", newsWidth: 285, newsSpeed: "normal", newsScroll: 1, newsNumber:1 }, settings); return this.each(function(i) { aNewsSlider.init(settings,this); }); }; var aNewsSlider = { init: function(s,p) { itemLength = jQuery(".item",p).length; newsContainerWidth = itemLength*s.newsWidth; jQuery(".container",p).css("width",newsContainerWidth + "px"); jQuery(".next",p).css("display","block"); if (s.newsNumber == 1) { jQuery(".next",p).css("background","url(/jahia/jsp/jahia/templates/csn/csn_templates/css/images/css/next.png)"); } else if (s.newsNumber == 2) { jQuery(".next",p).css("background","url(/jahia/jsp/jahia/templates/csn/csn_templates/css/images/css/next2.png)"); } if(itemLength == 1 || itemLength == 0){ jQuery(".next",p).css("display","none"); jQuery(".prev",p).css("display","none"); } animating = false; jQuery(".next",p).click(function() { if (animating == false) { animating = true; animateLeft = parseInt(jQuery(".container",p).css("left")) - (s.newsWidth * s.newsScroll); if (animateLeft + parseInt(jQuery(".container",p).css("width")) > 0) { jQuery(".prev",p).css("display","block"); if (s.newsNumber == 1) { jQuery(".prev",p).css("background","url(/jahia/jsp/jahia/templates/csn/csn_templates/css/images/css/prev.png)"); } else if (s.newsNumber == 2) { jQuery(".prev",p).css("background","url(/jahia/jsp/jahia/templates/csn/csn_templates/css/images/css/prev2.png)"); } jQuery(".container",p).animate({left: animateLeft}, s.newsSpeed, function() { jQuery(this).css("left",animateLeft); if (parseInt(jQuery(".container",p).css("left")) + parseInt(jQuery(".container",p).css("width")) <= s.newsWidth * s.newsScroll) { jQuery(".next",p).css("background","url(/jahia/jsp/jahia/templates/csn/csn_templates/css/images/css/next_grey.png)"); } animating = false; }); } else { animating = false; } return false; } }); jQuery(".prev",p).click(function() { if (animating == false) { animating = true; animateLeft = parseInt(jQuery(".container",p).css("left")) + (s.newsWidth * s.newsScroll); if ((animateLeft + parseInt(jQuery(".container",p).css("width"))) <= parseInt(jQuery(".container",p).css("width"))) { jQuery(".next",p).css("display","block"); if (s.newsNumber == 1) { jQuery(".next",p).css("background","url(/jahia/jsp/jahia/templates/csn/csn_templates/css/images/css/next.png)"); } else if (s.newsNumber == 2) { jQuery(".next",p).css("background","url(/jahia/jsp/jahia/templates/csn/csn_templates/css/images/css/next2.png)"); } jQuery(".container",p).animate({left: animateLeft}, s.newsSpeed, function() { jQuery(this).css("left",animateLeft); if (parseInt(jQuery(".container",p).css("left")) == 0) { jQuery(".prev",p).css("background","url(/jahia/jsp/jahia/templates/csn/csn_templates/css/images/css/prev_grey.png)"); } animating = false; }); } else { animating = false; } return false; } }); }, 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; } } if (jQuery(o).text().indexOf("View All") != -1) { jQuery(".next",p).css("background","url(/jahia/jsp/jahia/templates/csn/csn_templates/css/images/css/next_grey.png)"); jQuery(".prev",p).css("background","url(/jahia/jsp/jahia/templates/csn/csn_templates/css/images/css/prev_grey.png)"); jQuery(o).text("View Less"); jQuery(".container",p).css("left","0px").css("width",s.newsWidth * s.newsScroll + "px"); } else { jQuery(o).text("View All"); aNewsSlider.init(s,p); } } };