/* Copyright 2009 Palm, Inc.  All rights reserved. */

Photos.Scene.Albums = Class.create(Photos.Scene.Scroll, {
	initialize: function($super, passedArg) {
		$super(passedArg);
		this.listRenderWindow = 30;
		this.rowsPerScreen = 5;
		this.screensRendered =
				this.listRenderWindow / this.rowsPerScreen;
	},

	setup: function($super) {
		this.pixelThreshold = (this.screensRendered *
					this.controller.window.innerHeight) / 3;
		$super(this.controller.get('albums_list'), {
			itemTemplate: this.templatePrefix + 'albums/entry',
			swipeToDelete: false,
			reorderable: false,
			initialAverageRowHeight: 84, // pulled from screenshot
			scrollThreshold: this.pixelThreshold,
			renderLimit: this.listRenderWindow,
			lookahead: 50,
			filterFunction: this.requestAlbumsList.bind(this),
		});
		this.controller.get('albums_header').update(
						this.sceneModel.getHeader());
	},

	handleSelection: function(event) {
		this.pushWithTemplate(event, 'thumbs', {
			model: this.sceneModel.newThumbsModel(event.item)
		});
	},

	requestAlbumsList: function(filter, widget, offset, limit) {
		if (filter != this.lastFilter) {
			this.rowRequester.dropRequests();
			this.lastFilter = filter;
		}

		function translateAlbumsList(albums, total) {
			widget.mojo.setCount(total);
			widget.mojo.noticeUpdatedItems(offset, albums);
			widget.mojo.setLength(total);
			this.ready();
		}

		this.sceneModel.request(
			filter, offset, limit, translateAlbumsList.bind(this));
	}
});

