(function($) { $.fn.slides = function(option) { option = $.extend({}, $.fn.slides.option, option); return this.each(function() { $('.' + option.container, $(this)).children().wrapall('
'); var elem = $(this), control = $('.slides_control', elem), total = control.children().size(), width = control.children().outerwidth(), height = control.children().outerheight(), start = option.start - 1, effect = option.effect.indexof(',') < 0 ? option.effect : option.effect.replace(' ', '').split(',')[0], paginationeffect = option.effect.indexof(',') < 0 ? effect : option.effect.replace(' ', '').split(',')[1], next = 0, prev = 0, number = 0, current = 0, loaded, active, clicked, position, direction, imageparent, pausetimeout, playinterval; if (total < 2) { $('.' + option.container, $(this)).fadein(option.fadespeed, option.fadeeasing, function() { loaded = true; option.slidesloaded(); }); $('.' + option.next + ', .' + option.prev).fadeout(0); return false; } function animate(direction, effect, clicked) { if (!active && loaded) { active = true; option.animationstart(current + 1); switch (direction) { case 'next': prev = current; next = current + 1; next = total === next ? 0 : next; position = width * 2; direction = -width * 2; current = next; break; case 'prev': prev = current; next = current - 1; next = next === -1 ? total - 1 : next; position = 0; direction = 0; current = next; break; case 'pagination': next = parseint(clicked, 10); prev = $('.' + option.paginationclass + ' li.' + option.currentclass + ' a', elem).attr('href').match('[^#/]+$'); if (next > prev) { position = width * 2; direction = -width * 2; } else { position = 0; direction = 0; } current = next; break; } if (effect === 'fade') { if (option.crossfade) { control.children(':eq(' + next + ')', elem).css({ zindex: 10 }).fadein(option.fadespeed, option.fadeeasing, function() { if (option.autoheight) { control.animate({ height: control.children(':eq(' + next + ')', elem).outerheight() }, option.autoheightspeed, function() { control.children(':eq(' + prev + ')', elem).css({ display: 'none', zindex: 0 }); control.children(':eq(' + next + ')', elem).css({ zindex: 0 }); option.animationcomplete(next + 1); active = false; }); } else { control.children(':eq(' + prev + ')', elem).css({ display: 'none', zindex: 0 }); control.children(':eq(' + next + ')', elem).css({ zindex: 0 }); option.animationcomplete(next + 1); active = false; } }); } else { control.children(':eq(' + prev + ')', elem).fadeout(option.fadespeed, option.fadeeasing, function() { if (option.autoheight) { control.animate({ height: control.children(':eq(' + next + ')', elem).outerheight() }, option.autoheightspeed, function() { control.children(':eq(' + next + ')', elem).fadein(option.fadespeed, option.fadeeasing); }); } else { control.children(':eq(' + next + ')', elem).fadein(option.fadespeed, option.fadeeasing, function() { if ($.browser.msie) { $(this).get(0).style.removeattribute('filter'); } }); } option.animationcomplete(next + 1); active = false; }); } } else { control.children(':eq(' + next + ')').css({ left: position, display: 'block' }); if (option.autoheight) { control.animate({ left: direction, height: control.children(':eq(' + next + ')').outerheight() }, option.slidespeed, option.slideeasing, function() { control.css({ left: -width }); control.children(':eq(' + next + ')').css({ left: width, zindex: 5 }); control.children(':eq(' + prev + ')').css({ left: width, display: 'none', zindex: 0 }); option.animationcomplete(next + 1); active = false; }); } else { control.animate({ left: direction }, option.slidespeed, option.slideeasing, function() { control.css({ left: -width }); control.children(':eq(' + next + ')').css({ left: width, zindex: 5 }); control.children(':eq(' + prev + ')').css({ left: width, display: 'none', zindex: 0 }); option.animationcomplete(next + 1); active = false; }); } } if (option.pagination) { $('.' + option.paginationclass + ' li.' + option.currentclass, elem).removeclass(option.currentclass); $('.' + option.paginationclass + ' li:eq(' + next + ')', elem).addclass(option.currentclass); } } } function stop() { clearinterval(elem.data('interval')); } function pause() { if (option.pause) { cleartimeout(elem.data('pause')); clearinterval(elem.data('interval')); pausetimeout = settimeout(function() { cleartimeout(elem.data('pause')); playinterval = setinterval(function() { animate("next", effect); }, option.play); elem.data('interval', playinterval); }, option.pause); elem.data('pause', pausetimeout); } else { stop(); } } if (total < 2) { return; } if (start < 0) { start = 0; } if (start > total) { start = total - 1; } if (option.start) { current = start; } if (option.randomize) { control.randomize(); } $('.' + option.container, elem).css({ overflow: 'hidden', position: 'relative' }); control.children().css({ position: 'absolute', top: 0, left: control.children().outerwidth(), zindex: 0, display: 'none' }); control.css({ position: 'relative', width: (width * 3), height: height, left: -width }); $('.' + option.container, elem).css({ display: 'block' }); if (option.autoheight) { control.children().css({ height: 'auto' }); control.animate({ height: control.children(':eq(' + start + ')').outerheight() }, option.autoheightspeed); } if (option.preload && control.find('img:eq(' + start + ')').length) { $('.' + option.container, elem).css({ background: 'url(' + option.preloadimage + ') no-repeat 50% 50%' }); var img = control.find('img:eq(' + start + ')').attr('src') + '?' + (new date()).gettime(); if ($('img', elem).parent().attr('class') != 'slides_control') { imageparent = control.children(':eq(0)')[0].tagname.tolowercase(); } else { imageparent = control.find('img:eq(' + start + ')'); } control.find('img:eq(' + start + ')').attr('src', img).load(function() { control.find(imageparent + ':eq(' + start + ')').fadein(option.fadespeed, option.fadeeasing, function() { $(this).css({ zindex: 5 }); $('.' + option.container, elem).css({ background: '' }); loaded = true; option.slidesloaded(); }); }); } else { control.children(':eq(' + start + ')').fadein(option.fadespeed, option.fadeeasing, function() { loaded = true; option.slidesloaded(); }); } if (option.bigtarget) { control.children().css({ cursor: 'pointer' }); control.children().click(function() { animate('next', effect); return false; }); } if (option.hoverpause && option.play) { control.bind('mouseover', function() { stop(); }); control.bind('mouseleave', function() { pause(); }); } if (option.generatenextprev) { $('.' + option.container, elem).after('prev'); $('.' + option.prev, elem).after('next'); } $('.' + option.next, elem).click(function(e) { e.preventdefault(); if (option.play) { pause(); } animate('next', effect); }); $('.' + option.prev, elem).click(function(e) { e.preventdefault(); if (option.play) { pause(); } animate('prev', effect); }); if (option.generatepagination) { if (option.prependpagination) { elem.prepend(''); } else { elem.append(''); } control.children().each(function() { $('.' + option.paginationclass, elem).append('
  • ' + (number + 1) + '
  • '); number++; }); } else { $('.' + option.paginationclass + ' li a', elem).each(function() { $(this).attr('href', '#' + number); number++; }); } $('.' + option.paginationclass + ' li:eq(' + start + ')', elem).addclass(option.currentclass); $('.' + option.paginationclass + ' li a', elem).click(function() { if (option.play) { pause(); } clicked = $(this).attr('href').match('[^#/]+$'); if (current != clicked) { animate('pagination', paginationeffect, clicked); } return false; }); $('.' + option.paginationclass + ' li a', elem).hover(function() { if (option.play) { pause(); } clicked = $(this).attr('href').match('[^#/]+$'); if (current != clicked) { animate('pagination', paginationeffect, clicked); } return false; }); $('a.link', elem).click(function() { if (option.play) { pause(); } clicked = $(this).attr('href').match('[^#/]+$') - 1; if (current != clicked) { animate('pagination', paginationeffect, clicked); } return false; }); if (option.play) { playinterval = setinterval(function() { animate('next', effect); }, option.play); elem.data('interval', playinterval); } }); } ; $.fn.slides.option = { preload: false, preloadimage: '../images/ajax-loader.gif', container: 'slides_container', generatenextprev: false, next: 'next', prev: 'prev', pagination: true, generatepagination: true, prependpagination: false, paginationclass: 'pagination', currentclass: 'current', fadespeed: 350, fadeeasing: '', slidespeed: 350, slideeasing: '', start: 1, effect: 'slide', crossfade: false, randomize: false, play: 0, pause: 0, hoverpause: false, autoheight: false, autoheightspeed: 350, bigtarget: false, animationstart: function() {}, animationcomplete: function() {}, slidesloaded: function() {} }; $.fn.randomize = function(callback) { function randomizeorder() { return (math.round(math.random()) - 0.5); } return ($(this).each(function() { var $this = $(this); var $children = $this.children(); var childcount = $children.length; if (childcount > 1) { $children.hide(); var indices = []; for (i = 0; i < childcount; i++) { indices[indices.length] = i; } indices = indices.sort(randomizeorder); $.each(indices, function(j, k) { var $child = $children.eq(k); var $clone = $child.clone(true); $clone.show().appendto($this); if (callback !== undefined) { callback($child, $clone); } $child.remove(); }); } })); } ; } )($jq);