// JavaScript Document
var ProductList = new Class({
	Extends: Page,
	
	setCategoryNav: null,
	setBanner: null,
	setCaption: null,
	setCategoryList: null,
	setProductList: null,
	
	initialize: function(pageState) {
		this.parent('product-list', pageState);
		
		this.setCategoryNav = this.setBlock.pass(['divCategoryNav', 'categoryNav'], this);
		this.setBanner = this.setBlock.pass(['divBanner', 'banner'], this);
		this.setCaption = this.setBlock.pass(['divCaption', 'caption'], this);
		this.setCategoryList = this.setBlock.pass(['abProdHomeIcons', 'categoryList'], this);
		this.setProductList = this.setBlock.pass(['divProductList', 'productList'], this);
	},
	
	requestCategoryNav: function() {
		return {
			server: 'ProductListServer',
			handler: 'categoryNav',
			params: []
		};
	},
	requestBanner: function(id) {
		return {
			server: 'ProductListServer',
			handler: 'banner',
			params: [id]
		};
	},
	requestCaption: function(id) {
		return {
			server: 'ProductListServer',
			handler: 'caption',
			params: [id]
		};
	},
	requestCategoryList: function(id) {
		return {
			server: 'ProductListServer',
			handler: 'categoryList',
			params: [id]
		};
	},
	requestProductList: function(id) {
		return {
			server: 'ProductListServer',
			handler: 'productList',
			params: [id]
		};
	},
	
	selectCategory: function(id) {
		this.pageState.id = id;
		
		this.addRequest(this.requestCategoryNav(id));
		this.addRequest(this.requestBanner(id));
		this.addRequest(this.requestCaption(id));
		this.addRequest(this.requestCategoryList(id));
		this.addRequest(this.requestProductList(id));
		
		this.sendRequests();
	},
	attachProductScrollbar: function() {
		var content = $('abProdHomeScroll');
		var scrollbar = $('area');
		var handle = $('knob');
		var steps = content.getScrollSize().x - content.getSize().x
		
		var slider = new Slider(scrollbar, handle, {	
			steps: steps,
			mode: 'horizontal',
			onChange: function(step){
				var x = step;
				var y = 0;
				content.scrollTo(x,y);
			}
		}).set(0);
	},
	
	afterContentUpdate: function(responseClass) {
		switch (responseClass) {
			case 'productList':
				this.attachProductScrollbar();
				break;
		}
	}
});
