window.addEvent('domready', function() {

	var links = $$('div.video-box');

	var count = 0;
	var curLink;

	links.each( function(link, i) {
		count++;
		
		var is_playing = false;
		
		link.onclick = function() {
			curLink = i+1;
			launchFlash(curLink);
			this.addClass('video-on');
			$('caption' + curLink).removeClass('caption-hide');
			$('backgrounder' + curLink).removeClass('backgrounder-hide');
			$('video-format' + curLink).removeClass('format-hide');
						
			for(j=1; j<4; j++) {
				if(j != curLink) {
					links[j-1].removeClass('video-on');
					$('caption' + j).addClass('caption-hide');
					$('backgrounder' + j).addClass('backgrounder-hide');
					$('video-format' + j).addClass('format-hide');
				}
			}
		}
		});
	});

function launchFlash(num) {
	if(!num) {
		num = 1;
	}
	
	var targetarea = document.getElementById('video');
	
	var firstPass = document.URL.split('math/');
	var secondPass = firstPass[1].split('.');
	page = secondPass[0];
	
	if(page == 'pr_math_centers') {
		videoName = 'AST05_mat_ctrschoice'; 
	} else if(page == 'pr_math_find') {
		videoName1 = 'AST05_mat_rhybeat';
		videoName2 = 'AST05_mat_findtres';
		videoName = eval('videoName' + num);
	} else if(page == 'pr_math_games') {
		videoName1 = 'AST05_mat_games24';
		videoName2 = 'AST05_mat_gamesmove';
		videoName = eval('videoName' + num);
	} 
	
	var oeTags = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
    + 'width="340" height="376"'
    + 'id="player" align="middle"'
    + 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0">'
    + '<param name="movie" value="../player/ccPlayer.swf?ccVideoName=../video/math/' + videoName + '_350.flv&ccVideoAutoStart=true&ccCaptSourceType=external&ccCaptionSource=../video/math/' + videoName + '.dfxp.xml&ccCaptionAutoHide=false" />'
    + '<param name="quality" value="high" />'
    + '<param name="bgcolor" value="#000000" />'
    + '<param name="allowScriptAccess" value="sameDomain" />'
	+ '<param name="allowFullScreen" value="false" />'
    + '<embed src="../player/ccPlayer.swf?ccVideoName=../video/math/' + videoName + '_350.flv&ccVideoAutoStart=true&ccCaptSourceType=external&ccCaptionSource=../video/math/' + videoName + '.dfxp.xml&ccCaptionAutoHide=false" '
    + 'width="340" height="376" '
    + 'quality="high" '
    + 'bgcolor="#000000" '
	+ 'name="player" '
	+ 'align="middle" '
	+ 'allowScriptAccess="sameDomain" '
	+ 'allowFullScreen = "false" '
    + 'type="application/x-shockwave-flash"'
    + 'pluginspage="http://www.macromedia.com/go/getflashplayer">'
    + '\</embed>'
    + '\</object>';
    
    targetarea.innerHTML = oeTags;
}

function writeFlash(num) {
//	if(PBS_FlashCanPlay(8)) {
		return (oeTags);   // embed the flash movie
		
/*	  } else {  // flash is too old or we can't detect the plugin
		// NOTE: height, width are required!
		var alternateContent = '<img src="../images/' + videoName + '.jpg" alt="" width="320" height="240" />';
	
		return(alternateContent);  // insert non-flash content
	  } */
}