(function($) { $.fn.hpFeaturedTabs = function(settings) { var config = { autoPlay: true, changeSpeed: 300, controlText: { play: 'Play', pause: 'Pause', next: 'Next', previous: 'Previous' }, speed: 5000 }; if (settings) $.extend(true, config, settings); var timer = ''; var counter = 0; var preloadedImg = []; var headers = []; var links = []; var slides = []; $(this).find('.featured_tab').each(function(i) { links[i] = $(this).find('a.slide').attr('href'); preloadedImg[i] = $(this).find('img').attr('src', $(this).attr('src')); slides[i] = $(this).find('a.slide').remove(); headers[i] = $(this).find('h3').html(); $(this).mouseenter(function() { goToAndPause(i) }); $(this).click(function() { window.location = links[i] }) }); $('#featured_slide').mouseenter(function() { if (isPlaying()) pause('hover') }); $('#featured-next').click(function() { next(); return false }); $('#featured-prev').click(function() { previous(); return false }); $('#featured-play').click(function() { isPlaying() ? pause('playBtn') : play(); return false }); if (config.autoPlay && slides.length > 1) { timer = setInterval(function() { play() }, config.speed) }; function isPlaying() { return $('#featured-play').hasClass('featured-paused') ? false : true }; function play(src) { if (!isBusy()) { counter++; transitionTo(slides, counter); if (src == 'hover' || !isPlaying()) { timer = setInterval(function() { play() }, config.speed) } if (!isPlaying()) { $('#featured-play').text(config.controlText.pause).removeClass('featured-paused') } } }; function pause(src) { clearInterval(timer); if (!src || src == 'playBtn') $('#featured-play').text(config.controlText.play).addClass('featured-paused') }; function next() { goToAndPause(counter + 1) }; function previous() { goToAndPause(counter - 1) }; function isBusy() { return $('#featured_slide').children().length > 1 ? true : false }; function goToAndPause(index) { $('#featured_slide').children().stop(true, true); if ((counter != index) || ((counter == index) && isBusy())) { if (isBusy()) $('#featured_slide').children().eq(0).remove(); transitionTo(slides, index); pause() } }; function transitionTo(slides, index) { var oldCounter = counter; if ((counter >= slides.length) || (index >= slides.length)) { counter = 0; var e2b = true } else if ((counter < 0) || (index < 0)) { counter = slides.length - 1; var b2e = true } else { counter = index } $(slides[counter]).clone().appendTo($('#featured_slide')).hide().fadeIn(config.changeSpeed, function() { if ($.browser.msie) this.style.removeAttribute('filter') }); if ($('#featured_slide').children().length > 1) { $('#featured_slide').children().eq(0).css('position', 'absolute').fadeOut(config.changeSpeed, function() { $(this).remove() }) }; $('#featured_stuff').find('h1').html(headers[counter]); $('.featured_tab').removeClass('featured_tab_on'); $('.featured_tab').eq(counter).addClass('featured_tab_on') }; return this } })(jQuery);
