// some variables to save
var currentPosition;
var currentVolume;
var currentItem;

// these functions are caught by the JavascriptView object of the player.
function sendEvent(typ,prm) { thisMovie("mpl").sendEvent(typ,prm); };
function getUpdate(typ,pr1,pr2,pid) {
	if(typ == "time") { currentPosition = pr1; }
	else if(typ == "volume") { currentVolume = pr1; }
	else if(typ == "item") { currentItem = pr1; setTimeout("getItemData(currentItem)",100); }
//	var id = document.getElementById(typ);
//	id.innerHTML = typ+ ": "+Math.round(pr1);
//	pr2 == undefined ? null: id.innerHTML += ", "+Math.round(pr2);
//	if(pid != "null") {
//		document.getElementById("pid").innerHTML = "(received from the player with id <i>"+pid+"</i>)";
//	}
};

// These functions are caught by the feeder object of the player.
function loadFile(obj) { thisMovie("mpl").loadFile(obj); };
function addItem(obj,idx) { thisMovie("mpl").addItem(obj,idx); }
function removeItem(idx) { thisMovie("mpl").removeItem(idx); }
function getItemData(idx) {
	var obj = thisMovie("mpl").itemData(idx);
	if(document.getElementById("phototitle")) {
		if(typeof obj["author"] == "undefined") {
//			document.getElementById("phototitle").innerHTML = "Ways of Seeing Me";
			document.getElementById("phototitle").innerHTML = obj["title"];
			document.getElementById("photographer").innerHTML = "";
		} else {
			document.getElementById("phototitle").innerHTML = "Xstudio Digital Photography";
			document.getElementById("photographer").innerHTML = "Photo by: "+obj["author"];
		}
	} else {
	document.getElementById("album").innerHTML = "Album: "+obj["category"];
	document.getElementById("title").innerHTML = "Title: "+obj["title"];
	document.getElementById("artist").innerHTML = obj["captions"];
	}
//	thisMovie("mpl").focus();
};

// 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 initFlash(typ,file,width,height,blockName) {
	var e = getElementsByStyleClass("on");
	for (var i = 0; i < e.length; i++) {
		e[i].className = "off";
		grid[e[i].id].hideheading();
	}
//	block.className = "on";
//	document.getElementById(blockName).className = "on";
	document.getElementById(blockName+'img').className = "on";
	document.getElementById(blockName+'text').className = "on";
//	grid[blockName].showHeading();
	grid[blockName+'img'].showHeading();
	grid[blockName+'text'].showHeading();
	switch(typ) {
	case "image":
		var so = new SWFObject("jw_image_rotator/imagerotator.swf","mpl",width,height,"7");
		so.addVariable("transition","slowfade");
		so.addVariable("overstretch","false");
		so.addVariable("backcolor","0xFFFFFF");
		so.addVariable("linkfromdisplay", "true");
		so.addVariable('linktarget', '_self');
		break;
	case "media":
		var so = new SWFObject("jw_media_player/mediaplayer.swf","mpl",width,height,"7");
		so.addParam("allowfullscreen","true");
		so.addVariable("displayheight","0");
		break;
	}
	so.addVariable("file",file);
	so.addVariable("enablejs","true");
	so.addVariable("javascriptid","mpl");
	so.addVariable("width",width);
	so.addVariable("height",height);
	so.write("player");
//	document.getElementById(block).style.opacity =.4;
//	var mmw = new SWFMacMouseWheel(so);
}

function getElementsByStyleClass (className) {
	var all = document.all ? document.all :
	document.getElementsByTagName('*');
	var elements = new Array();
	for (var e = 0; e < all.length; e++)
		if (all[e].className == className)
			elements[elements.length] = all[e];
      return elements;
}
