﻿/*
* 	Easy Slider 1.5 - jQuery plugin
*	written by Alen Grakalic	
*	http://cssglobe.com/post/4004/easy-slider-15-the-easiest-jquery-plugin-for-sliding
*
*	Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
*	Dual licensed under the MIT (MIT-LICENSE.txt)
*	and GPL (GPL-LICENSE.txt) licenses.
*
*	Built for jQuery library
*	http://jquery.com
*
*/
(function($) { $.fn.easySlider = function(k) { var l = { prevId: 'prevBtn', prevText: 'Previous', nextId: 'nextBtn', nextText: 'Next', controlsShow: true, controlsBefore: '', controlsAfter: '', controlsFade: true, firstId: 'firstBtn', firstText: 'First', firstShow: false, lastId: 'lastBtn', lastText: 'Last', lastShow: false, vertical: false, speed: 800, auto: false, pause: 2000, continuous: false }; var k = $.extend(l, k); this.each(function() { var f = $(this); var s = $("li", f).length; var w = $("li", f).width(); var h = $("li", f).height(); f.width(w); f.height(h); f.css("overflow", "hidden"); var g = s - 1; var t = 0; $("ul", f).css('width', s * w); if (!k.vertical) $("li", f).css('float', 'left'); if (k.controlsShow) { var i = k.controlsBefore; if (k.firstShow) i += '<span id="' + k.firstId + '"><a href=\"javascript:void(0);\">' + k.firstText + '</a></span>'; i += ' <span id="' + k.prevId + '"><a href=\"javascript:void(0);\">' + k.prevText + '</a></span>'; i += ' <span id="' + k.nextId + '"><a href=\"javascript:void(0);\">' + k.nextText + '</a></span>'; if (k.lastShow) i += ' <span id="' + k.lastId + '"><a href=\"javascript:void(0);\">' + k.lastText + '</a></span>'; i += k.controlsAfter; $(f).after(i) }; $("a", "#" + k.nextId).click(function() { animate("next", true) }); $("a", "#" + k.prevId).click(function() { animate("prev", true) }); $("a", "#" + k.firstId).click(function() { animate("first", true) }); $("a", "#" + k.lastId).click(function() { animate("last", true) }); function animate(a, b) { var c = t; switch (a) { case "next": t = (c >= g) ? (k.continuous ? 0 : g) : t + 1; break; case "prev": t = (t <= 0) ? (k.continuous ? g : 0) : t - 1; break; case "first": t = 0; break; case "last": t = g; break; default: break }; var d = Math.abs(c - t); var e = d * k.speed; if (!k.vertical) { p = (t * w * -1); $("ul", f).animate({ marginLeft: p }, e) } else { p = (t * h * -1); $("ul", f).animate({ marginTop: p }, e) }; if (!k.continuous && k.controlsFade) { if (t == g) { $("a", "#" + k.nextId).hide(); $("a", "#" + k.lastId).hide() } else { $("a", "#" + k.nextId).show(); $("a", "#" + k.lastId).show() }; if (t == 0) { $("a", "#" + k.prevId).hide(); $("a", "#" + k.firstId).hide() } else { $("a", "#" + k.prevId).show(); $("a", "#" + k.firstId).show() } }; if (b) clearTimeout(j); if (k.auto && a == "next" && !b) { ; j = setTimeout(function() { animate("next", false) }, d * k.speed + k.pause) } }; var j; if (k.auto) { ; j = setTimeout(function() { animate("next", false) }, k.pause) }; if (!k.continuous && k.controlsFade) { $("a", "#" + k.prevId).hide(); $("a", "#" + k.firstId).hide() } }) } })(jQuery);
