// write things to screen nicely
say = function(str){
	try{
		window.loadFirebugConsole();
		console.log(str);
	}catch(e){
		alert(str);
	}
}

// shortcuts
var oDom	= YAHOO.util.Dom;
var oEvent	= YAHOO.util.Event;

YAHOO.namespace("Youniverse");

// progress stuff
YAHOO.Youniverse.profileProgress = function(){
	
	// globals
	var iVDNATotal;
	var aVDNACompleted;
	var sVDNAHint;
	var sVDNAHintLink;
	var iProfileTotal;
	var iProfileCompleted;
	var sProfileHint;
	var sProfileHintLink;
	
	// set total modules
	this.setVDNATotal = function(iNum){
		iVDNATotal = (iNum);
	}
	
	// set number of modules completed
	this.setVDNACompleted = function(){
		aVDNACompleted = arguments;
	}
	
	// calculate percentage of modules completed
	this.calcVDNAPercentage = function(){
		return (aVDNACompleted.length>iVDNATotal)? 100:Math.round((aVDNACompleted.length/iVDNATotal)*100);
	}
	
	// calculate VDNA progress and write to screen
	this.getVDNAProgress = function(){
		var iComplete = this.calcVDNAPercentage();
		oDom.get("VDNATotal").innerHTML = iComplete + '%';
		if(aVDNACompleted.length>0){
			var iSectionWidth	= Math.floor(iComplete/aVDNACompleted.length);
			var innerBar 		= ''
			for(i=0;i<aVDNACompleted.length;i++){
				innerBar += '<div class="bar-section" style="width: '+iSectionWidth+'%; background-color: #'+aVDNACompleted[i]+';"></div>';
			}
			innerBar += '<div class="clear"></div>';
			oDom.get("vdnaBarContainer").innerHTML = innerBar;
		}
		if(iComplete==100){
			oDom.setStyle("VDNAH5", "display", "none");
		}else{
			oDom.get("VDNAHint").innerHTML = sVDNAHint;
			oDom.get("VDNAHint").setAttribute("title", sVDNAHint);
			oDom.get("VDNAHint").setAttribute("href", sVDNAHintLink);
		}
	}
	
	// set the VDNA hint
	this.setVDNAHint = function(sHint,sLink){
		sVDNAHint 		= sHint;
		sVDNAHintLink 	= sLink;
	}
	
	// set total milestones
	this.setProfileTotal = function(iNum){
		iProfileTotal = (iNum);
	}
	
	// set number milestones completed
	this.setProfileCompleted = function(iNum){
		iProfileCompleted = (iNum);
	}
	
	// calculate percentage of milestones completed
	this.calcProfilePercentage = function(){
		return (iProfileCompleted>iProfileTotal)? 100:Math.round((iProfileCompleted/iProfileTotal)*100);
	}
	
	// set profile hint
	this.setProfileHint = function(sHint,sLink){
		sProfileHint 		= sHint;
		sProfileHintLink 	= sLink;
	}
	
	// calculate profile progress and write to screen
	this.getProfileProgress = function(){
		var iComplete = this.calcProfilePercentage();
		oDom.get("ProfileTotal").innerHTML = iComplete;
		oDom.setStyle("profileBar", "width", iComplete + "%");
		if(iComplete==100){
			oDom.setStyle("profileH5", "visibility", "hidden");
		}else{
			oDom.get("profileHint").innerHTML = sProfileHint;
			oDom.get("profileHint").setAttribute("title", sProfileHint);
			oDom.get("profileHint").setAttribute("href", sProfileHintLink);
		}
	}
	
	// begin!
	this.init = function(){
		this.getVDNAProgress();
		this.getProfileProgress();
	}

}

