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

Photos.Scene.Friends = Class.create(Photos.Scene.Scroll, {
	initialize: function($super, passedArg) {
		$super(passedArg);
		this.albumsTotal = 0;
		this.initialRows = 1;
		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('friends_list'), {
			itemTemplate: 'friends/entry',
			swipeToDelete: false,
			reorderable: false,
			initialAverageRowHeight: 84, // pulled from screenshot
			scrollThreshold: this.pixelThreshold,
			renderLimit: this.listRenderWindow,
			lookahead: 50,
			filterFunction: this.request.bind(this)
		});
		this.controller.get('friends_title').update(
						this.sceneModel.getTitle());
	},

	handleSelection: function(event) {
		this.pushWithTemplate(event, 'albums', {
			model: new Photos.Model.FacebookAlbums(
				"facebook",
				event.item.contactID,
				event.item.contactName)
		});
	},

	translateList: function(filter, offset, limit, items, total) {
		this.mainListElement.mojo.setCount(total);
		this.mainListElement.mojo.noticeUpdatedItems(offset, items);
		this.mainListElement.mojo.setLength(total);
		this.ready();
	},

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

