
window.onresize = doresize;

function getWidth()
{
	if (typeof(window.innerWidth) == 'number') 
	{
		//Non-IE
		return window.innerWidth;
	} 
	else if (document.documentElement &&
			(document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
		//IE 6+ in 'standards compliant mode'
		return document.documentElement.clientWidth;
	} 
	else if (document.body && (document.body.clientWidth || document.body.clientHeight))
	{
		//IE 4 compatible
		return document.body.clientWidth;
	}
}

function getHeight()
{
	if (typeof(window.innerWidth) == 'number') 
	{
		//Non-IE
		return window.innerHeight;
	} 
	else if (document.documentElement &&
			(document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
		//IE 6+ in 'standards compliant mode'
		return document.documentElement.clientHeight;
	} 
	else if (document.body && (document.body.clientWidth || document.body.clientHeight))
	{
		//IE 4 compatible
		return document.body.clientHeight;
	}
}

function doresize()
{
	info = document.getElementById("fileinfo");
	list = document.getElementById("filelist");
	
	if (info)
	{
		info.style.height = getHeight() - 280;
	}
	if (list)
	{
		list.style.height = getHeight() - 280;
		list.style.width = getWidth() - 276;
	}
}

var currItem;
var currDirectory = "";

function selectItem(item)
{
	if (item)
	{
		item.className = "item selected";
	}
	currItem = item;
}

function deselectItem(item)
{
	if (item)
	{
		item.className = "item";
	}
	currItem = null;
}

function clickItem(itemId)
{
	if (currItem) 
	{
		deselectItem(currItem);
	}
	selectItem(document.getElementById(itemId));

	fileIcon = "Please select an item";
	filePath = currDirectory;
	fileInfo = "";
	if (currItem)
	{
		fileInfo = "<b>" + currItem.getAttribute("filename") + "</b><br />";
		fileInfo += currItem.getAttribute("filetype") + "<br />";
		if (!currItem.getAttribute("directory"))
		{
			fileInfo += "<br />";
			fileInfo += "Date modified: " + currItem.getAttribute("modified") + "<br />";
			fileInfo += "<br />";
			fileInfo += "Size: " + currItem.getAttribute("filesize") + "<br />";
		}

		if (currItem.getAttribute("directory")) {
			filePath = "<a href=\"" + currItem.getAttribute("fullfilename") + "\">" + currDirectory + currItem.getAttribute("filename") + "</a>";
			fileIcon = "<img src=\"../images/filetypes/folder.gif\" alt=\"\" width=\"48\" height=\"48\" />";
		} else if (currItem.getAttribute("thumbnail") == true) {
			filePath = "<a href=\"" + currItem.getAttribute("fullfilename") + "\">" + currItem.getAttribute("fullfilename") + "</a>";
			fileIcon = "<img src=\"" + currItem.getAttribute("icon") + "\" alt=\"\" />";
		} else {
			filePath = "<a href=\"" + currItem.getAttribute("fullfilename") + "\">" + currItem.getAttribute("fullfilename") + "</a>";
			fileIcon = "<img src=\"" + currItem.getAttribute("icon") + "\" alt=\"\" />";
		}
	}
	document.getElementById("fileinfotext").innerHTML = fileInfo;
	document.getElementById("fileinfoicon").innerHTML = fileIcon;
	document.getElementById("filepath").innerHTML = filePath;
}

function executeItem(filename)
{
	window.location = filename;
}
