/**
 * @author tom
 * 
 * compares booms and masts and apples and pears…
 */

var Comparator = Class.create( {
 	
	product			: '',
	url				: '',
	outerContainer	: '',
	createdContainer: '',
	currCompareID	: null,
	name: 'Comparator',
	
	setProduct: function(product) {
		this.product = product;
		this.outerContainer = this.product + '-table';
		this.createdContainer = 'compare-table';
	},
	
	setURL: function(url) {
		this.url = url;	
	},
 	
	 init: function(lang) {
		var scope = this;
		this.lang = lang;
		document.observe(
			'dom:loaded',
			function() {
				$('compare-submit').onclick = function() { 
					scope.getCompareTable(); 
					return false; 
				};
			}
		);
	},
	
	getCompareTable: function() {
		var selectValue = $('compareSelector').value;
		if ( this.currCompareID == selectValue || -1 == selectValue ) {
			return;
		}
		var scope = this;
		new Ajax.Request(
			this.url,
			{ 
				method		: 'post', 
				parameters	: 'prod2compare=' + selectValue + '&lang=' + scope.lang,		
				onSuccess	: 	function (request) { 
									scope.updateBoomTable( request.responseText.strip(), selectValue )
								}
			}
		);
	},

	updateBoomTable: function(contents, currID) {
		var scope = this;
		if ( $(this.createdContainer) ) {
			$(this.createdContainer).remove();
		}
		$(this.outerContainer).insert( { bottom: contents } );
		$(this.createdContainer).hide();
		new Effect.BlindDown( $(this.createdContainer), { duration: .5, afterFinish: scope.scrollViewport.bind(scope) } );
		this.currCompareID = currID;
	},	
	
	scrollViewport: function() {
		//window.location.hash = this.createdContainer;
		//$(this.createdContainer).scrollTo();
	}
	
 
 } );
 