function PricingLevelMeter( labelVersion )
{ // Represents a pricing level meter.
  // Precondition:
  //   labelVersion: "expanded" | "condensed" (default)
  // Postcondition:
  //   When instantiated, represents a PricingLevelMeter object.
  
	// private:
	
	this.getPricingLabels = function( labelVersion )
	{ // Returns an array of pricing labels.
	  // Precondition:
	  //   labelVersion: "expanded" | "condensed" (default)
	  // Postcondition:
	  //   An array of strings is returned.
		
		var labelArray = null;
		
		if( labelVersion == "expanded" )
		{
			// There are 13 pricing levels
			labelArray = new Array(
				"Can't get any cheaper. What are you waiting for? Go!!",	// Level 1 (Lowest)
				"Cheap Stuff",	// Level 2
				"Still Cheap Stuff",	// Level 3
				"Affordable",			// Level 4
				"Affordable. Won't hurt trying.",	// Level 5
				"",	// Level 6
				"Hmmm, affordable, but make sure you carry plenty of cash.",	// Level 7 (Medium)
				"",	// Level 8
				"",	// Level 9
				"",	// Level 10
				"",	// Level 11
				"",	// Level 12
				"Expensive Stuff. Get ready to do the dishes!"	// Level 13 (Highest)
			);
		}
		else
		{
			// The pricing labels. 
			// There are 7 pricing levels in this version.
			labelArray = new Array(
				"Can't get any cheaper than this, pal. What are you waiting for? Go and eat!!",	// Level 1 (Lowest)
				"Somewhere between cheap and affordable.",	// Level 2
				"Affordable",	// Level 3
				"Hmmm, affordable. Carry plenty of cash just in case.",	// Level 4 (Medium)
				"Ay Caramba! Costly... Hope you have enough moolah.",	// Level 5
				"Moderately Expensive. Carry a fat wallet.",	// Level 6
				"Expensive Stuff. Get ready to do the dishes after eating!"	// Level 7 (Highest)
			);
		}
		
		return labelArray;
	}

	this.getLevelIndex = function( level )
	{ // Returns the index of the current pricing level. 
	  //    Used for referencing the pricing level's label.
	  // Precondition:
	  //   1 <= level <= number of pricing levels.
	  //   or omit parameter to use current level.
	  // Postcondition:
	  //   The pricing level index is returned.
	  //   If level is invalid, -1 is returned.

		var args = this.getLevelIndex.arguments;
		
		if( 0 == args )
			return this._level - 1;
		else if( this.isLevelValid( level ) )
			return level - 1;
		else
			return -1;					
	}			
			
	// private:
	
	this._labelVersion = labelVersion;
	
	this._level = 1;	// The current level
	
	this._pricingLabels = this.getPricingLabels( labelVersion );

	// public:

	this.getLevelCount = function()
	{ // Returns the number of pricing levels.
	  // Precondition: none.
	  // Postcondition:
	  //   An integer number is returned.
	  
		return this._pricingLabels.length;
	}
				
	this.isLevelValid = function( level )
	{ // Checks whether the supplied level is within the range of levels.
	  // Precondition: 
	  //   level: an integer number.
	  // Postcondition:
	  //   Returns true if level is in range.
	  
		return (typeof( level ) == "number") 
			&& (1 <= level) 
			&& (level <= this.getLevelCount());
	}
				
	this.getCurrentLevel = function()
	{ // Gets the current level
	  // Precondition: none
	  // Postcondition: 
	  //   The current level is returned.
	  
		return this._level;
	}
	this.setCurrentLevel = function( value )
	{ // Sets the current pricing level
	  // Precondition:
	  //   1 <= value <= number of pricing levels
	  // Postcondition:
	  //   If valid, value is set as the current level, 
	  //   otherwise an error will be displayed.
	  
		if( this.isLevelValid( value ) )
			this._level = value;
		else
			alert( "Invalid level supplied: " + value );
	}

	this.getLabel = function( level )
	{ // Returns the pricing level's label, given the level number.
	  // Precondition:
	  //   1 <= level <= number of pricing levels
	  //   or omit parameter to use current level.
	  // Postcondition:
	  //   If level is supplied, the label for that level is returned.
	  //   If no argument is supplied, the current level is used.
	  
		var args = this.getLabel.arguments;
		
		if( 0 == args.length )
			return this._pricingLabels[ this.getLevelIndex() ];
		else if( this.isLevelValid( level ) )
			return this._pricingLabels[ this.getLevelIndex( level ) ];
		else
		{
			alert( "Invalid level for label: " + level );
			
			return "";
		}
	}
	
	this.drawMeter = function( id, level )
	{ // Generates the pricing level meter.
	  // Precondition:
	  //   id    : a string that represents the ID of the 
	  //			HTML element where the meter is to be placed.
	  //   level : (optional) the desired pricing level, where
	  //			1 <= level <= number of pricing levels.
	  // Postcondition:
	  //   The pricing level meter is drawn in the supplied container (id).
	  //   If level is omitted, the current pricing level is used.
	  
		var args = this.drawMeter.arguments;
		
		// Use supplied level or current one
		level = ( 2 == args.length )? level : this.getCurrentLevel();
		
		// Set supplied level as the current level
		this.setCurrentLevel( level );
		
		// Obtain reference to supplied HTML element by its ID				
		var htmlElm = document.getElementById( id );
		
		if( htmlElm == null )
		{
			alert( "HTML element '" + id + "' was not found!" );
		}
		else
		{
			var pricingGauge = new GoogleOMeter();
			
			// Set up the pricingGauge's parameters
			if( this._labelVersion == "expanded" )
			{
				pricingGauge.setWidth( 450 );
				pricingGauge.setHeight( 240 );
			}
			else
			{
				pricingGauge.setWidth( 400 );
				pricingGauge.setHeight( 210 );
			}
			pricingGauge.setData( level.toString() );
			pricingGauge.setScaling( "1," + this.getLevelCount() );
			pricingGauge.setLabels( "Level " + level.toString() );
			pricingGauge.setColors( "008000,ffff00,ff0000" );
			pricingGauge.setFill( "bg,s,ffffff00" );
			
			pricingGauge.draw( id );
			
			// Append the pricing label to the htmlElm
			htmlElm.innerHTML += "<span>" + this.getLabel( level ) + "</span>";
		}
	}			
}


