/**
 * Performance.js
 * Copyright 2007,2008 David Lindquist (DavidEzek@gmail.com)
 *
 * Small class for displaying performance information.
 * Fri Apr 11 18:21:58 PDT 2008
**/

var Performance = (function(){
	function Performance(title, startTime, description, website){
		var title = title;
		if(startTime){
			var startTime = new Date(startTime);
		}
		var description = description;
		var website = website;

		this.getDate = function(){
			return (startTime.getMonth() + 1) + '.' + startTime.getDate() + '.' + (startTime.getYear() + 1900);
		}

		this.getDiv = function(){
			var div = document.createElement('div');
			div.className = 'perfDiv';
			var link = document.createElement('a');
			
			// If we have a date, prepend it.
			if( startTime ){
				link.appendChild(document.createTextNode( this.getDate() ));
				link.appendChild(document.createTextNode( ': ' ));
			}

			// Create link that controls the hiding/showing of the performance info.
			link.appendChild(document.createTextNode( title ));
			link.className = 'perf';
			var hidden = true;
			link.href = '#';
			link.onclick = function(){
				hidden = !hidden;
				if(hidden){
					info.style.display = 'none';
				}
				else {
					info.style.display = 'block';
				}
			}

			
			var info = document.createElement('div');
			if( description ){
				info.appendChild(document.createTextNode( description ));
				info.appendChild(document.createElement('br'));
			}
			if( website ){
				var weblink = document.createElement('a');
				weblink.href = website;
				weblink.appendChild(document.createTextNode( website ));
				info.appendChild(weblink);
				info.appendChild(document.createElement('br'));
			}
			if(hidden){
				info.style.display = 'none';
			}
			else {
				info.style.display = 'block';
			}

			info.style.paddingLeft = '1em';
			div.appendChild(link);
			div.appendChild(info);
			return div;
		}
	}
	return Performance;
})();
