/*
egbvideo.js - to support streaming media files on the EGB site

Contents:
	0. Declarations

Requires:
	eshophj1.js: getObj()

History of Code:
	1.0 05/10/06 Start from The Performance Coach - see virtualCoach.js

History of Data:
	1.0 05/10/06 Initial videos

Instructions
	1. HTML page contains:
		a. Form ...
		b. Windows Media Player Object ...
	2. Video file naming convention: Video[x] + Speed[y] + Type
*/

// 0. Declarations
var Location = "mms://media.endurancegb.co.uk/egbmedia/";
var Type = "wmv";
var Channels = 2; // number of parallel channels

var Video = new Array(); // (set by form field VF)
Video[1] = "EnduranceGB001"; // Introductory EGB video, October 2006

var Speed = new Array(); //  (set by form field CS) Files provided suitable for:
Speed[0] = "38k"; //  1 x 64k channel via a 56k modem
Speed[1] = "48k"; // 1 x 64k channel (64 kbps)
Speed[2] = "112k"; // 2 x 64k channel (128 kbps)
Speed[3] = "150k"; // 3 x 64k channel (192 kbps)
Speed[4] = "256k"; // 4 x 64k channel (256 kbps)
Speed[5] = "256k"; // 5 x 64k channel (320 kbps)
Speed[6] = "256k"; // 6 x 64k channel (384 kbps)
Speed[7] = "256k"; // 7 x 64k channel (428 kbps)
Speed[8] = "256k"; // 8 x 64k channel (492 kbps)
Speed[9] = "512k"; // 9 x 64k channel (556 kbps)
Speed[10] = "512k"; // 10 x 64k channel (640 kbps)
Speed[11] = "512k"; // 11 x 64k channel (704 kbps)
Speed[12] = "512k"; // 12 x 64k channel (768 kbps)
Speed[13] = "512k"; // 13 x 64k channel (640 kbps)
Speed[14] = "512k"; // 14 x 64k channel (704 kbps)
Speed[15] = "512k"; // 15 x 64k channel (768 kbps)
Speed[16] = "512k"; // 16 x 64k channel (832 kbps)
Speed[17] = "512k"; // 17 x 64k channel (896kbps)
Speed[18] = "512k"; // 18 x 64k channel (960 kbps)
Speed[19] = "1024k"; // 19 x 64k channel (1024 kbps)

var timeoutID;
var Player;

function runvideo(form) { // 1.
	Player = getObj("Player");
	Player.onerror = PlayerErr;
	Player.settings.autoStart = true;
	var VF = form.VF.value;
	VF = VF < 1 ? 1 : (VF > (Video.length - 1) ? (Video.length - 1) : VF);
	var CS = form.CS;
	for (var i = 0; i < CS.length; i++) {
		if (CS[i].checked) {
			CS = CS[i].value;
			break;
		}
	}
	CS = CS < 0 ? 0 : (CS > (Speed.length - 1) ? (Speed.length - 1) : (CS > Channels ? Channels : CS));
	Player.URL = Location + Video[VF] + Speed[CS] + "." + Type;
	timeoutID = setTimeout ("TestPlayerError()", 1000);
	return false;
}

var ErrorQty = 0;

function TestPlayerError() {
	if (Player.error.errorCount > ErrorQty) {
		ErrorQty = Player.error.errorCount;
		PlayerErr();
	} else {
		timeoutID = setTimeout ("TestPlayerError()", 1500);
	}
}

function PlayerErr() {
	alert ("There is an error\n" + Player.error.item(ErrorQty==0?0:ErrorQty-1).errorDescription); 
}

function PlayerClose() {
	Player = getObj("Player");
	clearTimeout(timeoutID);
	Player.close();
}

function PlayerSize() {
	Player = getObj("Player");
	Player.stretchToFit = !Player.stretchToFit;
}

