﻿(function($) { $.fn.spotlight = function(a) { if (this.length && (spotlight = $.data(this[0], 'spotlight'))) { return spotlight } return this.each(function() { $.data(this, 'spotlight', new $.spotlight.init(this, a)) }) }; $.spotlight = { defaults: { featureItems: '.spotlight_item', itemContent: '.featured_content', feature: '.spotlight_feature', featuredClass: 'on', displayTime: 3, autoReStart: true, transition: null }, init: function(c, d) { var e = this; this.settings = $.extend({}, $.spotlight.defaults, d); this.features = $(c).find(this.settings.featureItems); this.featureContainer = $(c).find(this.settings.feature); if (this.settings.transition) { if (typeof this.settings.transition == 'object') { this.settings.transitionSpeed = this.settings.transition[1]; this.settings.transition = this.settings.transition[0] } this.transitionContainer = this.featureContainer.clone().css({ position: 'absolute', top: 0, left: 0, margin: 0, border: 0, overflow: 'hidden' }).hide() } this.features.each(function(a) { var b = $(this); b.data('idx', a); b.data('featured', b.find(e.settings.itemContent).remove().html()) }).hover(function() { e.show($(this).data('idx')) }, function() { e.restart() }); this.featureContainer.hover(function() { e.stop() }, function() { e.restart() }); this.show(0); this.start() } }; $.extend($.spotlight.init.prototype, { currentIdx: 0, showing: null, running: false, interval: null, show: function(a) { this.stop(); if (this.showing) this.showing.removeClass(this.settings.featuredClass); this.showing = this.features.eq(a); this.currentIdx = a; this.showing.addClass(this.settings.featuredClass); if (this.featureContainer) { if (this.transitionContainer) this.transitionTo(this.showing.data('featured')); else this.featureContainer.html(this.showing.data('featured')) } }, start: function() { var a = this; this.running = true; this.interval = setTimeout(function() { a.next(true) }, this.settings.displayTime * 1000) }, stop: function() { this.running = false; clearTimeout(this.interval) }, restart: function() { if (this.settings.autoReStart) this.start() }, next: function(a) { if (this.running || a) { var b = this.currentIdx + 1; if (b >= this.features.size()) b = 0; this.show(b); if (this.running || a) this.start() } }, transitionTo: function(a) { var b = this; this.transitionContainer.hide().html(a).appendTo(this.featureContainer); this.transitionContainer[this.settings.transition](this.settings.transitionSpeed, function() { b.featureContainer.html(a) }) } }) })(jQuery);