
/* Initialisation des bloc "SlideShow" et "Pictures Gallery"
-------------------------------------------------------------- */
function PictureGalleryPartOnLoad(){ 
	
	/* PICTURES GALLERY */
	if (typeof (Gallery) != 'undefined') {  
	
		Gallery.Init = function(GalleryPartID,nbCols,LineByPage) {			
			
			var page = 0, tablePage = [];
			var nbItem = jQuery('.BlocPicturesGallery '+GalleryPartID+' .item').length;
			
			if(nbItem>LineByPage*nbCols){
															 
				jQuery('.BlocPicturesGallery '+GalleryPartID+' .item').each(function(index){
					if((index%(LineByPage*nbCols)==0 && !!index)){ page++; }
					tablePage[page] = tablePage[page] || [];			
					tablePage[page].push(jQuery(this).detach());
				});
									
				var htmlPagination = '<div class="pagination gallerypagination"><ul>';
				jQuery('.BlocPicturesGallery '+GalleryPartID).addClass("js");
				jQuery('.BlocPicturesGallery '+GalleryPartID).html("");
														
				for(var i=0;i<tablePage.length;i++){
					if(!i){
						htmlPagination += '<li><a role="button" class="selected">'+(i+1)+'</a></li>';
						jQuery('.BlocPicturesGallery '+GalleryPartID).append('<div class="gallerypage page'+(i+1)+' selected"></div>');
					}
					else{
						htmlPagination += '<li><a role="button">'+(i+1)+'</a></li>';
						jQuery('.BlocPicturesGallery '+GalleryPartID).append('<div class="gallerypage page'+(i+1)+'"></div>');
					}				
					for(var j=0;j<tablePage[i].length;j++){
						if((j%nbCols)==0){
							jQuery('.BlocPicturesGallery '+GalleryPartID+' .gallerypage.page'+(i+1)).append('<div class="clear"></div>');
						}
						jQuery('.BlocPicturesGallery '+GalleryPartID+' .gallerypage.page'+(i+1)).append(tablePage[i][j]);					
					}
					jQuery('.BlocPicturesGallery '+GalleryPartID+' .gallerypage.page'+(i+1)).append('<div class="clear"></div>');
				}
				
				htmlPagination += "</ul></div>";
				jQuery('.BlocPicturesGallery '+GalleryPartID+'').append(htmlPagination);
				
				jQuery('.BlocPicturesGallery '+GalleryPartID+' .gallerypagination a').click(function(){
					var page = jQuery(this).html();
					jQuery('.BlocPicturesGallery '+GalleryPartID+' .gallerypagination a').removeClass("selected");	
					jQuery('.BlocPicturesGallery '+GalleryPartID+' .gallerypage').removeClass("selected");		
					jQuery('.BlocPicturesGallery '+GalleryPartID+' .gallerypage.page'+page).addClass("selected");	
					jQuery(this).addClass("selected");		 												 
				});				
			}		
		}		
		
		Gallery.Install = function() {
			Gallery.Simple = Gallery.Simple || [];		
			for (var i = 0; i < Gallery.Simple.length; i++) {
				var gallery_id = Gallery.Simple[i].ID;
				var gallery_cols = Gallery.Simple[i].NbCols;
				var gallery_line = Gallery.Simple[i].NbLineByPage;
				Gallery.Init("#gallery_" + gallery_id, gallery_cols, gallery_line);
			}
		};		
		
		Gallery.Install();	
	}
	
	/* SLIDESHOW */						
	if (typeof (Slideshow) != 'undefined') {  
	
		Slideshow.Init = function(SlideshowPartID,params) {
			jQuery('.BlocSlideshow '+SlideshowPartID).carousel(params); 
			jQuery('.BlocSlideshow '+SlideshowPartID+' .item').css('width',function(){ 
				return jQuery(this).parent().parent().css('width');
			});			
		}		
		
		Slideshow.Install = function() {
			Slideshow.Carousel = Slideshow.Carousel || [];		
			for (var i = 0; i < Slideshow.Carousel.length; i++) {
				var carousel_id = Slideshow.Carousel[i].ID;
				var carousel_params = Slideshow.Carousel[i].Params;
				Slideshow.Init("#slideshow_" + carousel_id, carousel_params);
			}
		};		
		
		Slideshow.Install();		
	}
}

function PictureGalleryPartOnLoadTimeout(){
	if (typeof (jQuery) != 'undefined') {  
		jQuery(document).ready(function(){
			jQuery.getScript('/Scripts/javascript/jquery/jquery.carousel.custom.min.js',PictureGalleryPartOnLoad);
		});
	}
	else{
		setTimeout("PictureGalleryPartOnLoadTimeout();",50);
	}
}
PictureGalleryPartOnLoadTimeout();
