$(document).ready(function(){
    // Load gallery
    $.fillSideGallery = function(album_id){
        $('#gallery-images').picasaGallery({
            user: 'thesignchefgallery',
            nextButton: 'gallery-arrow-right',
            prevButton: 'gallery-arrow-left',
            grid: '4x3',
            albumId: album_id + '',
            tooltip: 'medium',
            loadingImg: '/images/ajax-loader.gif',
            onClick: function(container, image, settings){
                $.showGallery(settings.user, settings.albumId, parseInt($(container).attr('index')));
            },
            onLoad: function(feed, images, settings){
            }
        });
    }
    
    $.showGallery = function(user, album_id, index) {
		// Default index to 0
		if(!index) index = 0;
		
        $.fn.colorbox({
            href: '/ajax/ajaxGallery.php?user=' + user,
            speed: "100",
            width: "950px",
            height: "650px",
            open: true
        }, function(){
            $.fillGallery(album_id, index);
        });
    }
    
    // Gallery modal
    $.fillGallery = function(album_id, index) {
		$('#gallery-image-ext').html('<img src="/themes/thesignchef/images/gallery_loading.gif" />');
		$('#gallery-ext').html('<img style="margin: 18px 0px 0px 152px;" src="/themes/thesignchef/images/ajax-loader-gallery.gif" />');
        $('#gallery-ext').picasaGallery({
            user: 'thesignchefgallery',
            nextButton: 'gallery-arrow-next',
            prevButton: 'gallery-arrow-prev',
            grid: '1x5',
			size: 'small',
            albumId: album_id + '',
			className: 'gallery-images-ext',
			loadingImg: '/images/ajax-loader.gif',
            onClick: function(container, image, settings) {
                $.showGalleryImage(image.content.src);
            },
			onLoad: function(feed, images, settings) {
				$('#gallery-ext-title').html(feed.title.$t);
				$('#gallery-ext-description').html(feed.subtitle.$t + '<br /><br /><em>Click thumbnail to view enlarged image.</em>');
				$.showGalleryImage(images[index].content.src);
			}
        });
    }
    
    $.showGalleryImage = function(src){
        $('#gallery-image-ext').attr('src', src).itemThumbnail({
			'loading': '/themes/thesignchef/images/gallery_loading.gif'
		});
    }
});
