﻿
function PlayVideoClip(fileName, duration, playerID, linkContainerID, scroll)
{
	StopAllClips();
	
	// highlight the link background that was just clicked (if a link container id is available)
	if (linkContainerID)
	{
		$j("#" + linkContainerID).addClass("selected");
	}
	
	// get the player values
	var playerPath = eval("__SDMediaPlayersPlayerPath_" + playerID);
	var playerImagePath = eval("__SDMediaPlayersPlayerImagePath_" + playerID);
	var playerFileName = eval("__SDMediaPlayersPlayerFileName_" + playerID);
	var playerSkinFileName = eval("__SDMediaPlayersPlayerSkinFileName_" + playerID);
	var playerWidth = eval("__SDMediaPlayersPlayerWidth_" + playerID);
	var playerHeight = eval("__SDMediaPlayersPlayerHeight_" + playerID);
	
	// the FlashObject script component is used to write flash movies to the page
	var fo = new FlashObject(playerPath + playerFileName + "?VideoUrl=" + fileName + 
		"&SkinUrl=" + playerSkinFileName + "&Duration=" + duration, "VideoPlayer", playerWidth, playerHeight, "8", "#FFFFFF");
	fo.addParam("wmode", "transparent");
	fo.write(playerID);
	
	// scroll to the player
	if (scroll) 
	{
		$j("#" + playerID).scrollTo(1000);
	}
}
function PlayAudioClip(fileName, duration, playerID, linkContainerID, scroll)
{
	StopAllClips();
	
	// highlight the link background that was just clicked (if a link container id is available)
	if (linkContainerID)
	{
		$j("#" + linkContainerID).addClass("selected");
	}
	
	// get the player values
	var playerPath = eval("__SDMediaPlayersPlayerPath_" + playerID);
	var playerImagePath = eval("__SDMediaPlayersPlayerImagePath_" + playerID);
	var playerFileName = eval("__SDMediaPlayersPlayerFileName_" + playerID);
	var playerSkinFileName = eval("__SDMediaPlayersPlayerSkinFileName_" + playerID);
	var playerWidth = eval("__SDMediaPlayersPlayerWidth_" + playerID);
	var playerHeight = eval("__SDMediaPlayersPlayerHeight_" + playerID);

	// the FlashObject script component is used to write flash movies to the page
	var fo = new FlashObject(playerPath + playerFileName + "?AudioUrl=" + fileName + 
		"&SkinUrl=" + playerSkinFileName + "&Duration=" + duration, "AudioPlayer", playerWidth, playerHeight, "8", "#FFFFFF");
	fo.addParam("wmode", "transparent");
	fo.write(playerID);

	// scroll to the player
	if (scroll) 
	{
		$j("#" + playerID).scrollTo(1000);
	}
}
function StopAllClips()
{
	ClearAllPlayers();
	ClearAllLinkHighlights();
}
function ClearAllPlayers()
{
	// for each video player
	$j("div.videoplayer").each(function (i) {
		// get the player values
		var playerImagePath = eval("__SDMediaPlayersPlayerImagePath_" + this.id);
		var playerFileName = eval("__SDMediaPlayersPlayerFileName_" + this.id);
		var playerWidth = eval("__SDMediaPlayersPlayerWidth_" + this.id);
		var playerHeight = eval("__SDMediaPlayersPlayerHeight_" + this.id);
		
		// clear all player containers; this prevents players from being able to overlap each other
		// if the user has clicked successive 'play now' links (without waiting for a clip to finish playing)
		$j(this).empty();
		$j(this).append("<img src=\"" + playerImagePath + playerFileName.replace(/swf/, "gif") + "\" width=\"" + playerWidth + 
			"\" height=\"" + playerHeight + "\" alt=\"Video Player\"/>");
	});
	// for each audio player
	$j("div.audioplayer").each(function (i) {
		// get the player values
		var playerImagePath = eval("__SDMediaPlayersPlayerImagePath_" + this.id);
		var playerFileName = eval("__SDMediaPlayersPlayerFileName_" + this.id);
		var playerWidth = eval("__SDMediaPlayersPlayerWidth_" + this.id);
		var playerHeight = eval("__SDMediaPlayersPlayerHeight_" + this.id);
		
		// clear all player containers; this prevents players from being able to overlap each other
		// if the user has clicked successive 'play now' links (without waiting for a clip to finish playing)
		$j(this).empty();
		$j(this).append("<img src=\"" + playerImagePath + playerFileName.replace(/swf/, "gif") + "\" width=\"" + playerWidth + 
			"\" height=\"" + playerHeight + "\" alt=\"Audio Player\"/>");
	});
}
function ClearAllLinkHighlights()
{
	$j("div.sdmediaplayers_list_item").removeClass("selected");
}
