var COLOR_GOLD = "#F7B201";
var COLOR_GRAY = "#5F543F";

function Project( name, constType, schoolType ){
	this.name = name;
	this.constType = constType;
	this.schoolType = schoolType;
	this.img = document.images[this.name + "Img"];
	Project.all[name] = this;
	
	Project.allLabels[this.constType] = document.getElementById("chk_constType_" + this.constType);
	Project.allLabels[this.schoolType] = document.getElementById("chk_schoolType_" + this.schoolType);
}
Project.all = new Array();
Project.allLabels = new Array();
Project.over = new Array();

Project.showAll = function(){
	for( var i in Project.all ){
		Project.all[i].show();
	}
	showProjectLabels();
}
Project.prototype.isVisible = function(){
	return Project.allLabels[this.constType].checked && Project.allLabels[this.schoolType].checked;
}
Project.prototype.show = function(){
	if( this.isVisible() ){
		var isOverS = Project.over.schoolType == this.schoolType;
		var isOverC = Project.over.constType == this.constType;
		
		var suffix = (isOverS || isOverC ) ? 'on' : 'off';
		this.img.src = '/images/portfolio/' + this.name + '_' + suffix + '.gif';
	}
	else{
		this.img.src = '/images/portfolio/empty_project.gif';
	}
	
}

Project.prototype.showDesc = function(on){
	if( this.isVisible() ){
		var div = document.getElementById( "projectDesc_" + this.name + "Div" );
		div.style.display = (on) ? "block" : "none";
	}	
	var div = document.getElementById( "portfolioDescDiv" );
	div.style.display = (on) ? "none" : "block";
}
function showProjectLabels(){
	for( var type in Project.allLabels ){
		Project.allLabels[type].parentElement.style.color = (type == Project.over.constType || type == Project.over.schoolType) ? COLOR_GOLD : COLOR_GRAY;
	}
}

/* mouse events */
Project.prototype.mouseover = function(){
	Project.over.constType = this.constType;
	Project.over.schoolType = this.schoolType;
	this.show();
	showProjectLabels();
	this.showDesc(true);
}
Project.prototype.mouseout = function(){
	Project.over = new Array();
	Project.showAll();
	this.showDesc(false);
}
function breakProjectLabel(id){
	return id.substr(4).split("_");
}
function mouseoverProjectLabel(a){
	var vals = breakProjectLabel(a.id);
	Project.over = new Array();
	Project.over[vals[0]] = vals[1];
	Project.showAll();	
}
function mouseoutProjectLabel(a){
	Project.over = new Array();
	Project.showAll();
}
function clickProjectLabel(a){
	var vals = breakProjectLabel(a.id);
	if( Project.lock == vals[1] ){
		Project.lock = "";
	}
	else{
		Project.lock = vals[1];
	}
	
	Project.showAll();
}