
function gwsWineIndexChartCompact () {
	var self = this;
	
	this._category = 1;
	this._coverage = -1;
	this._period = 1;
	this._index = -1;

	this._clearChildrenTag = function ( domEl ) {
		if ( !domEl || !domEl.removeChild ) { return; }
		while ( domEl.firstChild ) {
			domEl.removeChild( domEl.firstChild );
		}
	};
	
	this._getElementById = function (objName) {
			if (document.layers) {return document.layers[objName].document;}
			else if (document.getElementById) {return document.getElementById(objName);}
			else if (document.all) {return window[objName];}
		};

	this._htmlDiv = function () {return this._getElementById('GWS_wineIndexChartCompact');};
	
	this.changeCategory = function (category) {self._category=category;self._index=-1;self.display();};
	this.changeCoverage = function (coverage) {self._coverage=coverage;self.display();};
	this.changePeriod = function (period) {self._period=period;self.display();};
	this.changeIndex = function (index) {self._index=index;self.display();};

	this.display = function () {
			var d = self._htmlDiv();
			if( !d ){ return; }
			
			var AjaxObject = {
				handleSuccess: function ( o ) {
					if ( !o.responseText ) { return AjaxObject.handleFailure( o ); }
					
					self._clearChildrenTag( d );
					d.innerHTML = o.responseText;					
				},
				
				handleFailure: function ( o ) {
				},
				
				startRequest: function ( config ) {
					YAHOO.util.Connect.asyncRequest( 
											'GET',
											'/wineIndexCompactUI.asp?wineIndex=' + encodeURI( self._index ) + '&coverage=' + encodeURI( self._coverage ) + '&period=' + encodeURI( self._period ) + '&category=' + encodeURI( self._category ),
											config,
											null
										);
				}
			};
			
			AjaxObject.startRequest(
				{
					success: AjaxObject.handleSuccess,
					failure: AjaxObject.handleFailure,
					timeout: 60000	// 1 minute
				});
		};
		
	setTimeout( function(){ self.display(); }, 100 );
};

var gwsCompactChart = new gwsWineIndexChartCompact();