var currentFile = "";
var currentItem = 0;
var previousItem = -1;

function init() {
	createImageRotator()
}

function createImageRotator() {
	var s1 = new SWFObject("/eatacd/script/imagerotator.swf", "rotator", "736", "106", "7");
	s1.addParam("allowfullscreen", "false");
	s1.addVariable("file", "/media/xml/image-rotator.xml");
	s1.addVariable("width", "736");
	s1.addVariable("height", "106");
	s1.write("imageholder");
}

function createPlayer(theFile, autostart, shuffle) {
	// console.log("playlist: %s; autostart: %s; shuffle: %s", theFile,
	// autostart, shuffle)

	var s = new SWFObject("script/player.swf", "thePlayerId", "650","130", "8");
	s.addParam("allowfullscreen", "true");
	s.addVariable("file", theFile);

	s.addVariable("showicons", "false");
	s.addVariable("stretching", "fill");
	// s.addVariable("autostart", autostart);

	s.addVariable('playlist', 'right');
	s.addVariable('playlistsize', '350');
	s.addVariable('skin', 'script/controlpanel.swf');
	s.addVariable('autoscroll', 'true');
	s.addVariable('shownavigation', 'true');
	s.addVariable('linkfromdisplay', 'true');
	s.addVariable('showeq', 'true');
	s.addVariable('repeat', 'always');
	s.addVariable('shuffle', shuffle);
	s.addVariable("enablejs", "true");
	s.addVariable("javascriptid", "thePlayerId");

	s.write("placeholder");
}

function sendEvent(typ, prm) {
	thisMovie("thePlayerId").sendEvent(typ, prm);
};

function getUpdate(typ, pr1, pr2, pid) {
	if (typ == "item") {
		currentItem = pr1;
	}
};

// This is a javascript handler for the player and is always needed.
function thisMovie(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
	} else {
		return document[movieName];
	}
};

function initPlayer() {
	track = getParam('item')
	category = getParam('category')
	playlist = 'servlet/Playlist'
	autostart = 'false'
	shuffle = 'true'
	// check if taster
	if (track != "") {
		autostart = 'true'
		shuffle = 'false'
		if (category == 'teaching') {
			playlist = '/media/xml/teaching.xml'
		}
	}
	// console.log("init: item: %s; category: %s; playlist: %s; autostart: %s;
	// shuffle: %s", item , category, playlist, autostart, shuffle)
	createPlayer(playlist, autostart, shuffle)
	if (track != "") {
		setTimeout("sendEvent('item',  track)", 1500);
		// sendEvent('ITEM',location.search.substring(1))
	}
}

function getParam(name) {
	name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
	var regexS = "[\\?&]" + name + "=([^&#]*)";
	var regex = new RegExp(regexS);
	var results = regex.exec(window.location.href);
	if (results == null)
		return "";
	else
		return results[1];
}

function createWindow(adr) {
	console.log("taster: %s", adr)
	showFlag = true;
	sendEvent("stop");

	var pWin = window
			.open(
					adr,
					'Tasters',
					'width=650,height=120,left=100,top=200,resizable=yes,status=yes,toolbar=no,menubar=no,location=no');
	pWin.focus();
}
	
var popWin = null;
function createWindow2(theUrl) {
	popWin = window
			.open(
					theUrl,
					"tasters",
					"width=500,height=600,left=100,top=200,resizable=yes,status=yes,toolbar=no,menubar=no,location=no");
	popWin.focus();
}