Behaviour.register({
	'#instructions' : function (e) {
		if (flashEnabled) {
			$(e).innerHTML=$(e).innerHTML.replace(/download/,'play'); //automatically swap words if flash is present
		}
	},
	'.episodeActivationLink' : function (e) {
		if (flashEnabled) {
			$(e).innerHTML=$(e).innerHTML.replace(/Download/,'Play'); //automatically swap words if flash is present
			$(e).style.backgroundImage='url(/leadership/fyi/images/up_arrow.gif)';
		}
	},	
	'.episode-block' : function(e) {
		e.style.cursor='pointer';
		e.onmouseover=function() {
			if (!$(e).isActive) {
				$(e).style.backgroundColor='#bad0ef';
				$(e).select('.episode-title').first().style.backgroundColor='#bad0ef';
				$(e).select('.episodeActivationLink').first().style.backgroundColor='#bad0ef';
			}
		}
		e.onmouseout=function() {
			if (!$(e).isActive) {
				$(e).style.backgroundColor='#ffffff';
				$(e).select('.episode-title').first().style.backgroundColor='#ffffff';
				$(e).select('.episodeActivationLink').first().style.backgroundColor='#ffffff';
			}
		}
		e.onclick=function() {
			if (flashEnabled && !$(e).isActive) {
				thisEl=$(e);
				upEl=thisEl.up();
				//hide instructions, show player areas, only does something on first click
				$('instructions').style.display='none';
				$('nowplaying-left').style.display='block';
				$('nowplaying-right').style.display='block';
				$('nowplaying-label').innerHTML='Now playing:';
				//update content at top with current info
				$('nowplaying-title').innerHTML=thisEl.select('.episode-title').first().innerHTML;
				$('nowplaying-summary').innerHTML=thisEl.select('.episode-summary').first().innerHTML+' <a id="nowplaying-directlink" class="smalltypeArial" href="'+thisEl.select('.episodeActivationLink').first().href+'">Right-click to save</a>';

				//slight delay is necessary since this func can't be called at the same exact time DIV's display is set to block
				new PeriodicalExecuter(function(pe) {
					if (typeof($('audioplayerflash').sendNewMP3)=='function') {
						$('audioplayerflash').sendNewMP3(thisEl.select('.episodeActivationLink').first().href,thisEl.select('.episode-title').first().innerHTML);
						pe.stop();
					}
				},0.05);
				//set all episodes to default appearance
				upEl.select('.episode-block').each(function(el,ix) {
                                    el.isActive=false;
                                    el.setStyle({
					backgroundColor:'#ffffff',
                                    	cursor:'pointer'
				    });
                                });
				upEl.select('.episode-title').each(function(el,ix) {
                                    el.style.backgroundColor='#ffffff';
                                    el.style.color='#858585';
                                }); 
				upEl.select('a.episodeActivationLink').each(function(el,ix) {
                                    el.style.color='#7096bf';
                                }); 
				upEl.select('.episodeActivationLink').each(function(el,ix) {
                                    el.setStyle({
					color:'#7096bf',
					backgroundImage:'url(/leadership/fyi/images/up_arrow.gif)',							
					backgroundColor:'#ffffff'
				    });
                                    el.innerHTML='Play this episode';
                                }); 																					
				upEl.select('.episode-summary').each(function(el,ix) {el.style.color='#000000';}); 
				upEl.select('.runtime').each(function(el,ix) {el.style.color='#8a8a8a';}); 
				//then just gray the one you chose
				thisEl.isActive=true;
				thisEl.style.backgroundColor='#eeeeee';
				thisEl.style.cursor='default';
				thisEl.select('.episode-title').first().setStyle({
					backgroundColor:'#eeeeee',
					color:'#cccccc'
				});
				thisEl.select('.episodeActivationLink').first().style.color='#cccccc';
				thisEl.select('.episodeActivationLink').first().setStyle({
                                    backgroundImage:'url(/leadership/fyi/images/up_arrow_disabled.gif)',			
                                    backgroundColor:'#eeeeee'
                                });
				thisEl.select('.episodeActivationLink').first().innerHTML='Currently playing';	
				thisEl.select('.episode-summary').first().style.color='#cccccc';
				thisEl.select('.runtime').first().style.color='#cccccc';
				return false; //prevents activation of original HTML link
			} else if (flashEnabled && thisEl.isActive) { //prevents activation of original HTML link if this link is already playing
				return false;
			} else if (!flashEnabled) { //handle linking of entire DIV for non-flash users
				window.location=thisEl.select('.episodeActivationLink').first().href;
				return false;
			} //if javascript is off, normal href link works
			//return false; reenable this for debugging so page doesn't go anywhere on JS errors
		}
	}
});