function toggleVideoSample(video_id, state) {
	if (state == 'on') {
		document.getElementById("videoSample"+video_id).style.display = "block";
		document.getElementById("showVideoSample"+video_id).style.display = "none";
	}
	else {
		document.getElementById("videoSample"+video_id).style.display = "none";
		document.getElementById("showVideoSample"+video_id).style.display = "block";
	}
}

function deselectAllClips(objId)
{
	$j("#" + objId+"Playlist").each(function() {
		$j(this).find(".clip").removeClass("selected");
	});
}

$j(document).ready(function() {
	$j(".flashPlayerContainer").each(function(i, container) {
		var objId = container.id;
		// Remove the word 'container' to get the objId of the video player
		objId = objId.substring(0, objId.length-9);
		// For each clip anchor within this flash container
		$j("#" + container.id + " div.clip" ).each(function() {
			this.onclick = function(){
				//var parentDiv = $j(this).parents('div');
				var thisId = $j(this).attr("id");
				var pos = thisId.indexOf("Clip_");
				// Get the video object ID prefix
				var objId = thisId.substr(0, pos);
				// get the index number at the end
				var seq = thisId.substr(pos+5);

				deselectAllClips(objId);
				$j(this).addClass("selected");

				//Command the clip to play
				swfobject.getObjectById(objId).goto(seq);
				return false;
			};
		});
	});
	
	$j('a.videoSample').each(function() {
		this.onclick = function(){ var video_id = this.id.substr(15); toggleVideoSample(video_id, 'on'); return false; };
	});
	$j('a.hideVideoSample').each(function() {
		this.onclick = function() { var video_id = this.id.substr(15); toggleVideoSample(video_id, 'off'); return false; };
	});
	
});

