var Path = new Object ();

/*

*/

Path.initialize = function (_content, _concElement)
{
	this.content 			= _content;
	this.conc_element	=	_concElement // concatenation element
	
	// Cleanning array
	if (isSet (this.path))
	{
		var len = this.path.length;
		for (var i=0; i < len; i++)
			this.path.pop();
	}
	else // Creating new array
		this.path = new Array();
};

Path.push = function (value)
{
	this.path.push(value);
};

Path.pop = function ()
{
	if (this.path.length == 0)
		return false;

	this.path.pop ();
	return true;
};

Path.back = function ()
{
	// if there is what to pop, update the shown directories
	if (Path.pop ())
		TaskManager.add_task ("Path.get_folders");
	
	return false;
};

Path.back_to_main = function ()
{
	// if there is what to pop, update the shown directories
	while (Path.pop ());
	
	TaskManager.add_task ("Path.get_folders");
	
	return false;
};

Path.get_full_path = function ()
{
	var string_path = "";
	for (var i=0; i < this.path.length; i++)
	{
		if (string_path.length > 0)
			string_path += "/";
		string_path += this.path[i];
	}
	
	return string_path;
};

Path.allow_folders_access = function (_class)
{
	var a_elements = this.content.getElementsByTagName("A");
	
	for (var i=0; i < a_elements.length; i++)
	{
		var element = a_elements[i];
		if (element.className.indexOf (_class) > -1)
		{
			element.onclick = function (_event)
			{
				if (_event == null) _event = window.event; // necessary for many browsers (for using `window.event`)
				
				// won't get more than one press
				if (this.getAttribute ("Busy"))
					return false;
				this.setAttribute ("Busy", true);
				
				// Cancel other events
				if (isSet (_event.cancelBubble))
					_event.cancelBubble=true; //IE
				else
					_event.stopPropagation(); //FF
				
				var value = isSet (this.getAttribute ("path")) ? this.getAttribute ("path") : this.innerHTML;
				Path.push (value);
				
				TaskManager.add_task ("Path.get_folders");
				
				return false;
			};
		}
	}
};

Path.display_path = function ()
{
	if (! isSet (this.conc_element)) // if not set concatenation element
		return false;
	
	// script not done yet
};

Path.get_folders = function ()
{
	var postData = 'path='+Path.get_full_path();
	
	FormHandler.submitGetHtml (this.content, 'system_bin.php?page=folders', postData);
};

