/* Copyright Innomotion 2005*/


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

	this.addItem = addItem;
	this.build = build;
	this.buildPresentationMenu = buildPresentationMenu;
	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]);
		//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 DOMenuItem(topic,description,url,type){
	//menukohdan määrittely
	this.dateval = null;
	this.status = 'ondemand';
	this.topic = topic ? topic : 'no topic';
	this.description = description!='undefined' ? description : '';
	this.url = url ? url : "";
	this.type = type;
	this.number = DOnumber++;
	this.shows = new Array();
	this.addShow = addShow;
	this.setDateVal = setDateVal;
	this.setStatus = setStatus;
	DOLastItem = this;
}
function DOShow(topic,speaker,description,slides){
	this.topic = topic;
	this.description = description;
	this.speaker = speaker;
	this.slides = slides ? slides : 0;
	this.addSlideTimes = addSlideTimes;
	this.addSlideNumbers = addSlideTimes;
}
function addSlideTimes(){
}
function setDateVal(dateval){
	this.date = dateval;
}
function setCurrentItem(itemno,total){
	var i=1;
	for(i=0; i<total;i++){
	if(document.getElementById('ohjelma'+i)){
		if(i==itemno){
			document.getElementById('ohjelma'+i).bgColor='#FFFCE1';
			document.getElementById('ohjelma_linkki'+i).style.color='#333333';
			}
		else {
			document.getElementById('ohjelma'+i).bgColor='#ffffff';
			document.getElementById('ohjelma_linkki'+i).style.color='#666666';
			}
		}
	}//for
}
function buildPresentationMenu(area,current){
area--;
current--;
var currentItem = this.items[area];
var output='';
var k=1;
if(currentItem.shows[0]) {
		output+='<table id="maintable" width="100%" cellspacing="0" cellpadding="2">';
		var totalShows = currentItem.shows.length;
		for(j=0; currentItem.shows[j];j++){
			k = j+1;
			currentShow=currentItem.shows[j];
			output+='<tr onClick="setCurrentItem('+j+','+totalShows+'); parent.openPresentation('+(j+1)+'); return false;" style="cursor:pointer; cursor:hand">';
			if(j==current) output+='<td id="ohjelma'+j+'" bgcolor="#FFFCE1" style="color:#000000;" class="normal">';
			else output+='<td id="ohjelma'+j+'" class="normal" style="color:#666666">';
			output+='<img src="images/spacer.gif" width="10" height="40" align="left" vspace="0" hspace="0" border="0"><a id="ohjelma_linkki'+j+'" href="#" onClick="setCurrentItem('+j+','+totalShows+'); parent.openPresentation('+k+'); return false;"><strong>'+currentShow.topic+'</strong><br>'+currentShow.speaker+'</a></td></tr>';
		if(currentItem.shows[k]) 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 build(){
//rakentaa menun
target = document.getElementById('content');
var output ='';
for(i=this.items.length-1; i>=0;i--){
	currentItem = this.items[i];
	//alert(currentItem.topic);
output +='	<table width="828" border="0" cellpadding="0" cellspacing="0" title="Ohjelma">'+
'			  <tr>'+
'			<td height="20" align="left" valign="middle" class="header_dark">';
 if(currentItem.type=='html'){
	 				output+='<a href="';
					if(currentItem.url)	output+=currentItem.url+'?alue='+(i+1)+'&esitys=1';
					else{
						output+='player.';
						if(currentItem.status=='live') output+='php';
						else output+='html';
						output+='?alue='+(i+1)+'&esitys=1';
						}
					output+='" style="text-decoration:none">';
				}
output+='<b>'+currentItem.topic+'</b> &nbsp;';
if(currentItem.date) output +=' '+currentItem.date+' &nbsp;';
 if(currentItem.type=='html') output+='</a>';
 if(currentItem.status=='live') output+='&nbsp;<img align="absmiddle" src="images/live.gif" border="0" alt="Live-esitys"> <font color="green">LIVE</font>';
 if(expand==i) output+='<a class="normal" href="#" onClick="collapseItem(); return false;" style="text-decoration:none; font-weight:normal;"><img align="absmiddle" src="images/collapse.gif" border="0">Piilota ohjelma</a>';
 output+='	</td><td><img src="images/topnavi_colors.gif" align="right" border="0" alt=""></td>'+
			'  </tr>'+
'<tr><td colspan="2" background="images/dotline_fp_long.gif" style="background-repeat:repeat-x;" height="1"><img src="images/spacer.gif" alt="" border="0" height="1"></td></tr>'+			
		'	  <tr>'+

'				<td colspan="2" width="818" height="60" valign="top" align="left">'+
'					<table width="100%" cellpadding="4" cellspacing="2">';
if(currentItem.shows[0] && expand == i) {
		for(j=0; currentItem.shows[j];j++){
			currentShow=currentItem.shows[j];
			output+='  <tr><td><img src="images/topnavi_dot.gif" border="0" align="left" hspace="2" vspace="0"><a name="'+(j+1)+'"></a><strong>'+currentShow.topic+'</strong>';
			if(currentShow.speaker)output+=' - '+currentShow.speaker;
			output+=''+
'					  <br><i style="color:#333333;">'+currentShow.description+'</i></td>'+
'					  <td valign="middle" align="right" width="120"><a href="';
			if(currentItem.type=='media'){
					if(currentItem.url) output+=currentItem.url;
					else output+=mediaPolku+(i+i)+'/'+(j+1)+'.wmv';
				}
			else if(currentItem.type=='html'){
					if(currentItem.url)	output+=currentItem.url+'?alue='+(i+1)+'&esitys='+(j+1);
					else{
						output+='player.';
						if(currentItem.status=='live') output+='php';
						else output+='html';
						output+='?alue='+(i+1)+'&esitys='+(j+1);
					}
				}
			if(currentItem.status!='live')output+='" style="text-decoration:none">Avaa <img align="absmiddle" src="images/windowsmedia.gif" border="0"></a></td>'+
'					  <td width="20"><img src="images/spacer.gif" border="0" alt=""></td>'+
'					</tr>';
		if(currentItem.shows[j+1]) output+='<tr><td colspan="3" 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{
			if(currentItem.shows[0]){
				output+='  <tr><td colspan="2" valign="middle" align="left"><a href="#" onClick="expandItem('+i+');return false;" style="text-decoration:none"><img align="absmiddle" src="images/expand.gif" border="0">Näytä ohjelma</a></td>'+
'					  <td width="20"><img src="images/spacer.gif" border="0" alt=""></td></Tr>';
				}
			else {
				output+='  <tr><td><p><strong>'+currentItem.topic+'</strong></p>'+
'					  <p><i style="color:#333333;">'+currentItem.description+'</i></p></td>'+
'					  <td valign="middle" align="right"><a href="';
				if(currentItem.type=='media'){
					if(currentItem.url) output+=currentItem.url;
					else output+=mediaPolku+(i+i)+'/'+(j+1)+'.wmv';
					}
				else if(currentItem.type=='html'){
					if(currentItem.url)
						output+=currentItem.url+'?alue='+(i+1)+'&esitys=1';
					else{
							output+= 'player.';
							if(currentItem.status=='live') output+='php';
							else output+='html';
							output+='?alue='+(i+1)+'&esitys=1';
							}
					}	
				output+='" style="text-decoration:none">Avaa <img align="absmiddle" src="images/windowsmedia.gif" border="0"></a></td>'+
'					  <td width="20"><img src="images/spacer.gif" border="0" alt=""></td></Tr>';
				} 
		}
output+='					</table>'+
'				</td>'+
'			  </tr>'+
'			  <tr>'+

'				</tr><tr><td height="15">&nbsp;</td></tr>'+
'			  </table>';
			}
if(document.getElementById('content')) document.getElementById('content').innerHTML=output;
else {
	document.write(output);
	alert('error: content div was not found');
}
}
