// JavaScript Document


// UI Main Objects

var mediaPlaying = false;
var currentSpeaker = null;
function Presentations(){
	this.Open = function(){
		if(this.Count()>=arguments[0] && arguments[0]>0){
			
			this.GetItem(arguments[0]);
			this.Current().Open();
			}
			else return(false);
		}
	this.UserOpen = function(){
		if((PresentationList.Current().getProperty('status')==4 )|| (Webcast.getProperty('status')>2)){
			this.Open(arguments[0]);
			}
		else return(false);
		}
	this.OpenNext = function(){
		if(this.getPointer()<(this.Count()-1)){
			this.Next();
			//alert('setting presentation to next?');
			this.Current().Open();
			}
		else return(false);
		}
	this.OpenPrevious = function(){
			if(this.getPointer()>0){
				this.Previous();
				this.Current().Open();
			}
		else return(false);

		}
	}
Presentations.prototype = new ObjectList();
var PresentationList = new Presentations();

var Webcast = new Item();
	/*Webcast.setProperty('width',320);
	Webcast.setProperty('height',240);
*/
function UI(){
	this.init = initUI;

	function initUI(){
		this.setProperty('currentspeakerinfofield','speakertitleField');
		/*this.setProperty('',null);
		this.setProperty('',null);
		this.setProperty('',null);
		this.setProperty('',null);
		*/
		}
}
UI.prototype = new Item();

var UI = new UI();
	UI.init();


function ErrorHandler(){
	this.listLength = null;
	this.autoprint = false;
	this.Add = function(){
		var newItem = this.Insert();
		newItem.setProperty('message',arguments[0]);
		if(this.autoprint) this.Print();
		}
	this.Print = function(){
		if(this.target && this.Count())
		addTD(this.target,this.Current().getProperty('message'),'BEGINNING');
		if(this.listLength != null)
		this.Trim(this.listLength);
		}
	this.PrintAll = function(){
		this.First();
		if(!this.isEmpty())
			do{
				this.Print();
				}while(this.Next());
		}
	this.Trim = function(){
		trimTable(this.target,arguments[0]);
		}
	}
ErrorHandler.prototype = new ObjectList();
statusmessages = new ErrorHandler();
statusmessages.target = 'statusmessagetable';
statusmessages.listLength = 10;
statusmessages.autoprint = true;
	
var errors = new ErrorHandler();
errors.target = 'errortable';
errors.autoprint = true;

function SlideControl(){
	this.enlargeSlide = enlargeSlide;
	this.preloadImage = new Image();
	this.slides 	= new ObjectList();
	this.init 		= initSlideControl;
	this.setSlide 	= setSlide;
	this.getSlide 	= getSlide;
	this.checkForChange = checkForChange;
	this.Change 	= change;
	this.Hide 		= hide;
	this.Show 		= show;
	this.SetOpacity = setOpacity;	
	this.Next 		= getNextSlide;
	this.Previous 	= getPreviousSlide;
	this.NextSlide  = openNextSlide;
	this.PreviousSlide = openPreviousSlide;
	this.Open 			= openSlideSet;
	this.OpenCurrent	= OpenCurrentSlide;
	this.setHTMLContent = setHTMLSlide;
	//this.displayHTMLSlide = openHTMLSlide;
	//this.displayImageSlide = openImage;
	function enlargeSlide(){
		window.open(baseURL+'viewpicture.php?pid='+PresentationList.Current().getProperty('slides').Current().getProperty('id'), 'Enlargement','status=no,location=no,menubar=no,toolbar=no,scrollbars=yes,resizable=no');
		}
	function checkForChange(newtime){
		var found=-1;
		newtime = parseInt(newtime*10);
		if(!PresentationList.Current().getProperty('slidechanges').IsEmpty()){
			PresentationList.Current().getProperty('slidechanges').First();
			do	{
				if(newtime >=parseInt(PresentationList.Current().getProperty('slidechanges').Current().getProperty('time'))) found = PresentationList.Current().getProperty('slidechanges').Current().getProperty('number');
//				statusmessages.Add('comparing '+PresentationList.Current().getProperty('slidechanges').Current().getProperty('time')+' to '+newtime);
				}while(PresentationList.Current().getProperty('slidechanges').Next());
			}
		//	else statusmessages.Add('No slide changes set for current presentation');
		if(found >0)  this.setSlide(found);
		}	
	function change(){
		
		jobqueue.addJob('SlideControl.Hide()',true,20,50);
		jobqueue.addJob('SlideControl.OpenCurrent()',true,1);
		jobqueue.addJob('SlideControl.Show()',true,20,50);	
		}
	function openNextSlide(){
		if(this.Next())
		this.Change();
		}
	function setSlide(slide){
		if(this.getSlide(slide))
			this.Change();
	//	else statusmessages.Add('getSlide returned false for slide ' + slide + ' - slide already set');
		}
	function openPreviousSlide(){
		if(this.Previous())
			this.Change();
		}	

	function initSlideControl(){
		this.setProperty('visibility','hidden');
		this.setProperty('opacity',100);
		this.setProperty('stepping',10);
		this.setProperty('imageobjectID','imageField');
		this.setProperty('slideHTMLcontainerID','slideHTMLcontainer');
		this.setProperty('objectID',this.getProperty('imageobjectID'));
		this.setProperty('slidetextContainer','slidetextcontainer');
		this.setProperty('slidenumberContainer','slidenumbercontainer');
		if(!PresentationList.IsEmpty())	{
			this.setSlide(Webcast.getProperty('currentslide'));
			//statusmessages.Add('setting slide '+Webcast.getProperty('currentslide'));
			}
		else statusmessages.Add('no presentations found');
		if(Webcast.getProperty('status')<4){
			//hide slide controls
			if(getElement('slideControlsNext')) getElement('slideControlsNext').style.display='none';
			if(getElement('slideControlsPrevious')) getElement('slideControlsPrevious').style.display='none';
			}
		}
	function getSlide(snumber){
		var currentSlideSet = PresentationList.Current().getProperty('slides');
		if(!currentSlideSet.IsEmpty()){
			if(PresentationList.getPointer() != this.getProperty('currentPresentation')){
				statusmessages.Add('Slidecontrol notice - Presentation has changed');
				this.setProperty('currentPresentation',PresentationList.getPointer());
				return(currentSlideSet.GetItem(snumber));
				}
			if(snumber == parseInt(currentSlideSet.getPointer())+1){
				return(false);
				}
			else return(currentSlideSet.GetItem(snumber));
			}
		else{
			currentSlideSet.getSlideList();
			return(false);		
			}
		}
		
	function getNextSlide(){	
		var currentSlideSet = PresentationList.Current().getProperty('slides');
		if(!currentSlideSet.IsEmpty()){
			if(currentSlideSet.getPointer() < currentSlideSet.Count()-1){
				return(currentSlideSet.Next());
			}
			else return(false);
		}
		else return(false);
		}
	
	function getPreviousSlide(){
		var currentSlideSet = PresentationList.Current().getProperty('slides');
		if(!currentSlideSet.IsEmpty()){
			if(currentSlideSet.getPointer() > 0){
				return(currentSlideSet.Previous());	
			}
			else return(false);
		}
		else return(false);
		}
	
	function OpenCurrentSlide(){
		var slideList = PresentationList.Current().getProperty('slides');
		statusmessages.Add('Opening slide '+ parseInt(slideList.getPointer()+1)+' / '+slideList.Count());
		if(PresentationList.Current().getProperty('slidechanges').IsEmpty()) PresentationList.Current().getSlideChanges();
		if(slideList.Count()>0){
			
			
			/*Change Slide*/
			var Slide = slideList.Current();
			var slideImageElement 	= this.getProperty('imageobjectID'); 
			var slideHTMLElement 	= this.getProperty('slideHTMLcontainerID');
		//	alert(Slide.getProperty('type'));
			if(Slide.getProperty('type') == 'image'){
				this.setProperty('objectID',this.getProperty('imageobjectID'));
				//Hide HTML if necessary, display image field.
				if(slideHTMLElement != -1)getElement(slideHTMLElement).style.display='none';
				if(slideImageElement ==-1 ){ //generate error
					return(false);
					}
				else {
					getElement(slideImageElement).style.display = 'block';
					getElement(slideImageElement).width = Webcast.getProperty('slidewidth');
					//alert('displaying image '+Slide.getProperty('url')+', field display is set to: '+getElement(slideImageElement).style.display);
					getElement(slideImageElement).src = Slide.getProperty('url');	
					}//no errors
				}//End image slide
			else if(Slide.getProperty('type') == 'html'){
				this.setProperty('objectID',this.getProperty('slideHTMLcontainerID'));
				//Display HTML slide
				if(slideImageElement != -1)getElement(slideImageElement).style.display='none';
				if(slideHTMLElement ==-1 ){ //generate error
					return(false);
					}
				else {
					getElement(slideHTMLElement).style.display='block';
					getElement(slideHTMLElement).width=Webcast.getProperty('slidewidth');
					//alert('displaying HTML '+Slide.getProperty('id')+', field display is set to: '+getElement(slideHTMLElement).style.display);
					getHTMLSlide();
					}
				}//end html slide
			else statusmessages.Add('undefined slide type:'+ Slide.getProperty('type'));
			if(slideList.Next()){
				/*Pre-load next slide*/
				if(Slide.getProperty('type') == 'image')
					this.preloadImage.src = Slide.getProperty('url');
				slideList.Previous();
				}
			if(this.getProperty('slidetextContainer')!=null && this.getProperty('slidetextContainer')!=-1 ){
				//Display slide infotext if any + container available.
				if(getElement(this.getProperty('slidetextContainer'))){
				   getElement(this.getProperty('slidetextContainer')).innerHTML = Slide.getProperty('text')!=-1 ? Slide.getProperty('text') : '';
				   }
				  else errors.Add('no container found for slide text');
				}
			if(this.getProperty('slidenumberContainer')!=null && this.getProperty('slidenumberContainer')!=-1 ){
				//Display slide number if container available
				if(getElement(this.getProperty('slidenumberContainer'))){
				   getElement(this.getProperty('slidenumberContainer')).innerHTML = (parseInt(slideList.getPointer()+1)) + ' / ' + slideList.Count();
				   }						  
				  else errors.Add('no container found for slide number');
				}
			}//if there are slides
		else return(false);
		}
	function setHTMLSlide(content){
	getElement(this.getProperty('slideHTMLcontainerID')).innerHTML = content;
	}
	function hide(){
		// Hide current slide 
		if(this.getProperty('opacity')>0){
			//alert(this.getProperty('opacity'));
			this.setProperty('opacity',(this.getProperty('opacity')-this.getProperty('stepping')));
			this.SetOpacity(this.getProperty('objectID'),this.getProperty('opacity'));
			return(false);
		}
		else return(true);
	}
	function show(){
		//Show current slide
		if(this.getProperty('opacity')<100){
			this.setProperty('opacity',(this.getProperty('opacity')+this.getProperty('stepping')));
			this.SetOpacity(this.getProperty('objectID'),this.getProperty('opacity'));
			return(false);
		}
		else return(true);
		}

	function setOpacity(obj, opacity) {
		//Set object opacity
		if(obj==-1) return(false);
	 obj = getElement(obj);
	  opacity = (opacity == 100)?99.999:opacity;
	  
	  // IE/Win
	  obj.style.filter = "alpha(opacity:"+opacity+")";
	  
	  // Safari<1.2, Konqueror
	  obj.style.KHTMLOpacity = opacity/100;
	  
	  // Older Mozilla and Firefox
	  obj.style.MozOpacity = opacity/100;
	  
	  // Safari 1.2, newer Firefox and Mozilla, CSS3
	  obj.style.opacity = opacity/100;
	}
}
SlideControl.prototype = new Item();

var SlideControl = new SlideControl();
	SlideControl.init();
	
var ChatControl = new Item();

var PollControl = new Item();

function PlayerControl(){
	this.setMediaSource = function(){
		this.setProperty('mediasource',PresentationList.Current().getProperty('mediasources').Current());
		this.setProperty('currentsourcetype',this.getProperty('mediasource').getProperty('sourcetype'));
		}
	this.Play = playMedia;
	this.Stop = stopMedia;
	this.Open = openMedia;
	
		function playMedia(){
			/* Write media player component for selected media source */
			var playerHTML = '';
			var ODFile = '';
			this.setMediaSource();
			if(this.getProperty('width')==-1)
				this.setProperty('width',Webcast.getProperty('videowidth'));
			if(this.getProperty('height')==-1)
				this.setProperty('height',Webcast.getProperty('videoheight'));
			var mSource = this.getProperty('mediasource');
			this.setProperty('displaycontrols',(PresentationList.Current().getProperty('videocontrols')==1 ? true : false));
		//	alert(this.getProperty('displaycontrols'));
		statusmessages.Add('opening media player: '+this.getProperty('width')+' x '+this.getProperty('height') + 'px, format: '+mSource.getProperty('mediaformat')+'.');
		if(mediaPlaying == false || (PresentationList.Current().getProperty('status')==4 )|| (Webcast.getProperty('status')>2)){
			switch(mSource.getProperty('mediaformat')){
				case "wm":
					var WMPlayerHeight = parseInt(this.getProperty('height'));
					if(mSource.getProperty('sourcetype')=='ondemand'){ 
						if((PresentationList.Current().getProperty('ondemandfile')!=-1) && (PresentationList.Current().getProperty('ondemandfile'))){
							ODFile = PresentationList.Current().getProperty('ondemandfile');
						}
						else if(mSource.getProperty('filename')!=-1){ 
							ODFile = mSource.getProperty('filename');
						}
						else{
							ODFile = (parseInt(PresentationList.getPointer())+1) + '.'+ (mSource.getProperty('mediatype')=='audio' ? "wma" :"wmv");
						}
					}
					if((mSource.getProperty('sourcetype')=='ondemand') && (this.getProperty('displaycontrols') == true)) WMPlayerHeight += 71;
					
					playerHTML = '<object classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" type="application/x-oleobject" width="'+this.getProperty('width')+'" border="0" height="'+WMPlayerHeight+'" hspace="0" vspace="0" standby="Loading Microsoft® Windows® Media Player components..." id="MediaPlayer">'+
					'        <param name="FileName" value="'+mSource.getProperty('url')+(mSource.getProperty('sourcetype')=='ondemand' ? ODFile :'')+'">'+
					'        <param name="AutoStart" value="true">'+
					'        <param name="AutoRewind" value="true">'+
					'        <param name="Loop" value="true">'+
					'        <param name="TransparentAtStart" value="true">'+
					'        <param name="AnimationatStart" value="false">';
					if((mSource.getProperty('sourcetype')=='ondemand') && (this.getProperty('displaycontrols') == true)) 
						playerHTML+='        <param name="ShowControls" value="true">'+
						'        <param name="ShowAudioControls" value="true">'+
						'        <param name="ShowStatusBar" value="true">'+
						'        <param name="ShowTracker" value="true">';
					else playerHTML+='        <param name="ShowControls" value="false">'+
					'        <param name="ShowAudioControls" value="false">'+
					'        <param name="ShowStatusBar" value="false">'+
					'        <param name="ShowTracker" value="false">';
					playerHTML+='        <param name="autoSize" value="false">'+
					'        <param name="ShowGotoBar" value="false">'+
					'        <param name="ShowDisplay" value="false">'+
					'        <param name="uiMode" value="mini">'+
					'        <param name="displaySize" value="0">'+
					
					'        <param name="ShowPositionControls" value="false">'+
					'        <embed type="application/x-mplayer2" id="MediaPlayer"'+
					'	 pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/"'+
					'	 src="'+mSource.getProperty('url')+(mSource.getProperty('sourcetype')=='ondemand' ? ODFile :'')+'"'+
					'	 height='+WMPlayerHeight+
					'	 width='+this.getProperty('width')+
					'	 hspace=0'+
					'	 vspace=0'+
					'	 border=0'+
					'	 autostart=1'+
					'	 transparentatstart=0'+
					'	 animationstart=1';
					if((mSource.getProperty('sourcetype')=='ondemand') && (this.getProperty('displaycontrols') == true))  
					   playerHTML+='	 showcontrols=1'+
						'	 showstatusbar=1'+
						'	 showtracker=1'+
						'	 showaudiocontrols=1';
					else playerHTML+='	 showcontrols=0'+
						'	 showstatusbar=0'+
						'	 showtracker=0'+
						'	 showaudiocontrols=0';
					playerHTML+='	 showdisplay=0'+
					'	 showpositioncontrols=0'+
					'	 uimode=mini'+
					' autosize=0'+
					'	 displaysize=0> </embed>'+
					'      </object>';
				//	statusmessages.Add(mSource.getProperty('url')+(mSource.getProperty('sourcetype')=='ondemand' ? (mSource.getProperty('filename')!=-1 ? mSource.getProperty('filename')  : (parseInt(PresentationList.getPointer())+1)) + '.'+ (mSource.getProperty('mediatype')=='audio' ? "wma" :"wmv") :''));
						if(this.getProperty('objectID')!=-1){
							if(getElement(this.getProperty('objectID'))){
								var playerElement = getElement(this.getProperty('objectID'));
								//Write player to UI
								playerElement.innerHTML = playerHTML;
								playerElement.height = WMPlayerHeight;
								playerElement.width = this.getProperty('width');
								if(getElement('slideTD') && getElement('playerContentTD')){
									if(parseInt(getElement('playerContentTD').style.padding)){
									getElement('slideTD').height = parseInt(WMPlayerHeight)+(parseInt(getElement('playerContentTD').style.padding)*2);
//									getElement('slideTD').width = this.getProperty('width');
									statusmessages.Add('slide window height set to'+parseInt(WMPlayerHeight)+'px');
									}
									}
								else statusmessages.Add('unable to fit slide window');
							//	alert(playerHTML);
								//getElement(this.getProperty('objectID')).style.backgroundColor='#cccccc';
								if(getElement('MediaPlayer')){
									getElement('MediaPlayer').InvokeURLs=0;
									getElement('MediaPlayer').URL=mSource.getProperty('url');
									if(!navigator.userAgent.indexOf("IE") == -1) getElement('MediaPlayer').Open(mSource.getProperty('url'));
									 }
								}
							
						else errors.Add('could not render media player component, container missing: '+this.getProperty('objectID'));
						}
					break;
				case "real":
					playerHTML+='<table cellpadding="0" cellspacing="0" border="0"><tr><td><OBJECT CLASSID="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width='+this.getProperty('width')+' height='+this.getProperty('height')+' hspace="0" vspace="0">'+
					'   <param name="controls" VALUE="imagewindow">'+
					'   <param name="console" VALUE="video">'+
					'	<param name="loop" value="false">'+
					'	<param name="autostart" value="true">'+
					'	<param name="autogotourl" value="false">'+
					'   <param name="src" value="'+mSource.getProperty('url')+(mSource.getProperty('sourcetype')=='ondemand' ? (mSource.getProperty('filename')!=-1 ? mSource.getProperty('filename')  : (parseInt(PresentationList.getPointer())+1)) + '.'+ (mSource.getProperty('mediatype')=='audio' ? "rma" :"rm") :'')+'">'+
					'  <embed scriptcallbacks="onGoToUrl" SRC="'+mSource.getProperty('url')+(mSource.getProperty('sourcetype')=='ondemand' ? (mSource.getProperty('filename')!=-1 ? mSource.getProperty('filename')  : (parseInt(PresentationList.getPointer())+1)) + '.'+ (mSource.getProperty('mediatype')=='audio' ? "rma" :"rm") :'')+'" width='+this.getProperty('width')+'  height='+this.getProperty('height')+' hspace="0" vspace="0" autostart="true" loop="false" type="audio/x-pn-realaudio-plugin" controls="imagewindow" console="video" autogotourl="false" name="rvcontrol"></embed></object></td></tr>';
					if((mSource.getProperty('sourcetype')=='ondemand') && (this.getProperty('displaycontrols') == true)) 
					playerHTML+='<tr><td><object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="'+this.getProperty('width')+'" height="70" hspace="0" vspace="0" id="rvcontrol"><param name="controls" VALUE="ControlPanel,StatusField,PositionField">'+
					'   <param name="console" VALUE="video">'+
					'	<param name="loop" value="true">'+
					'	<param name="autostart" value="true">'+
					'	<param name="autogotourl" value="false">'+
					'   <param name="src" VALUE="'+mSource.getProperty('url')+(mSource.getProperty('sourcetype')=='ondemand' ? (mSource.getProperty('filename')!=-1 ? mSource.getProperty('filename')  : (parseInt(PresentationList.getPointer())+1)) + '.'+ (mSource.getProperty('mediatype')=='audio' ? "rma" :"rm") :'')+'">'+
					'   <embed scriptcallbacks="onGoToUrl" src="'+mSource.getProperty('url')+(mSource.getProperty('sourcetype')=='ondemand' ? (mSource.getProperty('filename')!=-1 ? mSource.getProperty('filename')  : (parseInt(PresentationList.getPointer())+1)) + '.'+ (mSource.getProperty('mediatype')=='audio' ? "rma" :"rm") :'')+'" width="'+this.getProperty('width')+'" height="69" hspace="0" vspace="0" autostart="true" loop="true" type="audio/x-pn-realaudio-plugin" console="video" autogotourl="false">'+
					'	</embed></object></td></tr>';
					playerHTML+='</table>';
					if((mSource.getProperty('sourcetype')=='ondemand') ||(currentShow.presentationStatus=='ondemand') || (this.getProperty('currentsourcetype') == 'ondemand')){
						if(this.getProperty('objectID')!=-1){
							//Write player to UI
							var playerElement = getElement(this.getProperty('objectID'));
							playerElement.innerHTML = playerHTML;
							playerElement.width = this.getProperty('width')+'px';
							var elHeight = parseInt(this.getProperty('height'));
							if((mSource.getProperty('sourcetype')=='ondemand') && (this.getProperty('displaycontrols') == true)) elHeight += 69;
							playerElement.height = elHeight+'px';
							playerElement.valign = 'top';

							}
						else errors.Add('could not render media player component, container missing: '+this.getProperty('objectID'));
					}
					break;
				case "flash":
					break;
				case "qt":
					break;
				default:
					alert('Error: Unknown media format('+mSource.getProperty('mediaformat')+'). Could not open the player element.');
					break;
				}
				mediaPlaying = true;
			}
				
			}
		function stopMedia(){
			}
		function openMedia(){
			this.setMediaSource();
			this.Play();
			}
}
PlayerControl.prototype = new Item();

var PlayerControl = new PlayerControl();
	PlayerControl.setProperty('objectID','playerField');
	PlayerControl.setProperty('currentsourcetype',null);
	PlayerControl.setProperty('width',null);
	PlayerControl.setProperty('height',null);
	PlayerControl.setProperty('displaycontrols',true);
	PlayerControl.setProperty('mediasource',null);
	
	


function openSlideSet(){
	//statusmessages.Add('opening slide 1 of '+PresentationList.Count()+' for presentation '+PresentationList.Current().getProperty('showtitle'));
	PresentationList.Current().getProperty('slides').First();
	this.setSlide(Webcast.getProperty('currentslide'));
//	this.setSlide();
	}

function openPresentation(index){
	//Opens selected presentation: player,slides,etc
		var sourceToOpen = index ? this.getProperty('mediasources').GetItem(index) : this.getProperty('mediasources').Current();
	//debug	alert('opening presentation '+this.getProperty('showtitle'));
		if(this.getProperty('mediasources').IsEmpty())
			{
			getMediasources();
			return(false);
			}
		if(this.getProperty('mediasources').Count()>1){
			var mSources = this.getProperty('mediasources') ;
			//	alert('opening mediasource '+ (this.getProperty('mediasources').getPointer()+1) +' / ' + this.getProperty('mediasources').Count());
			if(mediatype==null && (!index)){
				//Media type selection ;if mediatype is selected, only sources of selected type were loaded (hopefully)
				var mediaTypes = new Array();
				do	{
					if(!in_array(mSources.Current().getProperty('mediaformat'),mediaTypes))
						mediaTypes.push(mSources.Current().getProperty('mediaformat'));
					}while(mSources.Next());
					mSources.First();
					//Create selection menu
					CreateMediatypeSelector(mediaTypes);
					sourceToOpen = false;
				}
			else if(sourceToOpen.getProperty('mediaformat') != mediatype){
				//try to open source of specified format
				mSources.First();
				var loop = true;
				do	{
					if(mSources.Current().getProperty('mediaformat') == mediatype){
						sourceToOpen = mSources.Current();
						loop = false;
					}
					}while(mSources.Next() && loop == true);
				
			}

			}
		if(sourceToOpen != false){
		if(sourceToOpen.getProperty('url')!=-1){
			PlayerControl.setProperty('src',sourceToOpen.getProperty('url'));
			PlayerControl.setProperty('width',sourceToOpen.getProperty('width'));
			PlayerControl.setProperty('height',sourceToOpen.getProperty('height'));
			PlayerControl.setMediaSource();
			PlayerControl.Play();
			}
		else errors.Add('No media source selected.');
		}
		else errors.Add('No source URLs defined for presentation');
	SlideControl.Open();
	this.displayProperty('speaker','currentspeakertitlefield');
	this.displayProperty('showtitle','playerHeaderTD');
	Webcast.displayProperty('date','datefield');
	}

currentSpeaker = PresentationList.Current();

function selectMediaType(newType){
	mediatype = newType;
	statusmessages.Add('mediatype set to '+ mediatype);
	PresentationList.Current().Open();
	
}
function CreateMediatypeSelector(mediaTypes){
var cType = null;
var cell = null;
var row = null;
var cellHTML = '';
var i = 0;
var currentcol = 0;
var cols = 3;
if(mediaTypes.length){
	if(mediaTypes.length < cols) cols = mediaTypes.length;
	statusmessages.Add(mediaTypes.length+' sources available');
	if(getElement(PlayerControl.getProperty('objectID'))){
		var targetTable = document.createElement('table');
		getElement(PlayerControl.getProperty('objectID')).innerHTML ='';
		if(parseInt(PlayerControl.getProperty('height'))>0)getElement(PlayerControl.getProperty('objectID')).height = PlayerControl.getProperty('height');
		getElement(PlayerControl.getProperty('objectID')).appendChild(targetTable);
		row = targetTable.insertRow(-1);
		cell = row.insertCell('-1');
		cell.colSpan = cols;
		
		cell.innerHTML = 'Valitsemasi tapahtuma on katsottavissa useissa mediaformaateissa.<br>Valitse Sinulle parhaiten sopiva formaatti:';
	
		row = targetTable.insertRow(-1);
		while(cType = mediaTypes.pop()){
			cellHTML ='';
			currentcol++;
			if(currentcol>cols){	
				row = targetTable.insertRow(-1);
				currentcol = 1;
			}
			cell = row.insertCell(-1);
			cell.style.padding = '10px';
			if((currentcol < cols) && (cType == mediaTypes.length-1)){
					cell.colSpan = ( cols +1  - currentcol);
			}
			cell.valign='middle';
			cell.align='center';
			switch(cType){
				case "wm":
					cellHTML+='<img border="1" style="border-bottom-color:#000000;" src="images/mime_wmv.gif" border="0" vspace="4" hspace="4" alt ="Windows Media"><br><a href="#" onClick="selectMediaType(\'wm\'); return false;">Windows Media</a>';
					break
				case "real":
					cellHTML+='<img border="1" style="border-bottom-color:#000000;" src="images/mime_rm.gif" border="0" vspace="4" hspace="4" alt ="Real Media"><br><a href="#" onClick="selectMediaType(\'real\'); return false;">Real Media</a>';
					break
				case "qt":
					cellHTML+='<img border="1" style="border-bottom-color:#000000;" src="images/mime_mov.gif" border="0" vspace="4" hspace="4" alt ="Quicktime"><br><a href="#" onClick="selectMediaType(\'qt\'); return false;">Quicktime</a>';
					break
				case "flash":
					cellHTML+='<img border="1" style="border-bottom-color:#000000;" src="images/mime_swf.gif" border="0" vspace="4" hspace="4" alt ="Flash"><br><a href="#" onClick="selectMediaType(\'flash\'); return false;">Avaa Flash</a>';
					break
					}
			cell.innerHTML = cellHTML;
			cType = false;
			}
		}
		else return(false);
	}//end if mediatypes	
}//end function 
/*
function OpenPresentationList(){
	
	if(PresentationList.IsEmpty()) return(false);
	var currentIndex = PresentationList.getPointer();
	var cell = null;
	var row = null;
	var i =1;
	var j = null;
	
	if(getElement('presentationlisttable'))
	var targetTable = getElement('presentationlisttable');
	else {
		if(getElement('presentationlistcontainer')){
			getElement('presentationlistcontainer').innerHTML='';
			var targetTable = document.createElement('table');
			getElement('presentationlistcontainer').appendChild(targetTable);
			}
		else return(false);
		}
	
	PresentationList.First();
	targetTable.style.width='660px';
	do{
		currentListItem = PresentationList.Current();
		row = targetTable.insertRow(-1);
		//Create cell for presentation image
		cell = row.insertCell(-1);
		if(PresentationList.getPointer == currentIndex){
	//		cell.style.backgroundColor='#cccccc';
		}
		cell.style.width='80px';
		cell.style.height='40px';
		cell.style.verticalAlign='top';
		cell.rowSpan='2';
		cell.align='center';
			if(currentListItem.getProperty('speakerimage')!=-1){
					cell.innerHTML = '<img vspace="0" hspace="5" src="imagedata/'+currentListItem.getProperty('speakerimage')+'_'+presentationThumbnailWidth+'.jpg" border="3" style="border-color:#ffffff;" width="'+presentationThumbnailWidth+'">';
					}
			else {
						cell.innerHTML = '<img vspace="0" hspace="5" src="images/layout/default_thumbnail.gif" border="3" style="border-color:#ffffff;" width="40">';
			}
		//cell.innerHTML = 'kuva t&auml;h&auml;n';
		cell = row.insertCell(-1);
		cell.style.width='100px';
		cell.style.color='#acacac';
		cell.style.verticalAlign='top';
		cell.rowSpan='2';
		cell.innerHTML = currentListItem.getProperty('time');
		//Create cell for presentation info
		cell = row.insertCell(-1);
		cell.style.width='500px';
			cell.style.verticalAlign='top';
		if(PresentationList.getPointer == currentIndex){
			//cell.style.backgroundColor='#cccccc';
		}
		cell.innerHTML ='<a class="presentationListItem" href="#" onClick="PresentationList.UserOpen(' + parseInt(PresentationList.getPointer()+1) + '); return false;"><b>' + currentListItem.getProperty('showtitle')+'</b></a>';
		row = targetTable.insertRow(-1);
		cell = row.insertCell(-1);
			cell.style.verticalAlign='top';
		if(PresentationList.getPointer == currentIndex){
			//cell.style.backgroundColor='#cccccc';
		}
		cell.innerHTML =(currentListItem.getProperty('speaker') ? '<font color="#787878">'+ currentListItem.getProperty('speaker') + ((currentListItem.getProperty('speakertitle')) ? (',' +currentListItem.getProperty('speakertitle')) : '') +(currentListItem.getProperty('company')? ',' + currentListItem.getProperty('company') : '' +"</font>"): '');
		i++;
		}while(PresentationList.Next());
		
	PresentationList.setPointer(currentIndex);
	
}
*/
function OpenPresentationList(){
	
	if(PresentationList.IsEmpty()) return(false);
	var currentIndex = PresentationList.getPointer();
	var cell = null;
	var row = null;
	var oTBody = null;
	var containerRow = null;
	var containerCell = null;
	var i =1;
	var j = null;
	
	if(getElement('presentationlisttable'))
	var outerTable = getElement('presentationlisttable');
	else {
		if(getElement('presentationlistcontainer')){
			getElement('presentationlistcontainer').innerHTML='';
			 oTBody = document.createElement('tbody');
			var outerTable = document.createElement('table');
			outerTable.appendChild(oTBody);
			getElement('presentationlistcontainer').appendChild(outerTable);
			}
		else return(false);
		}
	if(oTBody != null) outerTable = oTBody;
	PresentationList.First();
	outerTable.style.width='640px';
	outerTable.style.verticalAlign='top';
	containerRow = document.createElement('tr');
	containerCell = document.createElement('td');
	var targetTable = document.createElement('table');
	targetTable.style.width='320px';
	targetTable.valign='top';
	targetTable.style.verticalAlign='top';
	if(!containerCell) return(false);
	//alert(containerCell);
	containerRow.appendChild(containerCell);
	outerTable.appendChild(containerRow);
	containerCell.appendChild(targetTable);
	do{
		currentListItem = PresentationList.Current();
		if(PresentationList.getPointer() == parseInt((PresentationList.Count()+1) / 2)){

			containerCell = document.createElement('td');
		 	targetTable = document.createElement('table');
				targetTable.style.width='320px';
			containerRow.appendChild(containerCell);
			containerCell.appendChild(targetTable);
			}
		row = targetTable.insertRow(-1);
		//Create cell for presentation image
		cell = row.insertCell(-1);
		if(PresentationList.getPointer == currentIndex){
	//		cell.style.backgroundColor='#cccccc';
		}
		cell.style.width='80px';
		cell.style.height='40px';
		cell.style.verticalAlign='top';
		cell.rowSpan='2';
		cell.align='center';
			if(currentListItem.getProperty('speakerimage')!=-1){
					cell.innerHTML = '<img vspace="0" hspace="5" src="imagedata/'+currentListItem.getProperty('speakerimage')+'_'+presentationThumbnailWidth+'.jpg" border="3" style="border-color:#ffffff;" width="'+presentationThumbnailWidth+'">';
					}
			else {
						cell.innerHTML = '<img vspace="0" hspace="5" src="images/layout/default_thumbnail.gif" border="3" style="border-color:#ffffff;" width="40">';
			}
		//cell.innerHTML = 'kuva t&auml;h&auml;n';
		cell = row.insertCell(-1);
		cell.style.width='100px';
//		cell.style.color='#acacac';
		cell.style.verticalAlign='top';
		cell.rowSpan='2';
		cell.className = 'presentationListTime';
		cell.innerHTML = currentListItem.getProperty('time');
		//Create cell for presentation info
		cell = row.insertCell(-1);
		cell.style.width='500px';
			cell.style.verticalAlign='top';
		if(PresentationList.getPointer == currentIndex){
			//cell.style.backgroundColor='#cccccc';
		}
		cell.innerHTML ='<a class="presentationListItem" href="#" onClick="PresentationList.UserOpen(' + parseInt(PresentationList.getPointer()+1) + '); return false;"><b>' + currentListItem.getProperty('showtitle')+'</b></a>';
		row = targetTable.insertRow(-1);
		cell = row.insertCell(-1);
		cell.className = 'presentationListSpeaker';
			cell.style.verticalAlign='top';
		if(PresentationList.getPointer == currentIndex){
			//cell.style.backgroundColor='#cccccc';
		}
		cell.innerHTML =(currentListItem.getProperty('speaker') ? currentListItem.getProperty('speaker') + ((currentListItem.getProperty('speakertitle')) ? (',' +currentListItem.getProperty('speakertitle')) : '') +(currentListItem.getProperty('company')? ',' + currentListItem.getProperty('company') : ''): '');
		i++;
		}while(PresentationList.Next());
	//alert(outerTable.innerHTML);
	PresentationList.setPointer(currentIndex);
	
}
var PresentationListView = new Item();
PresentationListView.setProperty('objectID','presentationlistcontainer');

var FeedbackView = new Item();
FeedbackView.setProperty('objectID','feedbackcontainer');
var MaterialListView = new Item();
MaterialListView.setProperty('objectID','materiallistcontainer');
if(getElement(MaterialListView.getProperty('objectID')))
MaterialListView.setProperty('initialcontent',getElement(MaterialListView.getProperty('objectID')).innerHTML);
MaterialListView.init = function(){
	if(getElement(MaterialListView.getProperty('objectID'))){
		if((getElement(MaterialListView.getProperty('objectID')).innerHTML == MaterialListView.getProperty('initialcontent')) || MaterialListView.getProperty('initialcontent')==-1)  
			openMaterialList();
		}
	else 	openMaterialList();
		
	}
	

