/* Copyright Innomotion 2005*/

var currentSelectionHref = null;
function DOMenu(){
	//määritellään DOmenu-luokka
	this.items = new Array();

	this.addItem = addItem;
	this.build = build;
	this.buildPresentationMenu = buildPresentationMenu;
	this.selectPresentation = selectPresentation;
	if(this.items.length){
			currentItem = this.items[this.items.length];	
		this.addShow = currentItem.addShow;
	}
}
function addItem(){
	//menu-kohdan lisäys
	if(arguments[0].toString().indexOf("[object Object]") != -1) {
		this.items[this.items.length] = arguments[0];
	} else {
		this.items[this.items.length] = new DOMenuItem(arguments[0], arguments[1], arguments[2], arguments[3],(this.items.length+1));
		//alert(this.items[this.items.length-1].topic);
		return(this.items[this.items.length-1])
	}
}
function addShow(){
	//menu-kohdan lisäys
	if(arguments[0].toString().indexOf("[object Object]") != -1) {
		this.shows[this.shows.length] = arguments[0];
	} else {
		this.shows[this.shows.length] = new DOShow(arguments[0], arguments[1], arguments[2],arguments[3]);
	}
	return(this.shows[this.shows.length-1])
}
function setCurrentItem(itemno,total){
	var i=1;
	
		for(i=0; i<total;i++){
	if(document.getElementById('ohjelma_linkki'+i)){
		if(i == parseInt(itemno)){
			
			document.getElementById('ohjelma_linkki'+i).style.color='#000000';
			}
		else {
			
			document.getElementById('ohjelma_linkki'+i).style.color='#666666';
			}
		}
	}//for
}
function DOMenuItem(topic,description,url,type,javaID){
	//menukohdan määrittely
	this.id = javaID;
	this.dateval = null;
	this.topic = topic ? topic : 'no topic';
	this.description = description!='undefined' ? description : '-';
	this.keywords = '';
	this.speakernames = new Array();
	this.url = url ? url : "";
	this.exturl= "";
	this.type = type;
	this.number = DOnumber++;
	this.shows = new Array();
	this.addShow = addShow;
	this.setDateVal = setDateVal;
	this.setStatus = setStatus;
	this.getSpeakernames = getSpeakernames;
	this.setDescription = setDescription;
	this.setKeywords = setKeywords;
	this.getShowCount = getShowCount;
	this. setExtUrl=setExtUrl;
	DOLastItem = this;
}
function getSpeakernames(){
	var namesArray = new Array();
	if(this.shows[0]){
		for(i=0;this.shows[i];i++)
			namesArray[namesArray.length] = this.shows[i].speaker;
		return(namesArray);
		}
	//else return(false);
	return(namesArray);
}
function getShowCount(){
	return(this.shows.length);
	}	
function setExtUrl(url) {
	this.exturl=url;
}
function setDescription(description){
	this.description = description;
	}
function setKeywords(){
	if(arguments[0])
	for(i=0;arguments[i];i++){
		if(i>0) this.keywords +=',';
		this.keywords += arguments[i];
	}
	}
function DOShow(topic,speaker,description,slides){
	this.topic = topic;
	this.description = description;
	this.speaker = speaker;
	this.setFilename = function(){ }
	this.slides = slides ? slides : 0;
	this.addSlideTimes = addSlideTimes;
	this.addSlideNumbers = addSlideTimes;
}
function addSlideTimes(){
}
function setDateVal(dateval){
	this.date = dateval;
}

function buildPresentationMenu(area,current){
area--;
current--;
var currentItem = this.items[area];
var output='';
if(currentItem.shows[0]) {
	var totalShows = currentItem.shows.length;
		output+='<table id="maintable" width="100%" cellspacing="0" cellpadding="2">';
		for(j=0; currentItem.shows[j];j++){
			currentShow=currentItem.shows[j];
			output+='<tr onClick="setCurrentItem('+j+','+totalShows+');  parent.openPresentation('+(j+1)+')" style="cursor:pointer; cursor:hand">';
			if(j==current) output+='<td id="ohjelma_linkki'+j+'" style="color:#000000; padding-left: 20px; padding-right:5px;" class="normal">';
			else output+='<td class="normal" id="ohjelma_linkki'+j+'" style="color:#666666; padding-left: 20px; padding-right:5px;">';
			output+='<strong>'+currentShow.topic+'</strong><br>'+currentShow.speaker+'</td></tr>';
		if(currentItem.shows[j+1]) output+='<tr><td height="1" background="images/divider.gif" style="background-repeat:repeat-x;"><img src="images/spacer.gif" height="1" border="0" alt=""></td></tr>';
		}//for
	}//if
else {
	output+='<strong>'+currentItem.topic+'</strong><br>';
	}
output+='</table>';
//alert(output);
getElement('body').innerHTML=output;
}
function expandItem(itemno){
	expand = itemno;
	juuri.build();
}
function collapseItem(){
	expand = '-1';
	juuri.build();
}
function selectPresentation(itemid){
	if(getElement('openerLink')){
		getElement('openerLink').style.visibility = 'visible';
		getElement('openerLink').style.display = 'block';
		}
	if(getElement('openerTD')){
		getElement('openerTD').background = 'images/webcastcenter/open_bg.gif';
		getElement('openerTD').style.backgroundImage = 'url(images/webcastcenter/open_bg.gif)';

		}
	currentItem = this.items[itemid];
	var informationContent = '';
	var target = null;
	target = getElement('information');
	//Sisältö: Kuvaus, Asiasanat, puhujat, paikka, pvm
	informationContent +='<p><b>Kuvaus</b></p>';
	if(currentItem.description=='undefined') 
		currentItem.setDescription('-');
	informationContent +='<p> '+currentItem.description+'</p>';
	/*informationContent +='<p><b>Asiasanat</b></p>';
	if(currentItem.keywords == 'undefined') currentItem.setKeywords('-');
	informationContent +='<p>'+currentItem.keywords+'</p>';
	*/
	var sNames = new Array();
	sNames = currentItem.getSpeakernames();
	if(sNames.length>0){
			informationContent +='<p><b>Puhujat</b></p>';
		informationContent +='<p>';
		for(i=0;sNames[i];i++){ 
			if(i>0) informationContent += ',';
			informationContent += ' '+sNames[i];
		}
		informationContent +='</p>';
		}
	if(currentItem.dateval != null){
		informationContent +='<p><b>Aika ja paikka</b></p>';
		informationContent +='<p>'+currentItem.dateval+'</p>';
	}
	if(currentItem.getShowCount()>0)
		informationContent +='<p><b>Tapahtumassa on '+currentItem.getShowCount()+' esitystä.</b></p>';
	if(target != null)
		target.innerHTML = informationContent;
	else alert('Tapahtumasta ei löydy tietoja');
	
}
function openCurrentSelection(){
	if(currentItem){
		currentSelectionHref = 'player.html?alue='+currentItem.id;
		}
	if(currentItem.exturl!="")
		document.location.href = currentItem.exturl;
	else if(currentSelectionHref)
		document.location.href = currentSelectionHref;
	}
function build(){
//rakentaa menun
target = document.getElementById('content');
var output ='<table width="100%" border="0" cellpadding="0" cellspacing="0" title="Ohjelma">';
for(i=this.items.length-1; i>=0;i--){
	currentItem = this.items[i];
	//alert(currentItem.topic);
	output +='<tr><td style="padding: 5px;" align="left" valign="middle" class="header_dark">';
	output+='<a href="#" onClick="juuri.selectPresentation('+i+'); return false;" style="text-decoration:none; text-transform:uppercase;">';
		output += currentItem.topic +'</a></td><td>';
	if(currentItem.date) output +=' '+currentItem.date;
	 if(currentItem.status=='live') output+='&nbsp;<img align="absmiddle" src="images/live.gif" border="0" alt="Live-esitys"> <font color="green">LIVE</font>';
	 output+='	</td></tr>';
		}
output+='	</table>';
if(document.getElementById('content')) document.getElementById('content').innerHTML=output;
else {
	document.write(output);
	alert('error: content div was not found');
	}
}
