var teamPicker,team,teamViewerUL,bio,newBio,so;


function showBio() {
	infoBox.exit();
	newName = this.getElementsByTagName('h3')[0].innerHTML;
	newTitle = this.getElementsByTagName('p')[0].innerHTML
	newBio = this.getElementsByTagName('p')[1].innerHTML;
	if (bio.innerHTML != newBio) {
		teamBioFx.start({
			'height': 0
		})
		$('teamFlash').showPhoto(newName + ',' + newTitle);
		this.setStyle('opacity',.25);
	}
}

function teamSetup(){

	// setup images
	$('team').addClass('active');
	teamPicker = $('teamPicker');
	team = $ES('#teamViewer li');
	teamViewerUL = $ES('#teamViewer ul')[0];

	window['teamSlideFx'] = new Fx.Styles(teamViewerUL, {
		duration: 400,
		wait: true,
		transition: Fx.Transitions.Expo.easeInOut
	});

	bio = $('bio');
	window['teamBioFx'] = new Fx.Styles(bio, {
		duration: 500,
		wait: true,
		transition: Fx.Transitions.Expo.easeInOut,
		onComplete: function() {
			if (this.element.offsetHeight == 0) {
				bio.innerHTML = newBio;
				teamBioFx.start({
					'height': this.element.scrollHeight
				});
			}
		}
	});

	window['arrowU'] = $('arrowU');
	arrowU.onclick = function() {
		newTop = parseInt(teamViewerUL.getStyle('top')) + teamViewerUL.parentNode.offsetHeight;
		if (newTop <= 0) {
			teamSlideFx.start({
				'top': newTop
			});
			if (newTop >= 0) {
				this.setStyle('opacity',.1);
			} else {
				arrowD.setStyle('opacity',.6);
			}
		}
	}
	arrowU.setStyle('opacity',.1)

	window['arrowD'] = $('arrowD');
	arrowD.onclick = function() {
		newTop = parseInt(teamViewerUL.getStyle('top')) - teamViewerUL.parentNode.offsetHeight;
		if (newTop > -(teamViewerUL.parentNode.offsetHeight*3)) {
			teamSlideFx.start({
				'top': newTop
			});
			if (newTop-teamViewerUL.parentNode.offsetHeight <= -(teamViewerUL.parentNode.offsetHeight*3)) {
				this.setStyle('opacity',.1);
			} else {
				arrowU.setStyle('opacity',.6);
			}
		}
	}

	team.each(function(el, i) {
		el.addEvent('click', showBio);
		el.addEvent('mouseover', function() {
			infoBox.hover(this);
		});
		el.addEvent('mouseout',infoBox.exit);
	});

	//load Flash
	var flashvars = {};
	var params = {
		wmode: 'transparent',
		bgcolor: '#000',
		allowscriptaccess: 'always'
	};
	var attributes = {
		id: 'teamFlash',
		name: 'teamFlash'
	};
	swfobject.embedSWF('images/team.swf', 'flashObj', '420', '260', '7.0.0', false, flashvars, params, attributes);
}

window.addEvent('domready', teamSetup);