function initializePlayer(movieID, divID, width, height) {
	errorCnt = 0;
	lastErrorCnt = 0;
	ytplayer = null;
	// <![CDATA[
	// allowScriptAccess must be set to allow the Javascript from one
	// domain to access the swf on the youtube domain
	var params = {
		allowScriptAccess : "always",
		bgcolor : "#cccccc",
		play : false,
		loop : false,
		menu : true,
		allowfullscreen : true
	};
	// this sets the id of the object or embed tag to 'myytplayer'.
	// You then use this id to access the swf and make calls to the player's API
	var atts = {
		id : "myytplayer"
	};
	swfobject.embedSWF(
					"http://www.youtube.com/v/"	+ movieID
					+ "&amp;border=0&amp;enablejsapi=1&amp;playerapiid=ytplayer&amp;fs=1&amp;rel=0",
					divID, width, height, "10", null, null, params, atts);
	// ]]>
}

function onYouTubePlayerReady(playerId) {
	ytplayer = document.getElementById("myytplayer");
	ytplayer.addEventListener("onError", "onYtPlayerError");
	ytplayer.style.visibility="hidden";
	document.getElementById("welcome_image").style.height="240px";
	//document.getElementById("requirementsInfoBox").style.visibility="hidden";
	// ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
}

//function play() {
//	if (ytplayer) {
//		ytplayer.playVideo();
//	}
//}

function loadAndPlay(nextVideoID) {
	if (ytplayer) {
		ytplayer.loadVideoById(nextVideoID);
		// alert("started playing"+nextVideoID);
	}
}

function getPlayerState() {
	if (ytplayer == null) {
		return -1;
	}
	if (errorCnt != lastErrorCnt) {
		lastErrorCnt = errorCnt;
		return -2;
	}
	return ytplayer.getPlayerState();
}

function showPlayer() {
	//alert("showplayer");
	if (ytplayer) {
		document.getElementById("welcome_image").style.visibility="hidden";
		document.getElementById("welcome_image").style.height="0px";
		ytplayer.style.visibility="visible";
	}
}

function hidePlayer() {
	//alert("showplayer");
	if (ytplayer) {
		ytplayer.style.visibility="hidden";
	}
}

function onYtPlayerError(errNr) {
	errorCnt++;
}

function clearErrors() {
	errorOccurred = false;
}


//function onytplayerStateChange(newState) {
//	alert("Player's new state: " + newState);
// // stateChangeListener.@jukebox.client.JukeboxUI::playerStateChange(I)(5);
// @jukebox.client.JukeboxUI::someField=5;
// }
