// JavaScript Document
lcm_c_lists = [
	    {"client":3207,"console":1674327833, "target":"godology2"}
	]

	window.onload = function() {
		for(var i = 0; i < lcm_c_lists.length; i++) {
			window['lcm_c_func_'+i]=new Function("data","listvideos(data," + i + ");");
			_s = document.createElement("script");
			_s.src="http://customers.lightcastmedia.com/api/consoleListVideos?output=json&console="+lcm_c_lists[i].console+"&client="+lcm_c_lists[i].client + "&callback=lcm_c_func_"+i
			document.body.appendChild(_s);
		}
	}

	function listvideos(data,id) {
		if(data.response.code == 200) {
			d = data.response.data;
			target = lcm_c_lists[id].target
			lcm_c_lists[id].d = d

			for( var i = 0; i < d.length; i++) {
				var row = d[i];
				var tr = document.createElement('tr');
				if(i % 2 == 0) tr.className = 'odd';
				document.getElementById(target).tBodies[0].appendChild(tr);

				var td = document.createElement('td');
				var a = document.createElement('a');
				a.href="#";
				a.onclick = showaudio;
				a.id = "audeo_"+id+'_'+i;
				a.innerHTML = row.title;
				td.appendChild(a);
				tr.appendChild(td);


				var td = document.createElement('td');
				tr.appendChild(td);
				td.innerHTML = row.author;
				
				var mdate = row.description.match(/[0-9]{2}-[0-9]{2}-[0-9]{4}/);
				if(!mdate) {
					mdate = row.updated.substring(0,10)
					var datesplit = mdate.split('-');
					mdate = datesplit[1] + '-' + datesplit[2] + '-' + datesplit[0];
				}
				var td = document.createElement('td');
				tr.appendChild(td);
				td.innerHTML = mdate

				d[i].description = row.description.replace(/\s*[0-9]{2}-[0-9]{2}-[0-9]{4}/,"")
				d[i].description = row.description.replace(/\s*http.*\.mp3/,"")
			}
		}
		else {
			alert("ERROR LOADING DATA");
		}
	}

function showvideo(e) {
        var fields = this.id.split("_", 3)
        document.getElementById('videoholder').innerHTML = lcm_c_lists[fields[1]].d[fields[2]].embed.code;
        document.getElementById('mediatext').innerHTML = "<strong>"+lcm_c_lists[fields[1]].d[fields[2]].title+"    </strong><br />"+lcm_c_lists[fields[1]].d[fields[2]].description;
    }

	function showaudio(e) {
        var fields = this.id.split("_", 3)
        var emlocation = lcm_c_lists[fields[1]].d[fields[2]].embed.location;

        var embcode = "<object width=\"536\" height=\"20\" ><param name=\"movie\" value=\"" + emlocation + "\"><\/param><param name=\"allowFullScreen\" value=\"true\"><\/param><param name=\"Flashvars\" value=\"autoStart=1&audio_only=1\"><\/param><embed src=\"" + emlocation + "\" type=\"application\/x-shockwave-flash\" allowFullScreen=\"true\"  width=\"536\" height=\"20\"  FlashVars=\"autoStart=1&audio_only=1\" ><\/embed><\/object>"
        document.getElementById('videoholder').innerHTML = embcode;
        document.getElementById('mediatext').innerHTML = "<strong>"+lcm_c_lists[fields[1]].d[fields[2]].title+"</strong><br />"+lcm_c_lists[fields[1]].d[fields[2]].description;

    }
