﻿// extend the collapse menu class to support listen functionality
var podcastMenu = function(el){
	this._init(el);
}
System.extend(podcastMenu,Gui.CollapseMenu,{
	onSelect:function(id, link){
		var a = $(id);
		
		var aInfo = {lesson:'',title:'',file:''}
		var inputTags = a.getElementsByTagName('input');
		for(var i=0,l=inputTags.length;i<l;i++){
			aInfo[inputTags[i].name] = inputTags[i].value;
		}
		
		var now = $('now_playing');
		var nowInfo = {lesson:'',title:'',file:''}
		var inputTags = now.getElementsByTagName('input');
		for(var i=0,l=inputTags.length;i<l;i++){
			nowInfo[inputTags[i].name] = inputTags[i].value;
		}
		
		var not = $('not_playing');
		var notInfo = {lesson:'',title:'',file:''}
		var inputTags = not.getElementsByTagName('input');
		for(var i=0,l=inputTags.length;i<l;i++){
			notInfo[inputTags[i].name] = inputTags[i].value;
		}		
		
		$('download_div').href = aInfo.file;
		$('download').innerHTML = aInfo.lesson;
				
		if (aInfo.lesson != nowInfo.lesson) {
			var sb = [];
			sb[sb.length] = '<strong>'+aInfo.lesson +'</strong><br/>';
			sb[sb.length] = aInfo.title;
			sb[sb.length] = '<input type="hidden" name="lesson" value="'+aInfo.lesson+'"/>';
			sb[sb.length] = '<input type="hidden" name="file" value="'+aInfo.file+'"/>';
		
			not.innerHTML = sb.join('');
			
			$('not_playing_div').style.display = 'block';
		}else{
			$('not_playing_div').style.display = 'none';
		}
		
		var lf = $("lesson_frame");
		if(lf){
			lf.src = link;
		}
		
		return false;
	}
});

function play(){
	var not = $('not_playing');
	$('not_playing_div').style.display = 'none';
	var notInfo = {lesson:'',title:'',file:''}
	var inputTags = not.getElementsByTagName('input');
	for(var i=0,l=inputTags.length;i<l;i++){
		notInfo[inputTags[i].name] = inputTags[i].value;
	}

	var now = $('now_playing');		
	now.innerHTML = not.innerHTML;
	
	var refObj = $("ECCaudio");
	var refEmb = $("ECCaudio2");
		
	if(refObj && typeof refObj.loadFile == 'function')
		refObj.loadFile(notInfo.file);
	
	if(refEmb && typeof refEmb.loadFile == 'function')
		refEmb.loadFile(notInfo.file);
	
}
function init_other(){
	Gui.addControl(new podcastMenu('pocast_list'));
}