

TimeSlider=function(container){
    var _self=this;
    var _slider_left=26;
    var _slider_right=230;
    var startDate=new Date("5/12/2008");       
    var currentDate=new Date("5/12/2008");      
    var tempDate=new Date();                    
    var _mouseX;
    
    var _container=container;
    
	var _leftButton=document.createElement("img");
	_leftButton.id="leftButton";
	_leftButton.src="images/arrow_w_norm.png";
	_leftButton.style.height="26px";
	_leftButton.style.cursor="hand";
	_leftButton.onmouseover=function(){this.src='images/arrow_w_active.png';};
	_leftButton.onmouseout=function(){this.src='images/arrow_w_norm.png';};
	_leftButton.onclick=function()
	{
	    if(parseInt(_slider.style.left)>=_slider_left&&(currentDate.getTime()-startDate.getTime())>=(24*60*60*1000))
	    {
	        currentDate.setTime(currentDate.getTime()-(24*60*60*1000));
	        _self.refresh();
	    }
	};
	
	var _sliderScale=document.createElement("img");
	_sliderScale.id="sliderScale";
	_sliderScale.src="images/time_minus_hover.png";

	var _rightButton=document.createElement("img");
    _rightButton.id="rightButton";
	_rightButton.src="images/arrow_e_norm.png";
	_rightButton.style.height="26px";                               
	_rightButton.style.cursor="hand";                               
	_rightButton.onmouseover=function(){this.src='images/arrow_e_active.png';};
	_rightButton.onmouseout=function(){this.src='images/arrow_e_norm.png';};   
    _rightButton.onclick=function(){
	    if(parseInt(_slider.style.left)<=230&&(new Date("6/20/2008").getTime() - currentDate.getTime())>=(24*60*60*1000))
	    {
	        currentDate.setTime(currentDate.getTime()+(24*60*60*1000));
	        _self.refresh();
	    }	    
	};
    
	var _slider=document.createElement("div");
	_slider.id="slider";
	_slider.style.position="absolute";
	_slider.style.top="4px";
	_slider.style.left=_slider_left;
	_slider.style.width="200px";
	
	var _sliderSpan=document.createElement("span");
	_sliderSpan.innerHTML=currentDate.toLocaleDateString();
	_sliderSpan.style.fontSize="12px";
	_sliderSpan.style.color="#6633FF";
	_sliderSpan.style.fontWeight="bold";

	var _sliderImage=document.createElement("img");
	_sliderImage.src="images/timebar_norm.png";
	_sliderImage.onmouseover=function(){this.src='images/timebar_active.png';};
	_sliderImage.onmouseout=function(){this.src='images/timebar_norm.png';};  
	_sliderImage.onmousemove=function(){
	    if(event.button==1)
	    {
	        var tempX=event.x-_mouseX;
	        if(tempX<=230&&tempX>_slider_left)
	        {
	            var tempScale=parseInt((tempX-_slider_left)/5);
	            tempDate.setTime(startDate.getTime()+(24*60*60*1000)*tempScale);
	            if((new Date("6/20/2008").getTime() - tempDate.getTime())>=0)
	            {
	                this.parentNode.style.left=_slider_left+tempScale*5;
	                currentDate.setTime(startDate.getTime()+(24*60*60*1000)*tempScale);
	                _self.refreshSliderSpan();
	            } 
	        }  
	    }
	};
	_sliderImage.onmouseup=function(){
	    this.releaseCapture();
	    getZhenYuan(_self.toFormatString());
	    
	};
    _sliderImage.onmousedown=function(){
        _mouseX=event.x-this.parentNode.style.pixelLeft;
        this.setCapture();
	};	

	this.initlize=function(){
		var table=document.createElement("table");
		
		table.insertRow();
        table.cellPadding=0;
		table.cellSpacing=0;
		table.rows[0].insertCell();
		table.rows[0].cells[0].appendChild(_leftButton); 
		table.rows[0].insertCell();
		table.rows[0].cells[1].appendChild(_sliderScale); 
		table.rows[0].insertCell();
		table.rows[0].cells[2].appendChild(_rightButton); 
		
		_container.appendChild(table);

		_slider.appendChild(_sliderImage);
		_slider.appendChild(document.createElement("br"));
		_slider.appendChild(_sliderSpan);

		_container.appendChild(_slider);
		
		this.setCurrentTime(new Date("6/20/2008"));		
	};
    this.toFormatString=function(){
        return  currentDate.getFullYear()+"-"+(currentDate.getMonth()+1)+"-"+currentDate.getDate();
    };
    this.show=function(){
        _container.style.visibility="visible";
    };
    this.hide=function(){
        _container.style.visibility="hidden";
    };
    this.refresh=function(){
        this.refreshSlider();
        this.refreshSliderSpan();
    };
    this.refreshSlider=function(){
        if(_slider_left<=(_slider_left+5*(currentDate.getTime()-startDate.getTime())/(24*60*60*1000))&&(_slider_left+5*(currentDate.getTime()-startDate.getTime())/(24*60*60*1000))<=230)  
        {
            _slider.style.left=_slider_left+5*parseInt((currentDate.getTime()-startDate.getTime())/(24*60*60*1000));
        }
        getZhenYuan(this.toFormatString());
    };
    this.refreshSliderSpan=function(){
        _sliderSpan.innerHTML=currentDate.toLocaleDateString();  
    };
    this.setCurrentTime=function(obj){
        currentDate=obj;
        this.refresh();
    }; 
}



