// JavaScript Document
function Show(LayerName)
{
	LayerObj=document.getElementById(LayerName);
	LayerObj.style.display="inline";
}
function Hide(LayerName)
{
	LayerObj=document.getElementById(LayerName);
	LayerObj.style.display="none";
}

var flowPlayer1;
function init() {
		// <![CDATA[
	  var fo = new SWFObject("/images/flash/FlowPlayer.swf", "FlowPlayer", "468", "350", "7", "#ffffff", true);
      // need this next line for local testing, it's optional if your swf is on the same domain as your html page
      fo.addParam("allowScriptAccess", "always");
      fo.write("BlockPlayer");
		// ]]>
			
	if (document.getElementById) {
		flowPlayer1 = document.getElementById("FlowPlayer");
	}
}


// wait for the page to fully load before initializing
//window.onload = init;

function setInitialConfig() {
	fpConf.autoPlay = true;
	fpConf.autoBuffering = true;
	flowPlayer1.setConfig(fpConf);
}

var fpConf = {
	showPlayList: false,
	bufferLength: 20,
	loop: false,
	hideControls: false,
	showPlayListButtons: true,
	progressBarColor1: 0xFF0000,
	progressBarColor2: 0xFF0000,
	bufferBarColor1: 0x00FF00,
	bufferBarColor2: 0x00FF00,
	progressBarBorderColor1: 0xAAAAAA,
	progressBarBorderColor2: 0xAAAAAA
}

/*
 * JavaScript event hanlders:
 */
function clipSelected(clipIndex) {
	flowPlayer1.ToClip(clipIndex);
}

function play() {
	flowPlayer1.DoPlay();
	updateIsPlaying();
}

function pause() {
	flowPlayer1.Pause();
	updateIsPlaying();
}

function stop() {
	flowPlayer1.DoStop();
	updateIsPlaying();
}

function updateIsPlaying() {
	/*var field = document.getElementById("playing");
	field.value = "Playing: " + flowPlayer1.getIsPlaying() + ", paused : " + flowPlayer1.getIsPaused();*/
}

function seek() {
	var seekTimeField = document.getElementById("seekTime");
	flowPlayer1.Seek(seekTimeField.value);
}

function getTime() {
	var time = flowPlayer1.getTime();
	var timeField = document.getElementById("time");
	timeField.value = time;
}

function getDuration() {
	var value = flowPlayer1.getDuration();
	var field = document.getElementById("duration");
	field.value = value;
}

function getPercentLoaded() {
	var value = flowPlayer1.getPercentLoaded();
	var field = document.getElementById("loaded");
	field.value = value;
}

function replaceConfig(dir) {
	// replace the playlist in our configuration
	fpConf.playList = [                      
	{ name: 'Tema', url: dir } ];
	fpConf.autoBuffering = true;
	fpConf.autoPlay = true;
	flowPlayer1.setConfig(fpConf);
}

function setCuePoints() {
	flowPlayer1.addCuePoints([ {time: 2, name: "cue1", parameters: { foo: 1, bar: "foobar" }}, { time: 5, name: "cue2", parameters: { foo: 2, bar: "foobar2" }} ]);
}

/*
 * Flash callback handlers. The player calls these on specific events:
 */

function onClipDone(clip) {
	addClipEvent("clip done : " + describeClip(clip));
}

function onClipChanged(clip) {
	addClipEvent("changed to clip : " + clip.name);
}

function onLoadBegin(clip) {
	//addClipEvent("started loading : " + clip.name);
}

function onStartBuffering(clip) {
	addClipEvent("started buffering : " + clip.name);
}

function onBufferFull(clip) {
	addClipEvent("buffer full for : " + clip.name);
}

function onBufferFlush(clip) {
	addClipEvent("buffer flush for : " + clip.name);
}

function onMetaData(obj) {
	addClipEvent("metadata received : duration " + obj.duration + ", video data rate " + obj.videodatarate + ", audio data rate " + obj.audiodatarate + ", creation date " + obj.creationdate);
}

function onStreamNotFound(clip) {
	addClipEvent("stream not found: " + describeClip(clip));
}

function onPlay(clip) {
	addClipEvent("play: " + clip.name);
}

function onStop(clip) {
	addClipEvent("stop: " + clip.name);
}

function onPause(clip) {
	addClipEvent("paused: " + clip.name);
}

function onResume(clip) {
	addClipEvent("resumed: " + clip.name);
}

function onCuePoint(cuePoint) {
	addClipEvent("cue point received, time: " + cuePoint.time + ", type '" + cuePoint.type + "', name: '" + cuePoint.name + "'" + "', thumb: " + cuePoint.thumb + ", parameters: " + cuePoint.parameters);
}

/*
 * Helpers:
 */
 
function addClipEvent(desc) {
	var events = document.getElementById("events");
	events.appendChild(document.createTextNode(desc));
	events.appendChild(document.createElement("br"));
}

function describeClip(clip) {
	return "Name: " + clip.name + ", baseUrl: " + clip.baseUrl + ", fileName: " + clip.fileName + 
	", start: " + clip.start + ", end: " + clip.end + ", protected: " + clip.protected +
	", linkUrl: " + clip.linkUrl + ", linkWindow: " + clip.linkWindow + ", controlEnabled: " +
	clip.controlEnabled;
}
