(function($){
  $.fn.shuffle = function() {
    return this.each(function(){
      var items = $(this).children();
      return (items.length)
        ? $(this).html($.shuffle(items))
        : this;
    });
  }

  $.shuffle = function(arr) {
    for(
      var j, x, i = arr.length; i;
      j = parseInt(Math.random() * i),
      x = arr[--i], arr[i] = arr[j], arr[j] = x
    );
    return arr;
  }
})(jQuery);
	
	$(document).ready(function(){
	
	 	 $(function () {
				 $.ajax({
					  type: "GET",
					  url: "/galleries/home_new/PhotoGallery.xml", // replace with absolute URL of your gallery's xml file
					  dataType: "xml",
					  success: function(xml) {
						  $(xml).find('img').each(function() {
							 var location = '/galleries/home_new/'; // replace with absolute path to the directory that holds your images
							 var url = $(this).attr('src');
							 var alt = $(this).attr('alt');
							  $('<img src="'+location+''+url+'" alt="'+alt+'"/>').appendTo('#galleria');
							  
						  });
																		
						// Load theme
						Galleria.loadTheme('/js/src/themes/classic/galleria.classic.js');



						 $('#galleria').galleria({
								image_crop: true, // crop all images to fit
								thumb_crop: true, // crop all thumbnails to fit
								transition: 'flash', // crossfade photos
								thumbnails:false,
								autoplay:2000,
            					carousel_speed: 200,
								extend: function() {
						
								this.bind(Galleria.IMAGE, function(e) {
						
									$('.counter').html(this.$('counter').html());
													
											})
								this.bind(Galleria.IMAGE, function(e) {
							
										$('.caption').html(this.$('info-description').html());
							
									})	
							
								
								
						   //get thumbnail width
						   var thumbnailWidth = $('.galleria-thumbnails').width();
						   $('.galleria-thumbnails').css({"width" : thumbnailWidth, "margin-left" : "auto", "margin-right" : "auto"})
						   $('.galleria-stage').css('z-index', '500');
							}
						
						   
						   });
   

		  
					  }
	  
				  });
	
			  })
	
		
	});
	                  



