/*
* 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
*
*/
/*
* markup example for $("#slider").easyslider();
*
*
*
*/
(function($) {
$.fn.easyslider = function(options){
// default configuration properties
var defaults = {
previd: 'prevbtn',
prevtext: '',
nextid: 'nextbtn',
nexttext: '',
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: 5000,
continuous: false
};
var options = $.extend(defaults, options);
this.each(function() {
var obj = $(this);
var s = $("li", obj).length;
var w = $("li", obj).width();
var h = $("li", obj).height();
obj.width(w);
obj.height(h);
obj.css("overflow","hidden");
var ts = s-1;
var t = 0;
$("ul", obj).css('width',s*w);
if(!options.vertical) $("li", obj).css('float','left');
if(options.controlsshow){
var html = options.controlsbefore;
if(options.firstshow) html += ''+ options.firsttext +'';
html += ' '+ options.prevtext +'';
html += ' '+ options.nexttext +'';
if(options.lastshow) html += ' '+ options.lasttext +'';
html += options.controlsafter;
$(obj).after(html);
};
$("a","#"+options.nextid).click(function(){
animate("next",true);
});
$("a","#"+options.previd).click(function(){
animate("prev",true);
});
$("a","#"+options.firstid).click(function(){
animate("first",true);
});
$("a","#"+options.lastid).click(function(){
animate("last",true);
});
function animate(dir,clicked){
var ot = t;
switch(dir){
case "next":
t = (ot>=ts) ? (options.continuous ? 0 : ts) : t+1;
break;
case "prev":
t = (t<=0) ? (options.continuous ? ts : 0) : t-1;
break;
case "first":
t = 0;
break;
case "last":
t = ts;
break;
default:
break;
};
var diff = math.abs(ot-t);
var speed = diff*options.speed;
if(!options.vertical) {
p = (t*w*-1);
$("ul",obj).animate(
{ marginleft: p },
speed
);
} else {
p = (t*h*-1);
$("ul",obj).animate(
{ margintop: p },
speed
);
};
if(!options.continuous && options.controlsfade){
if(t==ts){
$("a","#"+options.nextid).hide();
$("a","#"+options.lastid).hide();
} else {
$("a","#"+options.nextid).show();
$("a","#"+options.lastid).show();
};
if(t==0){
$("a","#"+options.previd).hide();
$("a","#"+options.firstid).hide();
} else {
$("a","#"+options.previd).show();
$("a","#"+options.firstid).show();
};
};
if(clicked) cleartimeout(timeout);
if(options.auto && dir=="next" && !clicked){;
timeout = settimeout(function(){
animate("next",false);
},diff*options.speed+options.pause);
};
};
// init
var timeout;
if(options.auto){;
timeout = settimeout(function(){
animate("next",false);
},options.pause);
};
if(!options.continuous && options.controlsfade){
$("a","#"+options.previd).hide();
$("a","#"+options.firstid).hide();
};
});
};
})(jquery);