jQuery.fn.extend({ featurePlayer2: function(p_timeout, plbgc1, pltcolor1, plbgimg1) { if (this.data('featurePlayer2')) return; this.data('featurePlayer2', true); var TIMEOUT = p_timeout; var $featurePlayer = this; var $featureStories = jQuery('.storyPanel > ul > li', this); var $featureStoriesRandom = jQuery('.storyPanel ul.random', this); var $featureStoriesTabs = jQuery('.storyList > ul > li', this); var $featureStoriesTabs_link = jQuery('.storyList > ul > li > a > span', this); var $featureStoriesTabsRandom = jQuery('.storyList ul.random', this); var $buttonNext = jQuery('.buttonContainer .next', this); var $buttonPrev = jQuery('.buttonContainer .prev', this); var timer; var currentIndex = 0; function _init() { $featureStoriesTabs.bind('click', function() { _pause(); currentIndex = $featureStoriesTabs.index(this); _show(currentIndex); }); $featureStoriesTabsRandom.each(function(i) { var $randomStories = jQuery('li', this); var randomIndex = Math.floor(Math.random() * $randomStories.length); $randomStories.eq(randomIndex).show(); $featureStoriesRandom.eq(i).find('li').eq(randomIndex).show(); }); $buttonNext.bind('click', _next); $buttonPrev.bind('click', _prev); $featurePlayer.bind('mouseenter', _pause).bind('mouseleave', _play); _show(currentIndex); _play(); } function _show(index) { var s_siblings; $featureStories.eq(index) .fadeIn('slow') .siblings('li').fadeOut('slow'); $featureStoriesTabs.eq(index) .addClass('selected') .siblings('li').removeClass('selected'); if (plbgc1 != ""){ $featureStoriesTabs.eq(index) .css('backgroundColor', '#'+plbgc1); $featureStoriesTabs.eq(index) .siblings('li').css('backgroundColor', 'transparent'); } if (plbgimg1 != ""){ $featureStoriesTabs.eq(index) .css('background-image', 'url(' + plbgimg1 + ')'); $featureStoriesTabs.eq(index) .siblings('li').css('background-image', 'none'); } if (pltcolor1 != ""){ $featureStoriesTabs_link.eq(index).css('color', '#' + pltcolor1); $featureStoriesTabs.eq(index).siblings('li').children('a').children('span').css('color', ''); } } function _next() { currentIndex = (currentIndex + 1) % $featureStories.length; _show(currentIndex); } function _prev() { currentIndex = (currentIndex - 1 + $featureStories.length) % $featureStories.length; _show(currentIndex); } function _play() { clearInterval(timer); timer = setInterval(function() { _next(); }, TIMEOUT); } function _pause() { clearInterval(timer); } _init(); } });