// Some global instances
var GalleryNavigation;

GalleryNavigation = {
	// Initial actions
	init : function() {
	},
	// New gallery
	newGN : function(i,u,o,e,f,b) {
		var t = this;
		var op = '0.'+o;
		var bGM = jQuery('.block_GalleryMedia');
		var bGN = jQuery('.block_GalleryNavigation');
    // Get and clones medias
		jQuery('.GalleryMedia_image',bGM).hide().clone().appendTo('.block_GalleryNavigation .GalleryNavigation_images');
		if(f != 'auto'){
			t.changeThumbsFormat(f,jQuery('.GalleryNavigation_images .GalleryMedia_image img',bGN));
		}
    jQuery('.block_GalleryNavigation .GalleryNavigation_contents').css("min-height", b+'px');
		jQuery('.GalleryMedia_content',bGM).hide().clone().appendTo('.block_GalleryNavigation .GalleryNavigation_contents');
		bGM.parents('.slot_outer_content').hide();
    // Init the navigation
    jQuery('.GalleryMedia_image',bGN).show().fadeTo('fast',op);
    jQuery('.GalleryMedia_content',bGN).fadeTo('fast',0).hide();
		jQuery('.GalleryMedia_content:first, .GalleryMedia_image:first',bGN).show().fadeTo('slow',1).addClass('current');
		jQuery('.GalleryNavigation_images img',bGN).bind(e,function(){
			if(jQuery('.GalleryNavigation_contents .GalleryMedia_content',bGN).eq(jQuery('.GalleryNavigation_images img',bGN).index(this)).hasClass('current').toString() != 'true'){
				jQuery('.GalleryMedia_image',bGN).fadeTo('fast',op);
				jQuery('.GalleryMedia_content',bGN).hide().fadeTo('fast',0).removeClass('current');
				jQuery('.GalleryMedia_content',bGN).eq(jQuery('.GalleryNavigation_images img').index(this)).show().fadeTo('fast',1).addClass('current');
				jQuery('.GalleryMedia_image',bGN).eq(jQuery('.GalleryNavigation_images img',bGN).index(this)).fadeTo('fast',1);
			}
		});
	},
	// Update thumbs navigation with the specified format
	changeThumbsFormat : function(f,el){
		el.each(function(){
			s = jQuery(this).attr('src');
			n = s.substr(s.lastIndexOf('/')+1, s.length);
			jQuery(this).hide().attr('src', f+n).show();
		});
	}
};

GalleryNavigation.init();

