﻿/// References swfobject.js
// Check the functions for the URL's of required players.




// Embeds a Flash video player into the specified container id.
// Uses fixed player settings (320x240, colors, buttons)
// The video path must be relative to the location.href (not the player)!
function AddFlashVideo(containerID, video, screenshot) {
	var player = "../video/player/mediaplayer.swf";
	var so = new SWFObject(player,'mpl','320','240','8');
	so.addParam('allowscriptaccess','always');
	so.addParam('allowfullscreen','true');
	so.addVariable('height','240');
	so.addVariable('width','320');
	so.addVariable('frontcolor','0x000000');
	so.addVariable('lightcolor','0x1eb53a');
	so.addVariable('screencolor','0x1eb53a');
	so.addVariable('showstop','true');
	
	//This player is OK with relative FLV files but not with images,
	//so let's figure out the absolute path for the screenshot:
//	var absPlayer = CombineRelativePath(location.href,player);
//	var absVideo = CombineRelativePath(absPlayer, video);
//	var absScreenShot = CombineRelativePath(absPlayer,screenshot);
	var absVideo = CombineRelativePath(location.href, video);
	var absScreenShot = CombineRelativePath(location.href, screenshot);
	so.addVariable('file',absVideo);
	so.addVariable('image',absScreenShot);
	so.write(containerID);
}

// Embeds a Flash audio player into the specified container id.
// Uses fixed player settings (size, colors)
// The audio path must be relative to the location.href (not the player)!
function AddFlashAudio(containerID, audio) {
	var player = "../audio/player/audioplayer.swf";
	var so = new SWFObject(player,containerID + "Player", "290", "24", "8");
	so.addParam("wmode","transparent");
	so.addParam("menu","false");
    so.addVariable("leftbg","0xa0d88e");
    so.addVariable("rightbg","0x1eb53a")
	
	//This particular player doesn't play relative-path files, so let's figure out
	//what the real path of the audio is (assuming it is relative to the current location)
	var absAudio = CombineRelativePath(location.href,audio);
	so.addVariable("soundFile", absAudio);
	
	so.write(containerID);
}

//Returns the absolute path that represents the relation between the relative path and the current path.
//Example: CombineRelativePath("http://www.example.com/folder/file.html", "../css/default.css") = "http://www.example.com/css/default.css"
//Example: CombineRelativePath("http://www.example.com/a/b/c/d/e/f/g.html", "/css/default.css") = "http://www.exmaple.com/css/default.css"
function CombineRelativePath(CurrentPath, RelativePath){
	//Let's see if it's truly a relative path, and 
	//if not, let's just return the whole path
	//(not-implemented)


    var destPath= CurrentPath.split("/");
	var relPath = RelativePath.split("/");

    //get rid of the filename:
    destPath.pop();
	
	var i;
	for (i in relPath){
	    switch (relPath[i]){
	        case "..":
	            destPath.pop();
	        case ".":
	            break;
	        case "":
	            //Remove all items except for the last 3 (there are 3 slashes in "http://www/")
	            while (destPath.length > 3){
	                destPath.pop();
	            }
                break;
            default:
                destPath.push(relPath[i]);
                break;
	    }
	}
	return destPath.join("/");
}
