/*
Static Media Utilities - Display Media function for Letter Box (without controls)
Uses information passed in query string to display the appropriate media content

*************************************************************************************************************
Please do not edit or copy, if you have questions contact dave.pedowitz@warnerbros.com
*************************************************************************************************************

REVISION HISTORY

01-14-02 Added special QT work for media.warnerbros.com
01-28-02 Added raincloud.warnerbros.com to real and windows media path
02-25-02 Fixed country variable, added jp [raincloud]
02-25-02 Added site variable to point to harrypotter, looneytunes or wbol [raincloud]
*/


function createMedia(moviePath, lyrId) {
	var d = document;
	var query = location.search;
	var host = location.host;
	var mediaTag = "";
	var mediaPath = "";
	var QTPath = "";
	var country = "";
	var site = "";
	var realExt, windowsExt, qtExt;
	var mediaWidth, mediaHeight;


	//Get the video ID from the query string
	var vidId = query.substring(query.lastIndexOf("id=")+3, query.indexOf("&"));

	//Get the type from the query string
	var type = query.substring(query.indexOf("&type=")+6, query.indexOf("&speed"));

	//Get the speed from the query string
	var speed = query.substring(query.indexOf("speed=")+6, query.length-3);
	
	var media = moviePath + vidId; 
	
	if ( type == "windows" || type == "real") {
		if (speed == "56") {
			mediaWidth = "176";
			mediaHeight = "76";
		} else if (speed == "100") {
			mediaWidth = "240";
			mediaHeight = "132";
		} else if (speed == "300") {
			mediaWidth = "320";
			mediaHeight = "172";
		} else if (speed == "500") {
			mediaWidth = "480";
			mediaHeight = "260";
		}
	} else {
		if (speed == "56") {
			mediaWidth = "240";
			mediaHeight = "132";
		} else if (speed == "100") {
			mediaWidth = "320";
			mediaHeight = "172";
		} else if (speed == "300") {
			mediaWidth = "480";
			mediaHeight = "260";
		}
	}
	//Use host variable to get domain and set country variable
	if (host.indexOf(".jp") != -1) {
		country += "/jp";
	} else if (host.indexOf(".co.uk") != -1) {
		country += "/uk";
	} else if (host.indexOf(".fr") != -1) {
		country += "/fr";
	} else if (host.indexOf(".it") != -1) {
		country += "/it";
	} else if (host.indexOf(".tw") != -1) {
		country += "/uk";
	} else if (host.indexOf(".kr") != -1) {
		country += "/uk";
	} else if (host.indexOf(".de") != -1) {
		country += "/de";
	} else {
		country += "/us";
	}
	
	//Use host variable to determine what server to pass to mediaPath
	/*
	var hostVar = new Object();
	hostVar.value = "custom";
	*/
	if (typeof(hostVar) != "undefined") {
		site += "/" + hostVar.value;
	} else if (host.indexOf("harrypotter") != -1) {
		site += "/harrypotter";
	} else if (host.indexOf("looneytunes") != -1) {
		site += "/looneytunes";
	} else {
		site += "/wbol";
	}
	
	if (typeof(MediaServer) != "undefined") {
		mediaPath += "http://raincloud.warnerbros.com" + site + country;
		realExt = "_" + speed + ".rpm";
		windowsExt = "_" + speed + ".asx";
		QT_type = new Object();
		QT_type.mimeType = "smil";
	} else {
		realExt = "_g2_" + speed + ".rpm";
		windowsExt = "_wm_"+speed + ".asx";
		if (type == "windows") {
			mediaPath = "http://" + location.host;
		}
	}
	
	//Begin QuickTime special work
	if (typeof(QT_type) != "undefined") {
		quicktimeExt = "_qt_"+speed + ".smil";
		QTPath = "http://raincloud.warnerbros.com" + site + country;
	} else {
		quicktimeExt = "_qt_"+speed + ".mov";
		QTPath = "http://media.warnerbros.com/"+ site  + country;
	}
		
	//Write proper embed based on player type, final error check
	if (media != null && type == "real") {
		mediaTag += "<embed name=\"wbRealPlayer\" type=\"audio/x-pn-realaudio-plugin\" src=\"" + mediaPath + media + realExt + "\" height=\"" + mediaHeight + "\" width=\"" + mediaWidth + "\" autostart=\"true\" controls=\"ImageWindow\" console=\"wbVideo1\" nologo=\"true\" maintainaspect=\"true\"><br>\n";
		mediaTag += "<embed name=\"wbRealPlayer\"  type=\"audio/x-pn-realaudio-plugin\" src=\""  + mediaPath + media + realExt + "\" height=\"26\" width=\"" + mediaWidth + "\" autostart=\"true\" controls=\"ControlPanel\" console=\"wbVideo1\" nologo=\"true\" maintainaspect=\"true\">";
	} else if (media != null && type == "windows") {
		mediaTag += "<EMBED TYPE=\"video/x-ms-asf-plugin\" SRC=\"" + mediaPath + media + windowsExt + "\" WIDTH=\"" + mediaWidth + "\" HEIGHT=\"" +(parseInt(mediaHeight) + 46) + "\" SHOWCONTROLS=\"1\" AUTOSTART=\"1\" ANIMATIONATSTART=\"1\" AUTOREWIND=\"0\" AUTOSIZE=\"0\" SHOWDISPLAY=\"0\" SHOWSTATUSBAR=\"0\" SendOpenStateChangeEvents=\"true\" TRANSPARENTATSTART=\"true\"></EMBED>";
	} else if (media != null && type == "quicktime") {
		mediaTag += "<embed type=\"video/quicktime\" src=\"http://media.warnerbros.com/all/quicktime/need_qt4.mov\" QTSRC=\"" + QTPath + media + quicktimeExt + "\" width=\"" + mediaWidth + "\" height=\"" + (parseInt(mediaHeight) + 14) + "\" controller=\"true\" loop=\"false\" autoplay=\"true\" kioskmode=\"true\" bgcolor=\"#000000\">";
	}
//	alert(mediaTag);
	if (d.layers && lyrId != null) {
		d[lyrId].document.write(mediaTag)
	} else {
		d.write(mediaTag);
	}
}

