$(function() {
// ======================= imagesloaded plugin ===============================
// https://github.com/desandro/imagesloaded
// $('#my-container').imagesloaded(myfunction)
// execute a callback when all images have loaded.
// needed because .load() doesn't work on cached images
// callback function gets image collection as argument
// this is the container
// original: mit license. paul irish. 2010.
// contributors: oren solomianik, david desandro, yiannis chatzikonstantinou
$.fn.imagesloaded = function( callback ) {
var $images = this.find('img'),
len = $images.length,
_this = this,
blank = 'data:image/gif;base64,r0lgodlhaqabaiaaaaaaap///ywaaaaaaqabaaacauwaow==';
function triggercallback() {
callback.call( _this, $images );
}
function imgloaded() {
if ( --len <= 0 && this.src !== blank ){
settimeout( triggercallback );
$images.off( 'load error', imgloaded );
}
}
if ( !len ) {
triggercallback();
}
$images.on( 'load error', imgloaded ).each( function() {
// cached images don't fire load sometimes, so we reset src.
if (this.complete || this.complete === undefined){
var src = this.src;
// webkit hack from http://groups.google.com/group/jquery-dev/browse_thread/thread/eee6ab7b2da50e1f
// data uri bypasses webkit log warning (thx doug jones)
this.src = blank;
this.src = src;
}
});
return this;
};
// gallery container
var $rggallery = $('#rg-gallery'),
// carousel container
$escarousel = $rggallery.find('div.es-carousel-wrapper'),
// the carousel items
$items = $escarousel.find('ul > li'),
// total number of items
itemscount = $items.length;
gallery = (function() {
// index of the current item
var current = 0,
// mode : carousel || fullview
mode = 'carousel',
// control if one image is being loaded
anim = false,
init = function() {
// (not necessary) preloading the images here...
$items.add('').imagesloaded( function() {
// add options
_addviewmodes();
// add large image wrapper
_addimagewrapper();
// show first image
_showimage( $items.eq( current ) );
});
// initialize the carousel
if( mode === 'carousel' )
_initcarousel();
},
_initcarousel = function() {
// we are using the elastislide plugin:
// http://tympanus.net/codrops/2011/09/12/elastislide-responsive-carousel/
$escarousel.show().elastislide({
imagew : 65,
onclick : function( $item ) {
if( anim ) return false;
anim = true;
// on click show image
_showimage($item);
// change current
current = $item.index();
}
});
// set elastislide's current to current
$escarousel.elastislide( 'setcurrent', current );
},
_addviewmodes = function() {
// top right buttons: hide / show carousel
var $viewfull = $(''),
$viewthumbs = $('');
$rggallery.prepend( $('