var PhotoGalleryModel = Class.create();

PhotoGalleryModel.PhotoAlbums = [];
PhotoGalleryModel.AlbumsLoaded = false;
PhotoGalleryModel.LoadPhotoAlbums = function() {
    var params = { command: 'getPhotoAlbums' };
 
    Application.ShowLoader('GetPhotoAlbums', 'Getting Photo Albums', true);
    Application.ShowProgress('60');
    new Ajax.Request('WebServices/Data.ashx', {
        method: 'get',
        parameters: params,
        onFailure: function() {
            Application.HideProgress();
            alert('Could not get photoAlbum data... Try again later.');
            Application.HideLoader('GetPhotoAlbums');
            if (callback) callback();
        },
        onSuccess: function(transport, json) {
            Application.ShowProgress(90);
            Application.HideLoader('GetPhotoAlbums');
            var oResponse = transport.responseText || "No response text";
            var jsResponse = oResponse.evalJSON(false);
            if (!jsResponse.IsSuccess) {
                alert(jsResponse.Message);
                return;
            }
            PhotoGalleryModel.PhotoAlbums = jsResponse.Data.Items;
            PhotoGalleryModel.AlbumsLoaded = true;
        }
    });
};
PhotoGalleryModel.Draw = function(carousel, album) {
    var ePhotoContainer = $('Items_PhotoCarousel');
    ePhotoContainer.innerHTML = '';
    album.Photos.each(function(item, ix) {
        var eItem = OS.AppendDiv(ePhotoContainer, 'item');
        if (ix == 0) Element.addClassName(eItem, 'selected');
        var eKey = OS.AppendDiv(eItem, 'key');
        eKey.innerHTML = item.Key;
        var eCaption = OS.AppendDiv(eItem, 'caption');
        eCaption.innerHTML = item.Caption;
        var ePhoto = OS.AppendDiv(eItem, 'photo');
        var eImgSrc = OS.AppendChild(ePhoto, 'img');
        eImgSrc.src = 'thumbnail.ashx?scope=4&ref=' + item.ImagePath + '&width=75&height=44&forceQuality=true&cacheSize=true';
    });
    carousel.load();
    carousel.reactivate();
}
