/*
* BCDC.US - simple image showcase jQuery plugin
* Examples and documentation at: http://bcdc.us
* Version: 1.0 ( Nov-25-2009 )
* Copyright (c) 2009 Bruno Correia
* Requires: jQuery v1.3+
* Demo at http://bcdc.us/jquery.plugins/jquery.showcase/demo.html
*/
(function($) {
$.fn.showcase = function(customOptions) {
var options = $.extend({},$.fn.showcase.defaultOptions, customOptions);
if ( options.openingImage == 'random' ) {
var n = $(this).parent().nextAll().length+1; // return the total amount of items
options.openingImage = Math.floor( Math.random() * n + 1 );
}
if ( $('#showcase img').length == 0 ) {
$('#showcase').append('
');
$('#showcase img').css({'display':'none'});
}
var $current = $('body').find('ul.showcase li a').eq(options.openingImage-1);
$current.addClass('current');
var $showcase = $('#showcase img');
if ( options.imageCaptions == true ) {
$('#showcase').after('');
$("#captions").text( $current.attr('rel') );
}
if ( options.pageLink == true ) {
$showcase.wrap('');
}
$showcase.load(function() {
$(this).fadeIn(options.fadeInSpeed);
});
$(this).click(function(event) {
event.preventDefault();
var $showcase = $('#showcase img');
var requested = $(this).parent().prevAll().length+1; // return eq position
if ( $(this).hasClass('current') == false ) {
$showcase.fadeOut(options.fadeOutSpeed, function() {
$showcase.attr({ src: options.imagePath + '/' + requested + '.' + options.imageExtension })
.load(function() { $showcase.hide().fadeIn(options.fadeInSpeed);
});
});
if ( options.pageLink == true ) {
$('#showcase a').attr('href', $(this).attr('href') );
}
if ( options.imageCaptions == true ) {
$('#captions').text( $(this).attr('rel') );
}
$('ul.showcase li a').removeClass('current');
$(this).addClass('current');
}
});
};
$.fn.showcase.defaultOptions = {
imagePath: 'images',
imageExtension: 'jpg',
imageCaptions: true,
openingImage: '1', // may use 'random'
pageLink: true,
fadeInSpeed: 600,
fadeOutSpeed: 700
};
})(jQuery);