

StationaryDivs = new function()
{

  $(window).bind("scroll.StationaryDivs", function(){
	  StationaryDivs.Refresh();
  });	


  var _stationaryDivs = new Storage();
  
	return{
	
	  Add: function(div){
		  var s = new StationaryDiv(div);
			_stationaryDivs.AddComponent(s, s.ID);
			StationaryDivs.Current = s;
			StationaryDivs.Current.Refresh();
		},
		
		Current: null,
		
		Get: function(id)
		{
		  this.Current = _stationaryDivs.GetComponent(id);
			return this.Current;
		},
		
  
		Refresh: function()
		{
		  if(StationaryDivs.Current)
  		  StationaryDivs.Current.Refresh();
		
		}
	
	}

}




function StationaryDiv(DivElement)
{
  var _div = $(DivElement);
	
	Setup();	
	
	this.ID = _div.attr("id");
	
	this.MouseDown = false;
	
	this.minHeight = 100;

	this.StartY = 0;


	
	this.Minimize = function()
	{
		_div.css("display", "none")
	}
	
	this.Restore = function()
	{
		_div.css("display", "block");
	}
	
	this.Resize = function(e)
	{
	  if(e.button == 0)
		  return;
		
    var _scroll = (document.all)?document.body.scrollTop:window.pageYOffset;
    
    var winH = document.body.offsetHeight;
		
		var diff = this.StartY - e.pageY;
		
		var _t = Utilities.ToNumber(_div.css("top"));
		
		var heit = Utilities.ToNumber(_div.css("height"));		
		
		_div.css("top", _t - diff);
		
		var _h = heit + diff;

		_div.css("height", _h);		
		
		this.StartY = e.pageY;		
	

	}
	
	
	
	
	this.Refresh = function(){
	
		return;
				
    var _scroll = (document.all)?document.body.scrollTop:window.pageYOffset;
    
    var winH = document.body.offsetHeight;
    
    var winW = document.body.offsetWidth;
    
    var t = winH - _div.height() + _scroll;
    
    _div.css("top", t).css("width", winW);

	}
	
  this.SetTitle = function(title)
	{
	  _div.find(">h3").text(title);
	}
	

	
	
	function Setup(){
	  var handle = _div.find(">h3");

  	handle.css("cursor", "n-resize");		
		
		handle.click(function(e){
	    var id = $(this).parents('.StationaryDiv').attr("id");
			var div = StationaryDivs.Get(id);
			StationaryDivs.Current = div;
		});
			
		handle.mousedown(function(e){
			StationaryDivs.Current.MouseDown = true;
			StationaryDivs.Current.StartY = e.pageY;
		});
		
		handle.mouseup(function(){
	    StationaryDivs.Current.MouseDown = false;
		});
		
		$("body").bind("mousemove.StationaryDiv", function(e){
		  if(!StationaryDivs.Current.MouseDown)
			  return;
				
			StationaryDivs.Current.Resize(e);  
		
		});
		
	}

}


