new function() {
	this.__construct = function() {
		this.use_ie = ( typeof window.attachEvent=='object' );
		
		if ( !this._init() ) {
			this.__listen( window, 'load' );
		}
	};
	
	this.__listen = function( elem, type ) {
		var _this = this;
		
		if ( this.use_ie ) {
			elem.attachEvent( 'on'+type, function(e){_this.__handler(e)} );
		}
		else {
			elem.addEventListener( type, function(e){_this.__handler(e)}, false );
		}
	};
	
	this.__handler = function( evt ) {
		var target = ( this.use_ie ) ? evt.srcElement : evt.target;
		
		switch ( evt.type ) {
			case 'load':
				this._init();
				break;
			case 'mousedown':
				switch ( target ) {
					case this.thumb:
						if ( !this.animated ) {
							this.drag_mouse_loc = evt.clientX;
							this.drag_thumb_loc = this.loc;
							this.dragging = true;
						}
						
						if ( !this.use_ie ) {
							evt.preventDefault();
						}
						break;
					default:
						while( target && target.nodeName!='BODY' && target!=this.elem ) {
							target = target.parentNode;
						}
						
						if ( target==this.elem ) {
							if ( !this.use_ie ) {
								evt.preventDefault();
							}
						}
				}
				break;
			case 'mousemove':
				if ( this.dragging ) {
					this.loc = this.drag_thumb_loc+( evt.clientX-this.drag_mouse_loc );
					this.loc = ( this.loc<0 ) ? 0 : ( ( this.loc>this.max_loc ) ? this.max_loc : this.loc );
					this._update();
				}
				break;
			case 'mouseup':
				if ( this.dragging ) {
					this.dragging = false;
				}
				break;
			case 'selectstart':
				evt.returnValue = false;
				break;
		}
	};
	
	this._init = function() {
		if ( this._init_comparator() ) {		
			if ( this.animated ) {
				this.__listen( this.elem, 'mousedown' );
			
				if ( this.use_ie ) {
					this.__listen( this.elem, 'selectstart' );
				}
				
				this._start();
			}
			else {
				this.__listen( document, 'mousemove' );
				this.__listen( document, 'mouseup' );
			}
			
			return true;
		}
		
		return false;
	};
	
	this._init_comparator = function() {
		this.elem = document.getElementById( '_comparator' );
		
		if ( this.elem ) {
			this.animated = ( this.elem.getAttribute( '_animated' )=='true' );
			
			this._init_columns();
			this._init_slider();
			this._init_thumb();
			
			this.max_height = 105; //210; //105;
			
			this.max_loc = parseInt( this.elem.style.width )-79;
			this.loc = 0;
			
			this._init_max_value();
			this.value = 0;
			
			this._update();
			
			return true;
		}
		
		return false;
	};
	
	this._init_columns = function() {
		var graph = document.getElementById( '_cmp_graph' );
		var col;
		var i = 0;
		var j;
		
		this.cols = new Array();
		while ( i<graph.rows[0].cells.length ) {
			col = { 'label': null, 'bar': null };
			
			elems = graph.rows[0].cells[i].getElementsByTagName( 'SPAN' );
			j = 0;
			while( j<elems.length ) {
				if ( elems[j].getAttribute( '_type' )=='barlbl' ) {
					col.label = elems[j];
					break;
				}
				j++;
			}
			
			elems = graph.rows[0].cells[i].getElementsByTagName( 'DIV' );
			j = 0;
			while( j<elems.length ) {
				if ( elems[j].getAttribute( '_type' )=='bar' ) {
					col.bar = elems[j];
					break;
				}
				j++;
			}
			
			if ( col.label!=null && col.bar!=null ) {
				this.cols.push( col );
			}
			
			i++;
		}
	};
	
	this._init_slider = function() {
		this.slider = document.getElementById( '_cmp_slider' );
	};
	
	this._init_thumb = function() {
		this.thumb = document.getElementById( '_cmp_thumb' );
		
		if ( !this.animated ) {
			this.__listen( this.thumb, 'mousedown' );
		
			if ( this.use_ie ) {
				this.__listen( this.thumb, 'selectstart' );
			}
		}
	};
	
	this._init_max_value = function() {
		var value;
		var i = 0;
		
		this.max_value = 0;
		while( i<this.cols.length ) {
			value = this._get_column_value( i, 100 );
			if ( value>this.max_value ) {
				this.max_value = value;
			}
			i++;
		}
	};
	
	this._start = function() {
		if ( !this.timer ) {
			var _this = this;
			this.timer = window.setInterval( function(){_this._animate()}, 60 );
		}
	};
	
	this._stop = function() {
		if ( this.timer ) {
			window.clearTimeout( this.timer );
			this.timer = null;
		}
	};
	
	this._wait = function() {
		this.timer = null;
		this._start();
	};
	
	this._animate = function() {
		if ( this.loc==this.max_loc ) {
			this._stop();
			
			this.loc = -1;
			
			var _this = this;
			this.timer = window.setTimeout( function(){_this._wait()}, 4000 );
			
			return;
		}
		else {
			this.loc += 1;
		}
		this._update();
	};
	
	this._update = function() {
		var value = this.loc/this.max_loc;
		/*if ( value<=0.2 ) {
			value = ( value/0.2 )*.01;
		}
		else if ( value<=0.4 ) {
			value = ( ( value-0.2 )/0.2 )*.04+.01;
		}
		else if ( value<=0.6 ) {
			value = ( ( value-0.4 )/0.2 )*.05+.05;
		}
		else if ( value<=0.8 ) {
			value = ( ( value-0.6 )/0.2 )*.4+.1;
		}
		else {
			value = ( ( value-0.8 )/0.2 )*.5+.5;
		}*/
		this.value = value*100;
		
		this._update_slider();
		this._update_thumb();
		this._update_cols();
	};
	
	this._update_slider = function() {
		this.slider.rows[0].cells[0].style.width = this.loc+'px';
		this.slider.rows[0].cells[1].style.width = (this.max_loc-this.loc)+'px';
	};
	
	this._update_thumb = function() {
		this.thumb.style.left = this.loc+'px';
	};
	
	this._update_cols = function() {
		var value;
		var i = 0;
		
		while( i<this.cols.length ) {
			value = this._get_column_value( i, this.value );
			this.cols[i].label.innerHTML = this._format_money( value );
			this.cols[i].bar.style.height = ( this.max_value==0 ) ? '0px' : parseInt( ( value/this.max_value )*this.max_height )+'px';
			i++;
		}
	};
	
	this._format_money = function( amt ) {
		amt = Math.round( amt );
		
		amt = amt.toString();
		
		amt = amt.split( "" );
		amt.reverse();
		amt = amt.join( "" );
		
		amt = amt.match( /[0-9]{0,3}/g );
		amt.pop();
		amt = amt.join( "," );
		
		amt = amt.split( "" );
		amt.reverse();
		amt = amt.join( "" );
		
		return '$'+amt;
	};
	
	this._get_column_value = function( col, value ) {
		switch ( col ) {
			case 0:
				return ( value<=5 ) ? value*6720 : 6720*5+( ( value-5 )*4800 );
			case 1:
				return value*22000;
			case 2:
				return value*26200;
			default:
				return 0;
		}
	};
	
	this.__construct();
}

var bubble = new function() {
	this.elem = null;
	this.timer = null;
	this.opacity = 1.0;
	this.dir = -1.0;
	
	this.open = function() {
		this.dir = 1.0;
		if ( this.opacity<1.0 && !this.timer ) {
			var _this = this;
			this.timer = window.setInterval( function(){_this.animate()}, 1 );
		}
	};
	
	this.close = function() {
		this.dir = -1.0;
		if ( this.opacity>0.0 && !this.timer ) {
			var _this = this;
			this.timer = window.setInterval( function(){_this.animate()}, 1 );
		}
	};
	
	this.animate = function() {
		this.opacity += this.dir*.1;
		this.opacity = ( this.opacity<0 ) ? 0 : ( ( this.opacity>1.0 ) ? 1.0 : this.opacity );
		
		if ( !this.elem ) {
			this.elem = document.getElementById( '_cmp_bubble' );
		}
		
		this.elem.style.opacity = this.opacity;
		
		if ( ( this.dir>0 && this.opacity==1.0 ) || ( this.dir<0 && this.opacity==0.0 ) ) {
			window.clearTimeout( this.timer );
			this.timer = null;
		}
		
		if ( this.opacity>0.0 && this.elem.style.display!='block' ) {
			this.elem.style.display = 'block';
		}
		else if ( this.opacity==0.0 && this.elem.style.display!='none' ) {
			this.elem.style.display = 'none';
		}
	};
};

// Hack to prevent text selection on IE during slider drag
try
{	if(window.jQuery != undefined)
	{	var $money_span = jQuery(".money_box > span");
		if($money_span.length > 0)
		{	var span = $money_span.get(0);
			if(span && span.onselectstart != undefined)
		        span.onselectstart=function(){return false};
		}
	}
} catch(err){}
