
/**
req.oncomplete = function () {
	response = this.responseText;
}
req.getText("http://localhost/stream/desc.rest.php?uid=94b8245be5a8f44ff314613744dac8f9");
*/




window.onload = function () {


	dias = document.getElementsByTagName("ul");
	
	for(i=0;i<dias.length;i++) {
		ul = dias[i];
		if( ul.className.match ( /day/ ) ) {
			
			lis = ul.getElementsByTagName("li");
			for(j=0;j<lis.length;j++) {
				li = lis[j];
				if(li.className.match( /item/ ) ) {
					addStreamBehaviour(li);
				}
					
			}
		
		}
	}

	
}


function showDescription() {
    if (!arguments.length) return;
    var objLnk = arguments[0];
	if( objLnk.className.match( /clicked/ ) ) {
		objLnk.className = objLnk.className.replace( /clicked/, '' );
		
		divs = window.document.getElementById('item-'+objLnk.rel).getElementsByTagName('div');
		if( divs.length > 0 ) {
			div 	= divs[0];
			div.style.display = div.style.display != 'none' ? 'none':'block';
		}
			
		return false;
	}	
    
	objLnk.className += ' clicked';

	uid = objLnk.getAttribute("rel");
	
	req.uid = uid;
	req.oncomplete = function () {

		obj = window.document.getElementById("item-"+this.uid);
		
		
		if( obj ) {
			divs = obj.getElementsByTagName('div');
			if( divs.length > 0 ) {
				div 	= divs[0];
				div.style.display = div.style.display != 'none' ? 'none':'block';
			} else {


				divs = obj.getElementsByTagName("div");
				if( divs.length == 0 ) {
					div = window.document.createElement("div");
					div.className = "item-description";
					div.innerHTML = this.responseText;
					obj.appendChild(div);
				}
			}
		}	
	};
	/**
		alert(this.uid);
		return false;

		obj = window.document.getElementByid("item-"+this.uid);
		if( obj ) {			
			div = window.document.createElement("div");
			div.className = "description";
			
			div.innerHtml = $this->responseText;
			
			obj.appendChild(div);
		} else
			alert("not obj");
		
	};*/
	
	req.getText("./desc.rest.php?uid="+uid );
	
	return false;

}
function addStreamBehaviour( obj ) {
	
	as = obj.getElementsByTagName("a");
	a=as[0];

    a.setAttribute( 'onclick', 'javascript:showDescription(this);return false;' );
	//a.onclick = showDescription;

}

