var currentItem;

function sendEvent(typ, prm) { thisMovie("mpl").sendEvent(typ, prm); };
function getUpdate(typ, pr1, pr2, pid) {
	if (typ == "item") { currentItem = pr1; }
	else if (typ == "state") {
		if (pr1 == 3 && currentItem == 1) {
			/*
			loadFile({
				file:  'postroll.jpg',
				title: 'Visit our sponsor',
				link:  'http://www.kraft.com/'
			});
			*/
			hidePlayerDiv("player1");
			showPostRollDiv("postroll1");
		}
	}
};

function loadFile(obj) { thisMovie("mpl").loadFile(obj); };

function replay() {
	hidePostRollDiv("postroll1");
	showPlayerDiv("player1");
	// sendEvent('playpause');
}

function showPlayerDiv(id) {
	var playerDiv = getObject(id);
	if (playerDiv) playerDiv.style.display = "block";
}

function hidePlayerDiv(id) {
	var playerDiv = getObject(id);
	if (playerDiv) playerDiv.style.display = "none";
}

function showPostRollDiv(id) {
	var postRollDiv = getObject(id);
	if (postRollDiv) postRollDiv.style.display = "block";
}

function hidePostRollDiv(id) {
	var postRollDiv = getObject(id);
	if (postRollDiv) postRollDiv.style.display = "none";
}

// 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 getObject(objectId) {

	// lightweight cross-browser function to get an object given the id;
	if(document.getElementById && document.getElementById(objectId)) {
		return document.getElementById(objectId);
	} else if(document.all && document.all(objectId)) {
		return document.all(objectId);
	} else { // we're not going to support other (older) browsers
		return false;
	}
}

function createPlayer() {
	var s1 = new SWFObject("/videos/flvplayer.swf","mpl","320","260","8");
	s1.addParam("allowfullscreen","false");
	s1.addVariable("backcolor","0xFFFFFF");
	s1.addVariable("enablejs","true");
	s1.addVariable("javascriptid","mpl");
	s1.addVariable("file","/videos/truck_playlist.xml");
	s1.addVariable("repeat","list");
	s1.addVariable("usefullscreen","false");
	s1.write("flv_player1");
}
