//version 1657

var timerTM = null;
var chlsLatestVdos = new Array();

var latestVdoTM_tpl = '<div class="vdo_menu_channel_thumbnail"><a href="$href_link$"><img src="$thumb_img$" border ="0" id="slidemenu_$pid$_1"/></a><a class="ico_play" href="$href_link$"><img src="images/icon_play_off.gif" border=0 /></a><span>$duration$</span>$playlst_icon$</div><div class="vdo_menu_channel_vdo_title"><a href="$href_link$">$title$</a></div>';


function moverTopMenu(chid){
	mouseInTM = true;
	dojo.byId("topmenuobj").style.display = "";
	var oId, aId = '';
	var o = dojo.query('#topmenuobj div.slidemenu_container_lower');
	for(var i=0; i<o.length; i++){
		oId = o[ i ].id;
		aId = oId.replace("_catlst_", "_latest_");
		
		o[ i ].style.display = (oId==("slidemenu_catlst_"+chid)) ? "" : "none";
		if( dojo.byId(aId) )
			dojo.byId(aId).style.display = (oId==("slidemenu_catlst_"+chid)) ? "" : "none";
	}
	buildLatestVDOsTopMenu(chid);
	//dojo.byId("t1").innerHTML = "最新影片 " + chid;
}


function moutTopMenu(){
	mouseInTM = false;
	timerTM = setTimeout("hideTopMenu();", 500);
}


function hideTopMenu(){
	clearTimeout(timerTM);
	if(!mouseInTM)
		dojo.byId("topmenuobj").style.display = "none";
}


function inOutTopMenu(onOff){
	mouseInTM = onOff;
	setTimeout("hideTopMenu();", 500);
}


function channelLatestVDOsTopMenu(){
	var kw = {
		url: "index.php?fuseaction=Ajax.VDOMenu&list=channel&" +Math.random(),
		handleAs:"json",
		sync : true,
		timeout:60000, // 1 mins
		load: function (response, ioArgs) {
			for(var chl in response)
				chlsLatestVdos[ response[ chl ].channel_id.toString() ] = response[ chl ].program;
		},
		error: function (response, ioArgs) {
			//alert(response.message);
		}
	}
	dojo.xhrGet(kw);
}


function buildLatestVDOsTopMenu(chid, noNeedGetData){
	noNeedGetData = typeof(noNeedGetData) == "undefined" ? true : noNeedGetData;
	if( typeof(chlsLatestVdos[ chid ]) == "undefined" || !noNeedGetData )
		channelLatestVDOsTopMenu();
	
	var rH = '';
	var tooltip_queue = new Array();
	
	for( var itm=0;itm<chlsLatestVdos[ chid ].length;itm++){
		var data				= chlsLatestVdos[ chid ][ itm ];
		var addPlayLstImgHTML	= addPlayListImg(data.program_id);
		tooltip_queue[ '_' + data.program_id ] = videotooltips_text(data.fulldesc);
		
		rH += '<div class="slidemenu_thumbnail_container" id="slidemenu_' + data.program_id + '">';
		rH += latestVdoTM_tpl.replace(/\$thumb_img\$/gi,	data.img)
							.replace(/\$pid\$/gi,			data.program_id)
							.replace(/\$href_link\$/gi,		"index.php?fuseaction=Features.Archive&channel_id=" + data.channel_id + "&program_id=" + data.program_id)
							.replace(/\$duration\$/gi,		data.duration)
							.replace(/\$title\$/gi,			data.title)
							.replace(/\$playlst_icon\$/gi,	addPlayLstImgHTML);
		rH += "</div>\n";
	}
	
	dojo.byId("slidemenu_latest_" + chid).innerHTML = rH;

	for(var idx in tooltip_queue){
		tooltips('slidemenu'+ idx + '_1', tooltip_queue[ idx ]);
		//tooltips('btn_add2pl_'+prog[ v ].program_id,'加入我的清單');
	}
}
