﻿//Player functiion*************
function xmlDocReady() {	
	storeTags();
	showTags();
	play(0, false);
}

function storeTags() { //asx playlist

	getListOf("entry");

	for (i=0; i<tagList.length; i++) { 
		clearRow();
		addToRow(getAttr(i, "ref", "href"));
		addToRow(getTag(i, "title"));
		addToRow(getTag(i, "author"));
		addToRow(getAttr(i, "moreinfo", "href"));
		addToRow(getValueByAttrVal(i, "param", "name", "image", "value"));
        addToRow(getTag(i, "date"));
		addRowToArr();
	} 
}


function showTags() { //alert('first cell:' + tagArr[0][0] );
	var txt='<table border="0" cellpadding="0" cellspacing="0" width="980"><tr>'; 	

	for (i=0; i<tagArr.length; i++) {
 		txt+='<td valign="middle" width="100" height="100"><table  border="0" cellpadding="0" cellspacing="1" width="100" onclick="play(' + i + ', true)" ';
 		txt+='class="playlistlo" onmouseover="this.className = \'playlisthi\';" onmouseout="this.className = \'playlistlo\';">';
		txt+='<tr valign="middle" height="70">' + asCell(asImage(tagArr[i][4], "150", "60", "1", "Click to Play"))+'</tr>';
		//txt+='<td width="150" valign="top"></td></tr>';
		txt+='<tr><td width="150" height="50" valign="top" align="left">' + tagArr[i][1] +'</td></tr>';
		//txt+='&nbsp;by: ' + tagArr[i][2] + '<br>';
		//txt+='&nbsp;' + asLink(tagArr[i][3], "_blank", "more info");
		txt+='</table></td>';
	}
	txt+='</tr></table>';
	document.getElementById("writeroot").innerHTML=txt;	
}


function play(idx, go) { 
	if (go) { createPlayer(tagArr[idx][0], tagArr[idx][4], 'true'); } 
	else { createPlayer(tagArr[idx][0], tagArr[idx][4], 'false'); }	
	 document.getElementById("playerhandle").innerHTML= tagArr[idx][1];
     document.getElementById("listhandle").innerHTML= tagArr[idx][1]+"("+tagArr[idx][5].substring(0,10)+")";
}


function createPlayer(theFile, theImg, go) {
	var cnt = document.getElementById("container");
	var src = 'http://www.tdm.com.mo/global/player/wmvplayer.xaml';
	var cfg = {
		file: theFile,
		image: theImg,
		autostart: go,
		overstretch: 'true',
		height:'350',
		width:'480'
	};
	
	
	var ply = new jeroenwijering.Player(cnt,src,cfg);	
}


function init() {
	Drag.init(document.getElementById("playerhandle"), document.getElementById("playerroot"));	
	Drag.init(document.getElementById("listhandle"), document.getElementById("listroot"));
	document.getElementById("playerhandle").style.cursor = 'move';
	document.getElementById("listhandle").style.cursor = 'move';
	//show_date=document.getElementById("date")).value;	
   // importXML('http://www.tdm.com.mo/c_news/news.xml');
}

	


//rolling function*****************
function scroll_LR(id,amount) {
   var element = document.getElementById(id);
 amount = amount+parseInt(element.scrollLeft);
  var myAnim = new YAHOO.util.Scroll(element, {scroll: { to: [amount, 0] }}, 0.5, YAHOO.util.Easing.easeOut);
  myAnim.animate();
}

function scroll_UD(id,amount) {
      var element = document.getElementById(id);
     amount = amount+parseInt(element.scrollTop);
    var myAnim = new YAHOO.util.Scroll(element, {scroll: { to: [0, amount] }}, 0.5, YAHOO.util.Easing.easeOut);
    if (id == "newspgm") myAnim.onComplete.subscribe(backToTop);
     myAnim.animate();
function backToTop()
  {
    var temp;
    temp = parseInt(element.scrollHeight - 1) / 2;
    if (document.all) temp = parseInt(element.scrollHeight) / 2;
    if (element.scrollTop >= temp)
      element.scrollTop = 0;
   }
}
 
timer = null;
function initEPG(){
	   timer = setTimeout("autoProg(18)", 3000);
       }
	   
function autoProg(what){
	  scroll_UD('newspgm',what);
      timer = setTimeout("autoProg(18)", 5000);
      }
function manualrunEPG(what){
	  clearTimeout(timer);
       scroll_UD('newspgm',what);
       timer = setTimeout("autoProg(18)", 5000);
      }




