/*
* Easy Slider - jQuery plugin
* written by Alen Grakalic
* http://cssglobe.com/post/3783/jquery-plugin-easy-image-or-content-slider
*
* 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
*
*/
/*
* markup example for $("#images").easySlider();
*
*
*
*/
(function($) {
$.fn.easySlider = function(options){
// default configuration properties
var defaults = {
prevId: 'prevId',
prevText: 'Previous',
nextId: 'nextBtn',
nextText: 'Next',
orientation: '', // 'vertical' is optional;
speed: 800
};
var options = $.extend(defaults, options);
return this.each(function()
{
var obj = $(this);
var ul = obj.find('ul');
var s = ul.find('li').length;
var w = $j(ul.find('li:first')).width() - 100;
w = $.browser.msie ? w + 100 : w;
var h = obj.height();
var ts = s-1;
var t = 0;
var vertical = (options.orientation == 'vertical');
ul.css('width',s*w);
var p = options._prev;
var n = options._next;
var px = '#' + options.prevId;
var nx = '#' + options.nextId
obj.before('' + '');
$(px).data('boundTo', obj).hide();
$(nx).data('boundTo', obj).hide();
$(nx).click(function(){
animate("next", $(this));
if (t >= ts)
$(this).fadeOut();
$(px).fadeIn();
return false;
});
$(px).click(function(){
animate("prev", $(this));
if (t <= 0)
$(this).fadeOut();
$(nx).fadeIn();
return false;
});
function animate(dir, ref)
{
var obj = ref.data('boundTo');
if(dir == "next"){
t = (t>=ts) ? ts : t+1;
} else {
t = (t<=0) ? 0 : t-1;
};
if(!vertical)
{
var ml = (t*w*-1);
obj.find('ul').animate(
{ left: ml },
options.speed
);
}
else
{
var mt = (t*h*-1);
obj.find('ul').animate(
{ top: mt },
options.speed
);
}
};
if (s > 1)
{
$(nx).fadeIn();
}
});
};
})(jQuery);