function List(myList,parentPath,initialPath) {
	var instance=this;
	this.__parentPath__ = parentPath;
	this.__myList__ 	= myList;
	this.__rootPath__	= initialPath||"";
	this.__httpREQ__	= AJAX.getHTTPRequest();
	
	this.listDir=_listDir;
	this.listDir(this.__rootPath__);
	
	this.__myList__.onclick=function(e) {
		e = e || window.event;
		var fe =  e.target || e.srcElement,
			isLeaf = fe.getAttribute("leaf");
		if( isLeaf == null ) {
			fe = fe.parentNode;
			isLeaf = fe.getAttribute("leaf");
		}		
	
		if( isLeaf!=null ) {
			if ( isLeaf == "true" ) {
				window.open( instance.__parentPath__ + fe.getAttribute("value") );
			} else {
				instance.listDir(fe.getAttribute("value"));
			}
		}
	};
};

function _listDir( path ) {
	var listingEl=document.getElementById("list");
	var oldContent="";
	var httpREQ=this.__httpREQ__;
	var request="/php/pressKit/navigate/navigate.php?op=list&dir="+path;
	httpREQ.open( "GET",request,true );
	httpREQ.onreadystatechange=function() {
		if( httpREQ.readyState==4 ) {
			if( httpREQ.status==200 ) {
				var tokens= httpREQ.responseText.split("|");
				setOpacity( listingEl, 1 );
				if( tokens[0]=="OK" ) {
					if (tokens[1] == "DIR") {
						listingEl.innerHTML = tokens[2];
					} else 
					if (tokens[1] == "FILE") {
						// error ??
						listingEl.innerHTML = oldContent;
					}
				}							
			}						
		}
	};
	oldContent=listingEl.innerHTML;
	//setOpacity( listingEl, 0.3 );
	httpREQ.send( null );
	var imgElement = document.getElementById( "imageLoadPressKit" );
		imgElement.style.display="none";
};


//////////////////
/////// AJAX ////
var AJAX={
	getHTTPRequest: function(){
		var http = null;
		if (window.XMLHttpRequest) 
			http = new XMLHttpRequest();
		else 
			if (window.ActiveXObject) 
				http = new ActiveXObject("Microsoft.XMLHTTP");
		return http;
	}
};

//////////////////
/////// opacity ////
function setOpacity(el,opacity) {
	if( !el.style ) return;
	if( typeof el.style.filter != 'undefined' ) {
		el.style.filter='alpha(opacity='+opacity*100+');';				
	} else {
		el.style.opacity=opacity;
	}
};
