// JavaScript Document
var Artist = new Class({
	Extends: Page,
	
	messageObj: null,
	
	setArtistPhotoGallery: null,
	setArtistInfo: null,
	setProductList: null,
	setNewsSignupForm: null,
	
	initialize: function(pageState) {
		this.parent('artist', pageState);
		
		this.messageObj = new Message();
		
		this.setArtistPhotoGallery = this.setBlock.pass(['abBanner', 'artistPhotoGallery'], this);
		this.setArtistInfo = this.setBlock.pass(['divArtistInfo', 'artistInfo'], this);
		this.setProductList = this.setBlock.pass(['abSubContent', 'productList'], this);
		this.setNewsSignupForm = this.setBlock.pass(['abNewsSignUp', 'newsSignupForm'], this);
	},
	
	requestArtistPhotoGallery: function(id) {
		return {
			server: 'ArtistServer',
			handler: 'artistPhotoGallery',
			params: [id]
		};
	},
	requestArtistInfo: function(id) {
		return {
			server: 'ArtistServer',
			handler: 'artistInfo',
			params: [id]
		};
	},
	requestProductList: function(id) {
		return {
			server: 'ArtistServer',
			handler: 'productList',
			params: [id]
		};
	},
	requestNewsSignupForm: function() {
		return {
			server: 'ArtistServer',
			handler: 'newsSignupForm',
			params: []
		};
	},
	requestPersistNewsSignup: function(formValues) {
		return {
			server: 'ArtistServer',
			handler: 'persistNewsSignup',
			params: [formValues]
		};
	},
	
	selectPhoto: function(id) {
		$('imgMain').src = 'images/artist/' + id + '.jpg';
	},
	persistNewsSignup: function(form) {
		if (Validation.validateForm(form)) {
			this.addRequest(this.requestPersistNewsSignup(form.getFormValues()));
			this.sendRequests();
			form.reset();
		} else {
			this.messageObj.message('The form contains validation errors. Please correct and resend.', true);
		}
	},
	
	attachArtistInfoScrollbar: function() {
		var content = $$('.artistInfo .left .scroll')[0];
		var scrollbar = $('artistInfoArea');
		var handle = $('artistInfoKnob');
		var steps = content.getScrollSize().y - content.getSize().y
		
		var slider = new Slider(scrollbar, handle, {	
			steps: steps,
			mode: 'vertical',
			onChange: function(step){
				var x = 0;
				var y = step;
				content.scrollTo(x,y);
			}
		});
		slider.set(0);
	},
	attachProductListScrollbar: function() {
		var content = $('abProdHomeScroll');
		var scrollbar = $('productListArea');
		var handle = $('productListKnob');
		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);
			}
		});
		slider.set(0);
	},

	afterContentUpdate: function(responseClass) {
		switch (responseClass) {
			case 'artistInfo':
				this.attachArtistInfoScrollbar();
				break;
			case 'productList':
				this.attachProductListScrollbar();
				break;
		}
	}
});
