//Tabs function********************
var current_tab = 1;
function showBillbroad(what){
            var front_obj, back_obj;
            back_obj = document.getElementById('billbroad-layer-' + current_tab);
            front_obj = document.getElementById('billbroad-layer-' + what);
            document.getElementById('billbroad-layer-' + current_tab).style.display = "none";
			document.getElementById('tab-' + current_tab).borderStyle="none";
         //   document.getElementById('express-tab-' + current_tab).style.background = "url(http://www.tdm.com.mo/c_images/table/menu_s.jpg)";
			//document.getElementById('tab-' + current_tab).style.borderBottomWidth="1 px"; 
			//document.getElementById('tab-' + current_tab).style.color="#696969";
			
            current_tab = what;
            document.getElementById('billbroad-layer-' + current_tab).style.display = "block";
           // document.getElementById('express-tab-' + current_tab).style.background = "url(http://www.tdm.com.mo/c_images/table/menu_s2.jpg)";
			//document.getElementById('tab-' + current_tab).style.borderBottomWidth="0 px";
			// document.getElementById('tab-' + current_tab).style.color="#da6633";
}



           



//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="246">'; 	

	for (i=0; i<tagArr.length; i++) {
 		txt+='<tr><td><table width="246" onclick="play(' + i + ', true)" ';
 		txt+='class="playlistlo" onmouseover="this.className = \'playlisthi\';" onmouseout="this.className = \'playlistlo\';">';
		txt+='<tr>' + asCell(asImage(tagArr[i][4], "90", "50", "1", "Click to Play"));
		txt+='<td width="156" valign=top>';
		txt+= tagArr[i][1] + '<br>';
		//txt+='?e’A: ' + tagArr[i][5] + '<br>';
		//txt+='&nbsp;' + asLink(tagArr[i][3], "_blank", "more info");
		txt+='</td></tr></table></td></tr>';
	}
	txt+='</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("playerdate").innerHTML= tagArr[idx][5];
}


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:'300',
		width:'440'
	};
	
	
	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';
	//importXML('http://www.tdm.com.mo/c_news/news/player/playlist.xml'); 
	
	
}


//rolling function*****************
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 == "prognow") 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(20)", 3000);
       }
	   
function autoProg(what){
	  scroll_UD('prognow',what);
      timer = setTimeout("autoProg(20)", 5000);
      }
function manualrunEPG(what){
	  clearTimeout(timer);
       scroll_UD('prognow',what);
       timer = setTimeout("autoProg(20)", 5000);
      }



//start all function on window load
function start(){
	//player
	//init();
	//tabs
	showBillbroad(1);
	//showProgTab(1);
	//rolling 
	YAHOO.util.Event.addListener(window, "load", autoProg);
}

