var ORPlatform = new Object(); // Create object
ORPlatform.requiredFlashVersion = "10.0.0"; // Required version of Adobe Flash
ORPlatform.isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false; // Whether or not it is IE

ORPlatform.getPageSizeWithScroll = function() {
	if (window.innerHeight && window.scrollMaxY) { // Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
  	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	return arrayPageSizeWithScroll;
}

ORPlatform.toggleLights = function(id) {
	var player = document.getElementById(id);
	var overlay = document.getElementById("divORPlatformOverlay");
	if (!overlay) {
		var div = document.createElement("div");
		div.id = "divORPlatformOverlay";
		div.style.backgroundColor = "#000000";
		div.style.height = ORPlatform.getPageSizeWithScroll()[1] + "px";
		div.style.width = "100%";
		div.style.position = "absolute";
		div.style.top = "0px";
		div.style.left = "0px";
		div.onclick = function(e) { ORPlatform.toggleLights(id); }
		ORPlatform.setLightOpacity(div, 0);
		document.body.appendChild(div);
		if (typeof jQuery != "undefined") jQuery("#divORPlatformOverlay").fadeTo("slow", 0.8);
		else ORPlatform.setLightOpacity(div, 0.8);
		if (player) player.lowerLights();
	}
	else {
		if (overlay.style.display == "none") {
			overlay.style.display = "";
			overlay.style.height = ORPlatform.getPageSizeWithScroll()[1] + "px";
			if (typeof jQuery != "undefined") jQuery("#divORPlatformOverlay").fadeTo("slow", 0.8);
			else ORPlatform.setLightOpacity(div, 0.8);
			if (player) player.lowerLights();
		}
		else {
			if (typeof jQuery != "undefined") jQuery("#divORPlatformOverlay").fadeTo("slow", 0, ORPlatform.hideOverlay);
			else overlay.style.display = "none";
			if (player) player.raiseLights();
		}
	}
}

ORPlatform.hideOverlay = function() {
	var overlay = document.getElementById("divORPlatformOverlay");
	if (overlay) overlay.style.display = "none";
}

ORPlatform.setLightOpacity = function(element, percentage) {
	if (element) {
		if (typeof element.style.opacity != "undefined") element.style.opacity = percentage; // Firefox, etc.
		if (typeof element.style.filters != "undefined") element.style.filters.alpha.opacity = percentage * 100; // IE
		if (typeof element.style.MozOpacity != "undefined") element.style.MozOpacity = percentage; // Netscape
		if (typeof element.style.KHTMLOpacity != "undefined") element.style.KHTMLOpacity = percentage; // KHTML
	}
}

ORPlatform.popupSlide = function(url, width, height) {
	if (ORPlatform.popupSlideWindow && !ORPlatform.popupSlideWindow.closed) {
		ORPlatform.popupSlideWindow.focus();
		ORPlatform.popupSlideWindow.location.href = "http://www.orlive.com/popup/slide.cfm?img=" + url;
	}
	else ORPlatform.popupSlideWindow = window.open("http://www.orlive.com/popup/slide.cfm?img=" + url, "PopupSlide", "width=" + width + ",height=" + height + ",menubar=0,resizable=1,status=0,scrollbars=0");
}

ORPlatform.updatePopupSlide = function(url) {
	if (ORPlatform.popupSlideWindow && !ORPlatform.popupSlideWindow.closed) {
		ORPlatform.popupSlideWindow.location.href = "http://www.orlive.com/popup/slide.cfm?img=" + url;
	}
}

ORPlatform.updateSlide = function(id, url, current, total) {
	var slide = document.getElementById(id);
	if (slide && typeof slide.update == "function") slide.update(url, current, total);
}

ORPlatform.createSlide = function(slide, element, slideswf, installswf) {
	
	if (typeof slide != "object") {
		alert("You must pass in an object containing the slide properties.");
		return;
	}
	
	if (typeof element != "string") {
		alert("You must pass in the id of an HTML element in which to embed the slide.");
		return;
	}
	
	if (typeof slideswf != "string") {
		alert("You must pass in the path to the slide's SWF file.");
		return;
	}
	
	if (typeof slide.id != "string") {
		alert("You must specify an id property for the slide object.");
		return;
	}
	
	var div = document.getElementById(element);
	if (!div) { // Element with the specified ID does not exist
		alert("The element you specified for embedding the slide does not exist.");
		return;
	}
	
	/********************* DEFAULT VALUES *********************/
	
	// INSTALL SWF
	if (typeof installswf != "string") installswf = "";
	
	// BOOLEAN PROPERTIES
	if (typeof slide.popup != "boolean") slide.popup = true;
			
	// NUMERIC PROPERTIES
	if (typeof slide.width != "number") slide.width = 480;
	if (typeof slide.height != "number") slide.height = 360;
	if (typeof slide.popupWidth != "number") slide.popupWidth = 800;
	if (typeof slide.popupHeight != "number") slide.popupHeight = 600;
	
	/********************* FLASH DETECTION *********************/
	
	// REQUIRED VERSION OF FLASH NOT DETECTED
	if (!swfobject.hasFlashPlayerVersion(ORPlatform.requiredFlashVersion)) {
		div.style.color = "white"; // Set color
		div.style.padding = "10px"; // Set padding
		div.style.fontSize = "12px"; // Set font size
		div.style.textAlign = "left"; // Align text to the left
		div.style.backgroundColor = "black"; // Set background color
		div.style.fontFamily = "Verdana, Arial, Helvetica, sans-serif"; // Set font
		if (ORPlatform.isIE) {
			div.style.width = slide.width + "px"; // Set to defined width
			div.style.height = slide.height + "px"; // Set to defined height
		}
		else {
			div.style.width = (slide.width - 20) + "px"; // Set to defined width - padding
			div.style.height = (slide.height - 20) + "px"; // Set to defined height - padding
		}
		div.innerHTML = "<strong>Adobe Flash Player Requirement</strong><br />" + 
			"The ORLive slide player requires that Adobe Flash Player " + ORPlatform.requiredFlashVersion + 
			" or greater be installed in your web browser. Please visit Adobe.com in order to " + 
			"<a href='http://www.adobe.com/go/getflash' target='_blank' style='color:white;'>download " + 
			"and install the latest version</a> of Adobe Flash Player and then restart your web browser " + 
			"and return to this page."
		if (installswf == "") return;
	}
	
	/********************* PARAMETERS AND VARIABLES *********************/
	
	// BUILD FLASH ATTRIBUTES OBJECT
	slide.flashAttrib = {
		id: 					slide.id,
		name: 					slide.id
	};
	
	// BUILD FLASH PARAMS OBJECT
	slide.flashParams = {
		allowFullScreen: 		"false",
		allowScriptAccess: 		"always",
		wmode: 					"opaque"
	};
	
	// BUILD FLASH VARIABLES OBJECT
	slide.flashVars = {
		
		// Add slide variables
		height: 				slide.height,
		popup: 					slide.popup,
		popupWidth: 			slide.popupWidth,
		popupHeight: 			slide.popupHeight,
		width: 					slide.width
		
	};
	
	// LOOK FOR Z-INDEX SPECIFICATION
	var css = "outline:none; position:relative;";
	if (typeof ORPlatform.zIndex == "number")  css += " z-index:" + ORPlatform.zIndex + ";";
	else css += " z-index:499;";
	swfobject.createCSS("OBJECT#" + slide.id, css);
	
	// EMBED PLAYER
	swfobject.embedSWF(slideswf, element, slide.width, slide.height, ORPlatform.requiredFlashVersion, installswf, slide.flashVars, slide.flashParams, slide.flashAttrib);
	
}

ORPlatform.createPlaylist = function(playlist, element, playlistswf, installswf) {
	
	if (typeof playlist != "object") {
		alert("You must pass in an object containing the playlist properties.");
		return;
	}
	
	if (typeof element != "string") {
		alert("You must pass in the id of an HTML element in which to embed the playlist.");
		return;
	}
	
	if (typeof playlistswf != "string") {
		alert("You must pass in the path to the playlist's SWF file.");
		return;
	}
	
	if (typeof playlist.id != "string") {
		alert("You must specify an id property for the playlist object.");
		return;
	}
	
	if (typeof playlist.player != "string") {
		alert("You must specify the player parameter (id of player) for the playlist component.");
		return;
	}
	
	if (typeof playlist.playlist != "string") {
		alert("You must specify the playlist property (Object ID) for the playlist component.");
		return;
	}
	
	var div = document.getElementById(element);
	if (!div) { // Element with the specified ID does not exist
		alert("The element you specified for embedding the playlist does not exist.");
		return;
	}
	
	/********************* DEFAULT VALUES *********************/
	
	// INSTALL SWF
	if (typeof installswf != "string") installswf = "";
	
	// BOOLEAN PROPERTIES
	if (typeof playlist.search != "boolean") playlist.search = false;
			
	// NUMERIC PROPERTIES
	if (typeof playlist.width != "number") playlist.width = 320;
	if (typeof playlist.height != "number") playlist.height = 360;
	if (typeof playlist.fontSize != "number") playlist.fontSize = 10;
	if (typeof playlist.resultSize != "number") playlist.resultSize = 25;
	if (typeof playlist.thumbWidth != "number") playlist.thumbWidth = 60;
	if (typeof playlist.thumbHeight != "number") playlist.thumbHeight = 45;
	
	// STRING PROPERTIES
	if (typeof playlist.backgroundColor != "string") playlist.backgroundColor = "#000000";
	if (typeof playlist.fontColor != "string") playlist.fontColor = "#FFFFFF";
	if (typeof playlist.fontWeight != "string") playlist.fontWeight = "bold";
	if (typeof playlist.rollOverFontColor != "string") playlist.rollOverFontColor = "#000000";
	if (typeof playlist.rollOverColor != "string") playlist.rollOverColor = "#DEDEDE";
	if (typeof playlist.searchFilters != "string") playlist.searchFilters = "";
	if (typeof playlist.selectionFontColor != "string") playlist.selectionFontColor = "#000000";
	if (typeof playlist.selectionColor != "string") playlist.selectionColor = "#AAAAAA";
	
	/********************* FLASH DETECTION *********************/
	
	// REQUIRED VERSION OF FLASH NOT DETECTED
	if (!swfobject.hasFlashPlayerVersion(ORPlatform.requiredFlashVersion)) {
		div.style.color = "white"; // Set color
		div.style.padding = "10px"; // Set padding
		div.style.fontSize = "12px"; // Set font size
		div.style.textAlign = "left"; // Align text to the left
		div.style.backgroundColor = "black"; // Set background color
		div.style.fontFamily = "Verdana, Arial, Helvetica, sans-serif"; // Set font
		if (ORPlatform.isIE) {
			div.style.width = playlist.width + "px"; // Set to defined width
			div.style.height = playlist.height + "px"; // Set to defined height
		}
		else {
			div.style.width = (playlist.width - 20) + "px"; // Set to defined width - padding
			div.style.height = (playlist.height - 20) + "px"; // Set to defined height - padding
		}
		div.innerHTML = "<strong>Adobe Flash Player Requirement</strong><br />" + 
			"The ORLive playlist requires that Adobe Flash Player " + ORPlatform.requiredFlashVersion + 
			" or greater be installed in your web browser. Please visit Adobe.com in order to " + 
			"<a href='http://www.adobe.com/go/getflash' target='_blank' style='color:white;'>download " + 
			"and install the latest version</a> of Adobe Flash Player and then restart your web browser " + 
			"and return to this page."
		if (installswf == "") return;
	}
	
	/********************* PARAMETERS AND VARIABLES *********************/
	
	// BUILD FLASH ATTRIBUTES OBJECT
	playlist.flashAttrib = {
		id: 					playlist.id,
		name: 					playlist.id
	};
	
	// BUILD FLASH PARAMS OBJECT
	playlist.flashParams = {
		allowFullScreen: 		"false",
		allowScriptAccess: 		"always",
		wmode: 					"opaque"
	};
	
	// BUILD FLASH VARIABLES OBJECT
	playlist.flashVars = {
		
		// Add slide variables
		backgroundColor: 		playlist.backgroundColor,
		fontColor: 				playlist.fontColor,
		fontSize: 				playlist.fontSize,
		height: 				playlist.height,
		player: 				playlist.player,
		playlist: 				playlist.playlist,
		rollOverFontColor: 		playlist.rollOverFontColor,
		rollOverColor: 			playlist.rollOverColor,
		resultSize: 			playlist.resultSize,
		search:					playlist.search,
		searchFilters: 			playlist.searchFilters,
		selectionFontColor: 	playlist.selectionFontColor,
		selectionColor: 		playlist.selectionColor,
		thumbHeight: 			playlist.thumbHeight,
		thumbWidth: 			playlist.thumbWidth,
		width: 					playlist.width
		
	};
	
	// LOOK FOR Z-INDEX SPECIFICATION
	var css = "outline:none; position:relative;";
	if (typeof ORPlatform.zIndex == "number")  css += " z-index:" + ORPlatform.zIndex + ";";
	else css += " z-index:499;";
	swfobject.createCSS("OBJECT#" + playlist.id, css);
	
	// EMBED PLAYER
	swfobject.embedSWF(playlistswf, element, playlist.width, playlist.height, ORPlatform.requiredFlashVersion, installswf, playlist.flashVars, playlist.flashParams, playlist.flashAttrib);
	
}

ORPlatform.createPlayer = function(player, element, playerswf, installswf, local) {
	
	if (local) player.local = true;
	else player.local = false;
	
	if (typeof player != "object") {
		alert("You must pass in an object containing the player properties.");
		return;
	}
	
	if (typeof element != "string") {
		alert("You must pass in the id of an HTML element in which to embed the player.");
		return;
	}
	
	if (typeof playerswf != "string") {
		alert("You must pass in the path to the player's SWF file.");
		return;
	}
	
	if (typeof player.id != "string") {
		alert("You must specify an id property for the video player object.");
		return;
	}
	
	if (!player.local && typeof player.video != "string" && typeof player.playlist != "string") {
		alert("You must specify either a video or playlist property (Object ID) for the video player component.");
		return;
	}
	
	var div = document.getElementById(element);
	if (!div) { // Element with the specified ID does not exist
		alert("The element you specified for embedding the player does not exist.");
		return;
	}
	
	/********************* DEFAULT VALUES *********************/
	
	// INSTALL SWF
	if (typeof installswf != "string") installswf = "";
	
	// BOOLEAN PROPERTIES
	if (typeof player.background != "boolean") player.background = true;
	if (typeof player.branding != "boolean") player.branding = true;
	if (typeof player.controls != "boolean") player.controls = true;
	if (typeof player.fullscreen != "boolean") player.fullscreen = true;
	if (typeof player.lights != "boolean") player.lights = true;
	if (typeof player.mute != "boolean") player.mute = true;
	if (typeof player.slider != "boolean") player.slider = true;
	if (typeof player.showPlayComplete != "boolean") player.showPlayComplete = true;
	if (typeof player.showPlayPause != "boolean") player.showPlayPause = true;
	if (typeof player.showPlayReady != "boolean") player.showPlayReady = true;
	if (typeof player.time != "boolean") player.time = true;
			
	// NUMERIC PROPERTIES
	if (typeof player.width != "number") player.width = 640;
	if (typeof player.height != "number") player.height = 360;
	
	// STRING PROPERTIES
	if (typeof player.source != "string") player.source = "";
	if (typeof player.status != "string") player.status = "";
	if (typeof player.video != "string") player.video = "";
	if (typeof player.xml != "string") player.xml = "";
	
	// FARCRY SLIDE, PLAYLIST AND PROFILE ID
	if (typeof player.slide != "string") player.slide = "";
	if (typeof player.playlist != "string") player.playlist = "";
	if (typeof player.profile != "string") player.profile = "";
	
	/********************* FLASH DETECTION *********************/
	
	// REQUIRED VERSION OF FLASH NOT DETECTED
	if (!swfobject.hasFlashPlayerVersion(ORPlatform.requiredFlashVersion)) {
		div.style.color = "white"; // Set color
		div.style.padding = "10px"; // Set padding
		div.style.fontSize = "12px"; // Set font size
		div.style.textAlign = "left"; // Align text to the left
		div.style.backgroundColor = "black"; // Set background color
		div.style.fontFamily = "Verdana, Arial, Helvetica, sans-serif"; // Set font
		if (ORPlatform.isIE) {
			div.style.width = player.width + "px"; // Set to defined width
			div.style.height = player.height + "px"; // Set to defined height
		}
		else {
			div.style.width = (player.width - 20) + "px"; // Set to defined width - padding
			div.style.height = (player.height - 20) + "px"; // Set to defined height - padding
		}
		div.innerHTML = "<strong>Adobe Flash Player Requirement</strong><br />" + 
			"The ORLive video player requires that Adobe Flash Player " + ORPlatform.requiredFlashVersion + 
			" or greater be installed in your web browser. Please visit Adobe.com in order to " + 
			"<a href='http://www.adobe.com/go/getflash' target='_blank' style='color:white;'>download " + 
			"and install the latest version</a> of Adobe Flash Player and then restart your web browser " + 
			"and return to this page."
		if (installswf == "") return;
	}
	
	/********************* PARAMETERS AND VARIABLES *********************/
	
	// BUILD FLASH ATTRIBUTES OBJECT
	player.flashAttrib = {
		id: 					player.id,
		name: 					player.id
	};
	
	// BUILD FLASH PARAMS OBJECT
	player.flashParams = {
		allowFullScreen: 		player.fullscreen,
		allowScriptAccess: 		"always",
		wmode: 					"opaque"
	};
	
	// BUILD FLASH VARIABLES OBJECT
	player.flashVars = {
		background: 			player.background,
		branding: 				player.branding,
		controls: 				player.controls,
		fullscreen: 			player.fullscreen,
		local: 					player.local,
		lights: 				player.lights,
		mute: 					player.mute,
		playlist: 				player.playlist,
		showPlayComplete: 		player.showPlayComplete,
		showPlayPause: 			player.showPlayPause,
		showPlayReady: 			player.showPlayReady,
		slide: 					player.slide,
		slider: 				player.slider,
		source: 				player.source,
		status: 				player.status,
		time: 					player.time,
		video: 					player.video,
		profile: 				player.profile,
		xml: 					player.xml
	};
	
	// LOOK FOR Z-INDEX SPECIFICATION
	var css = "outline:none; position:relative;";
	if (typeof ORPlatform.zIndex == "number")  css += " z-index:" + ORPlatform.zIndex + ";";
	else css += " z-index:499;";
	swfobject.createCSS("OBJECT#" + player.id, css);
	
	// EMBED PLAYER
	swfobject.embedSWF(playerswf, element, player.width, player.height, ORPlatform.requiredFlashVersion, installswf, player.flashVars, player.flashParams, player.flashAttrib);
	
}