// #################################################

function Dost_Wrapper()
{
	this.id = 'wrapper';
	//-------------------
	this.Show = function()
	{
		$j('#'+this.id).show();
	};
	this.Hide = function()
	{
		$j('#'+this.id).hide();
	};
	//-------------------
}

// #################################################

function Dost_WindowSource( id , exit , exit_action )
{
	this.id = id;
	this.exit = exit;
	this.exit_action = exit_action;
	//-------------------
	this.SetContent = function( html )
	{
		$j('#'+this.id).html( html );
	};
	this.GetContent = function()
	{
		return $j('#'+this.id).html();
	};
	this.ClearContent = function()
	{
		$j('#'+this.id).html( '' );
	};
	//-------------------
}

// #################################################

function Dost_WindowContent() 
{
	this.id = 'fast_window_content';
	//-------------------
	this.Show = function()
	{
		$j('#'+this.id).show();
	}
	this.Hide = function()
	{
		$j('#'+this.id).hide();
	}
	//-------------------
	this.Set = function( html )
	{
		$j('#'+this.id).html( html );
	}
	this.Get = function()
	{
		return $j('#'+this.id).html();
	}
	this.Clear = function()
	{
		$j('#'+this.id).html( '' );
	}
	//-------------------
	this.Clear();
	this.Show();
	//-------------------
}

// #################################################

function Dost_WindowButtonExit() 
{
	this.id = 'fast_window_button_exit';
	this.action_click = '';
	//-------------------
	this.Show = function()
	{
		$j('#'+this.id).show();
	}
	this.Hide = function()
	{
		$j('#'+this.id).hide();
	}
	//-------------------
	this.Click = function()
	{
		if( this.action_click != '' )
		{
			eval(this.action_click);
			return true;
		}
		return false;
	}
	//-------------------
	this.Hide();
	//-------------------
}

// #################################################

function Dost_Window() 
{
	this.id = 'fast_window_container';
	this.content = new Dost_WindowContent();
	this.button_exit = new Dost_WindowButtonExit();
	//-------------------
	this.SetSource = function( source )
	{		
		this.content.Set(source.GetContent());
		this.content.Show();
		
		if( source.exit )
			this.button_exit.Show();
		else
			this.button_exit.Hide();
			
		this.button_exit.action_click = source.exit_action;
	}
	//-------------------
	this.Show = function()
	{
		$j('#'+this.id).show();
		$j('#'+this.id).css('margin-left',($j(document).width()/2-$j('#'+this.id).width()/2)+'px');
	}
	this.Hide = function()
	{
		$j('#'+this.id).hide();
	}
	//-------------------
	this.Hide();
	//-------------------
}

// #################################################

function Dost_WindowManager() 
{
	this.wrapper = new Dost_Wrapper();
	this.window = new Dost_Window();
	this.sources = new Array();
	//-------------------
	this.AddSource = function( source )
	{
		var temp_index = this.GetIndexSource(source.id);
		if( typeof temp_index == 'number' ) return false;
		
		this.sources[this.sources.length] = source; 
		return true;
	};
	this.RemoveSource = function( id_source )
	{
		var temp_index = this.GetIndexSource(id_source);
		if( typeof temp_index == 'undefined' ) return false;
		
		this.sources.splice(temp_index,1);
		return true;
	};
	this.GetIndexSource = function( id_source )
	{
		for(var i=0; i<this.sources.length; i++)
		{
			if( this.sources[i].id == id_source )
			return i;
		}
		return undefined;
	}
	//-------------------
	this.Open = function( id_source )
	{
		var temp_index = this.GetIndexSource(id_source);
		if( typeof temp_index == 'undefined' ) return false;
				
		this.window.SetSource(this.sources[temp_index]);
		
		this.wrapper.Show();
		this.window.Show();
		
		return true;
	};
	this.Close = function()
	{
		this.window.Hide();
		this.wrapper.Hide();
	
		return true;
	};
	//-------------------
	this.Close();
	//-------------------
}

// #################################################

var window_manager = new Dost_WindowManager();

// #################################################
