/*******************************
 Interface for custom install
 ******************************/
MN.ci = {
	"installqmp" : null,
	"upgrade" : false,
	"os" : null,
	"browser" : null,
	"popup" : true, //Set to true if install is in a separate window (popup) from the main player
	"ffupgrade" : false,
	
	//If you are not using a popup, the contents of this function should go in your own player page logic
	"WindowOnLoad" : function() {
		if(!MN.QMPInstall.CanPlay()){
			MN.ci.loadPreInstall();
		}
		else{
			if(MN.ci.popup){
				top.window.document.location="../install/pre_player_allset.html";
				
				//MN.CSS.RemoveClass($('ciEnd'), 'ciHidden'); //Show close window graphic
			}
			else{
				//Start player and any other page functionality - put your own function and player callback below
				//If you remove this function, remove the Window Onload event at the bottom of the code
				top.window.document.location="http://event.oprah.com/videochannel/event/install/pre_player_allset.html";
				//MN.QVT.CreatePlayer('player', OnPlayerLoaded, 352, 264);
			}
		}
	},
	
	"showTrouble" : function() {
		
		MN.CSS.AddClass($('ciPostInstall'), 'ciHidden');
		if(MN.ci.installqmp){
				MN.ci.installqmp.Stop();
			}
		MN.CSS.AddClass($('ciPlayer'), 'ciHidden');
		MN.CSS.RemoveClass($('ciTrouble'), 'ciHidden');
	},
	
	"startMoveInstall" : function() {
		MN.CSS.AddClass($('ciStart'), 'ciHidden');
		MN.CSS.RemoveClass($('ciPreInstall'), 'ciHidden');
	},
	
	"loadPreInstall" : function() {
		MN.CSS.RemoveClass($('ciPreInstall'), 'ciHidden');
		MN.ci.InstallInit();
		window.focus();
	},
	
	"InstallInit" : function() {
		MN.ci.displayInstallInstructions();
		MN.QMPInstall.MSG_BADOS = '';
		MN.QMPInstall.MSG_BADBROWSER = '';
		MN.QMPInstall.MSG_NEEDREINSTALL = '';
		MN.QMPInstall.MSG_UPGRADE_WIN_MOZILLA = '';
		MN.QMPInstall.MSG_UPGRADE_BASE_WIN_MOZILLA = '';
		MN.QMPInstall.MSG_UPGRADEFAILED = '';
		MN.QMPInstall.MSG_CANINSTALL = '';
		MN.QMPInstall.MSG_INSTALL_win_mozilla = '';
		MN.QMPInstall.MSG_INSTALL_win_ie = '';
		MN.QMPInstall.MSG_INSTALL_java = '';
		MN.QMPInstall.MSG_INSTALLING = '<div id="moveplay_progressouter"><div id="moveplay_progressinner"></div></div><span id="moveplay_installprogressmsg"></span>';
		MN.QMPInstall.MSG_BASE_INSTALLING_PREFIX = '<div id="moveplay_progressouter"><div id="moveplay_progressinner"></div></div><span id="moveplay_installprogressmsg"></span>';
		MN.QMPInstall.MSG_BASE_INSTALLING_POSTFIX = '<div id="moveplay_progressouter"><div id="moveplay_progressinner"></div></div><span id="moveplay_installprogressmsg"></span>';
		MN.QMPInstall.MSG_NOINSTALLMETHOD = '';
		MN.QMPInstall.MSG_NEEDRESTART = '';
	},
	
	"displayInstallInstructions" : function() {
		MN.ci.os = MN.QMPInstall.OS();
		MN.ci.browser = MN.QMPInstall.Browser();
		MN.ci.upgrade = MN.QMPInstall.UpgradeRequired();
		MN.ci.supportedOS = MN.QMPInstall.OSIsGood();
		
		if(MN.ci.upgrade && !(MN.ci.browser == "mozilla" && MN.ci.os != "mac")){
			
			MN.CSS.AddClass($('ciPreInstall'), 'ciHidden');
			MN.CSS.AddClass($('ciStart'), 'ciHidden');
			MN.CSS.RemoveClass($('ciUpgrade'), 'ciHidden');
			MN.CSS.RemoveClass($('ciPlayer'), 'ciHidden');
			MN.CSS.RemoveClass($('ciUpgradeNoFF'), 'ciHidden');
			MN.ci.StartUpgrade();
		}
		else if(MN.ci.upgrade){
			//PC-Firefox Upgrade
			MN.CSS.AddClass($('ciPreInstall'), 'ciHidden');
			MN.CSS.AddClass($('ciStart'), 'ciHidden');
			MN.CSS.RemoveClass($('ciUpgrade'), 'ciHidden');
			MN.CSS.RemoveClass($('ciPlayer'), 'ciHidden');
			MN.CSS.RemoveClass($('ciUpgradeFF'), 'ciHidden');
			MN.CSS.AddClass($('ciInstall2'), 'ciPicFF');
			
			
		}
		else if(MN.ci.supportedOS){
			MN.CSS.RemoveClass($('ciPlayer'), 'ciHidden');
			if(MN.ci.os == "mac")
			{	
				MN.CSS.RemoveClass($('ciPlayer'), 'ciNormal');
				MN.CSS.AddClass($('ciPlayer'), 'ciMoved');
				if(MN.QMPInstall.BrowserIsGood()){
					if(MN.ci.browser == "safari")
					{
						MN.CSS.RemoveClass($('ciMac'), 'ciHidden');
						MN.CSS.AddClass($('ciInstall1'), 'ciPicSafari');
					}
					else if(MN.ci.browser == "mozilla")
					{
						MN.CSS.RemoveClass($('ciMac'), 'ciHidden');
						MN.CSS.AddClass($('ciInstall1'), 'ciPicMacFF');
					}
					MN.QVT.CreatePlayer("ciPlayer", MN.ci.OnInstallPlayerLoaded, 352, 264);
				}
				else{
					MN.CSS.RemoveClass($('ciNoMac'), 'ciHidden');
					MN.CSS.AddClass($('ciButtons1'), 'ciHidden');
				}
			}
			else
			{
				if(MN.QMPInstall.BrowserIsGood()){
					if(MN.ci.browser == "ie")
					{
						MN.CSS.RemoveClass($('ciIE'), 'ciHidden');
						MN.CSS.AddClass($('ciInstall1'), 'ciPicIE');
					}
					else if(MN.ci.browser == "mozilla")
					{
						MN.CSS.RemoveClass($('ciFF'), 'ciHidden');
						MN.CSS.AddClass($('ciInstall1'), 'ciPicFF');
					}
					MN.QVT.CreatePlayer("ciPlayer", MN.ci.OnInstallPlayerLoaded, 352, 264);
				}
				else{
					MN.CSS.RemoveClass($('ciNoPC'), 'ciHidden');
					MN.CSS.AddClass($('ciButtons1'), 'ciHidden');
				}
			}
		}
		else{
			MN.CSS.RemoveClass($('ciNoOS'), 'ciHidden');
			MN.CSS.AddClass($('ciButtons1'), 'ciHidden');
			
		}
		
	},
	
	"StartUpgrade" : function() {
		MN.QVT.CreatePlayer("ciPlayer", MN.ci.OnInstallPlayerLoaded, 352, 264);
	},
	
	"StartInstall" : function() {
		MN.QMPInstall.StartInstall();
	},
	
	"OnInstallPlayerLoaded" : function(player) {
		if(!player)
		{
			return;
		}
		MN.CSS.RemoveClass($('ciPlayer'), 'ciMoved');
		MN.CSS.AddClass($('ciPlayer'), 'ciNormal');
		MN.CSS.AddClass($('ciPreInstall'), 'ciHidden');
	
		$('ciPlayer').style.width = '355px';
		$('ciPlayer').style.height = '267px';
		MN.ci.installqmp = player;
		MN.ci.installqmp.Play('http://cms007.dc2.qcn2.movenetworks.com/cms/publish/vod/vodclip/harpo/317.qvt');
		setTimeout(MN.ci.ShowInstallComplete, 1500);
	},
	
	"ShowInstallComplete" : function() {

	
		if(MN.ci.upgrade && !(MN.ci.browser == "mozilla" && MN.ci.os != "mac")){
			MN.CSS.AddClass($('ciUpgrade'), 'ciHidden');
		}
		MN.CSS.RemoveClass($('ciPostInstall'), 'ciHidden');
	},
	
	"ffCloser" : function() {
		
			window.open('','_parent','');
			window.close();
		
	},
	
	"CanSeeVideo" : function(b) {
		if(b) // The user said that they CAN see the video
		{
			MN.CSS.AddClass($('ciPostInstall'), 'ciHidden');
			if(MN.ci.installqmp){
				MN.ci.installqmp.Stop();
			}
			MN.CSS.AddClass($('ciPlayer'), 'ciHidden');
			if(MN.ci.popup){
				opener.location.reload(true);
				window.close();
				
			}
			else{
				
				location.reload(true);
			}
		}
		else // The user said that they CAN NOT see the video
		{
			if(MN.QMPInstall.OS() == "mac")
			{
				MN.ci.Popup('http://qmedia.xlontech.net/100513/global/support/faq.html', 650, 768); // Redirect to FAQ
			}
			else
			{
				MN.ci.Popup('http://qmedia.xlontech.net/100513/global/support/faq.html#av', 650, 768); // Redirect to the Audio/Video troubleshooting part of the FAQ
			}
		}
	},
	
	"Popup" : function(url, width, height, top, left) {
		if(!height) var height = 518;
		if(!width) var width = 785;
		if(!top) var top = 0;
		if(!left) var left = 0;
	
		var popup = null;
	
		var popupString = "height=%s,width=%s,toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,top=%s,left=%s".format(height, width, top, left);
		
		if(url != null)
		{
			popup = window.open(url, '_blank', popupString);
		}
		
		// Check to see if the window actually came up
		if(popup == null || typeof(popup) == "undefined")
		{
			// In case of a popup blocker
			alert('popup blocked');
			return null;
		}
		return popup;
	}
};
MN.Event.Observe(window,"load",MN.ci.WindowOnLoad);