//
// Dragr: Carroussel function
// Author: Concept M
// Version: v.1.0
// Description: turns a ul into a carroussel
(function($) {
$.fn.carroussel = function(options) {
var opts = $.extend({}, $.fn.carroussel.defaults, options);
var imghtml = '';
return this.each(function() {
var timeout = null;
var curritem = -1;
var items = $(this).find('li')
$.each(items, function(index, value) {
var style = 'display:none;z-index:'+index+';';
imghtml += '
';
$(this).mouseover(function(){
showImage(index);
});
});
imghtml = '' + imghtml + '
';
$(this).append(imghtml);
$(this).find('ul').css('z-index', $(this).find('li').length);
showImage(0);
function showImage(nr){
if(nr != curritem){
if(timeout != null && opts.animate == true){
clearTimeout(timeout);
}
if(curritem != -1){
var old_item = $('#' + opts.img_prefix + curritem);
}
// swap z-index
var old_z = parseInt($('#' + opts.img_prefix + curritem).css('z-index'));
var new_z = parseInt($('#' + opts.img_prefix + nr).css('z-index'));
if(old_z > new_z || curritem == -1){
$('#' + opts.img_prefix + nr).show();
$('#' + opts.img_prefix + curritem).fadeOut('fast', function(){
if(old_item != undefined){
old_item.hide();
}
});
}
else{
$('#' + opts.img_prefix + nr).fadeIn('fast', function(){
if(old_item != undefined){
old_item.hide();
}
});
}
// set active listitem
$(items[curritem]).removeClass('active');
$(items[nr]).addClass('active');
curritem = nr;
if(opts.animate == true){
timeout = setTimeout(function(){
var nextitem = curritem + 1;
if(nextitem == items.length){
nextitem = 0;
}
showImage(nextitem);
}, opts.time_out);
}
}
}
});
};
// plugin defaults
$.fn.carroussel.defaults = {
animate: false,
time_out: 4000,
img_prefix: 'carr_'
};
})(jQuery);