(function($) { // wrap it up ------------------------------------------------

_SETTINGS = {
  fIn   : 800,
  fOut  : 800,
  tShow : 4000
};

$(function(){ // onload
  slideshow_gallery();
});

slideshow_gallery = function() {
  
  if( (!$('div.compact_slideshow_gallery').length)
   || (!$('div#slideshow_images').length) ) return;

  // init the statics...................
  if( ! ('initd' in slideshow_gallery) ) {
    slideshow_gallery['initd'] = 1;
    slideshow_gallery['idx']   = 0;
    slideshow_gallery['gdiv']  = $('div.compact_slideshow_gallery');
	  slideshow_gallery['img$']  = $('div#slideshow_images').children('img');
    slideshow_gallery['len']   = slideshow_gallery.img$.length - 1;
  }

	(_next=function(){

		slideshow_gallery.idx = (slideshow_gallery.idx < slideshow_gallery.len)
                            ? (slideshow_gallery.idx+1) : 0;

	  slideshow_gallery.gdiv.find('img.main_image').onImagesLoaded(function() { 
		  var n_img = slideshow_gallery.img$.eq(slideshow_gallery.idx).clone().addClass('_new');
      $('img.main_image').fadeIn(_SETTINGS.fIn, function(){
        setTimeout(function(){

          slideshow_gallery.gdiv.append(n_img).onImagesLoaded(function(_cont) {
            $('img.main_image',_cont).fadeOut(_SETTINGS.fOut, function(){
              $(this).remove();
              $('img._new',_cont).removeClass('_new').addClass('main_image')
                .fadeIn(_SETTINGS.fIn, function(){ _next(); });
            });
          });

        }, _SETTINGS.tShow);
      }); // ...fadeIn()...
    }); // ...onImagesLoaded()...

	})(); // call _next() right now...
};

})(jQuery); // scope wrapper ------------------------------------------------

function makeModal(div) {
	$(div).modal({
		onOpen: function (dialog) {
			dialog.overlay.fadeIn('slow', function () {
				dialog.container.slideDown('slow', function () {
					dialog.data.fadeIn('slow');
				});
			});
		},
		onClose: function (dialog) {
			dialog.data.fadeOut('slow', function () {
				dialog.container.slideUp('slow', function () {
					dialog.overlay.fadeOut('slow', function () {
						$.modal.close(); // must call this!
					});
				});
			});
		}
	});
}

