/* 
 * Gallery handler 
 */


var galleryHandler = function () {
    return {
        setAlbumCovers:function () {
            //myconsole.log ( 'Called: set Album Covers' );
            url = settings.base_address + '/?c=basket';
            $.ajax  ({
                url: settings.base_address + 'gallery/loadcovers',
                type:'POST',
                success:function (data) {
                    if ( data.success == true ) {
                        // set covers
                        galleryHandler.appendCoversToMenu ( data.data );
                    }
                }
            });
        },

        appendCoversToMenu: function ( data ) {
            total = ''; // contents placeholder

            $.each(data, function ( index, item ) {
                tpl = Templates.getTemplate ( 'homepage-cover' );
                tpl = tpl.replace ( "%album%", item.title );
                tpl = tpl.replace ( "%path%", item.path );
                tpl = tpl.replace ( "%thumb_prefix%", item.thumb_prefix);
                tpl = tpl.replace ( "%file%", item.filename );
                tpl = tpl.replace ( "%album_id%", item.album_id );
                tpl = tpl.replace ( "%album_id%", item.album_id );
                tpl = tpl.replace ( "%alias%", item.alias);
                tpl = tpl.replace ( "%alias%", item.alias );
                tpl = tpl.replace ( "%album%", item.title );
                tpl = tpl.replace ( "%album%", item.title );
                total += tpl;
            });

            $(".menu-covers").html(total);
            // make sure navigation is hidden ( when viewing gallery )
            $(".thumbsNavigation").addClass('hidden');
        }
    }
}();
