var team = [];
var activeMember;

function registerTeamItem ( id, imgoff, imgon , membername, membertitle )
{
	//alert ( id + " : " + imgoff + " : " + imgon) ;
	var obj = new Object ( ) ;
	obj.id = id;
	obj.membername = membername;
	obj.membertitle = membertitle;
	if ( imgoff !== null )
	{
		obj.off = new Image ( ) ;
		obj.off.src = imgoff;
	}
	if ( imgon !== null )
	{
		obj.on = new Image ( ) ;
		obj.on.src = imgon;
	}
	
	team.push ( obj ) ;
	
}


function drawThumbs ( target , initActiveId )
{
	//alert ( "drawThumbs : " + target)
	for ( i = 0 ; i < team.length ; i++ )
	{
		
		var member = team [ i ] ;
		
		
		if ( member.off !== undefined )
		{
			
			var cont = document.createElement( 'div' );
			var thumb = document.createElement( 'img' );
			thumb.id = member.id;
			thumb.src = member.off.src;
			cont.className ="teamThumb";
			member.thumb = thumb;
			
			var caption = document.createElement( 'p' );
			caption.innerHTML = member.membername+'<br />'+member.membertitle;		
			
			var t = this;
			thumb.onmouseup = function () {
				
				t.showMember ( this );
				
			}
			thumb.onmouseover = function () {
				
				t.showRollOver ( this );
			}
			
			thumb.onmouseout = function () {
				
				t.hideRollOver ( this );
			}
			
			cont.appendChild ( thumb );
			cont.appendChild ( caption );
			target.appendChild ( cont );
			
		}
	}
		
	if ( initActiveId != undefined ) showById ( initActiveId );
} 

function showById ( __id )
{
	//alert ( 'showById : ' + __id);
	for ( var member in team )
	{
		//alert ( team[member].id );
		if ( team [member ].id == __id )
		{
			showMember ( team[member].thumb );
			break;
		}
	}
} 
function showMember ( thumb )
{
	activeMember = thumb;
	//alert ( 'showMember : ' + thumb.id);
	var newID = thumb.id;
	//alert ( newID );
	for ( var i = 0 ; i < team.length ; i++ )
	{
		var copy = document.getElementById( 'copy_'+team [ i ].id );
		var copyOurTeam = document.getElementById( 'copy_ourteam' );
		//alert ( homecopy ) ;
		
		//alert ( copy + " : " + thumb );
		if ( team [ i ] .id == newID )
		{
			copyOurTeam.className = "nonvisible";
			copy.className = "visible";
			if ( team [ i ] .on !== undefined ) team[i].thumb.src = team[i].on.src;
		}	
		else
		{
			copy.className = "nonvisible";
			if ( team [ i ] .off !== undefined ) team[i].thumb.src = team[i].off.src;
		}
	}
	
}

function showRollOver ( thumb )
{
	
	for ( var i = 0 ; i < team.length ; i++ )
	{
		if ( team [ i ].id == thumb.id)
		{
			thumb.src = team[i].on.src;
			break;
		}
		
	}
}
function hideRollOver ( thumb )
{
	if ( activeMember != thumb )
	{
		for ( var i = 0 ; i < team.length ; i++ )
		{
			if ( team [ i ].id == thumb.id)
			{
				thumb.src = team[i].off.src;
				break;
			}
		}
			
	}
}