﻿// JavaScript Document
// Custom
var _imgHost = "http:\/\/fs.dmmotion.com\/10134\/img\/";
//var _imgHost = "img\/";
// Interface congif
var ENDmVideos, ENDgoTV;

function onPlayerInit(PyIndex) {
	// Inicializacion
	var player = admtv.Players[PyIndex];
	player.onContentChange = function () {
		var oEl = document.getElementById("ELHplList"+this.Id);
		if (oEl.innerHTML=="") oEl.innerHTML = ENDtv.gp(this.Index);
	}
	ENDmVideos = function (id) {
		ENDtv.sp(admtv.getPlayerById(id).Index, true);
	};
	ENDgoTV = function (id) {
		ENDtv.lk(id);
	};
	var vm = document.getElementById("ELHvm"+player.Id);
	vm.onclick = function () {
		ENDtv.lk(player.Id);
	};
	vm.style.cursor = "pointer";
	vm.onmouseover = function () {
		vm.style.textDecoration = "underline";
	}
	vm.onmouseout = function () {
		vm.style.textDecoration = "none";
	}
}

var ENDtv = {
	lk : function (PyId) {
		location.href = admtv.getPlayerById(PyId).generatePermalink();
	},
	pv : function (PyIndex, va) {
		this.sp(PyIndex, false);
		admtv.Players[PyIndex].playVideo({ChannelId:va[0], PlaylistId:va[1] , Id:va[2]});
		
	},
	ss : function (PyIndex) {
		var player = admtv.Players[PyIndex];
		var pEl = document.getElementById("ELHplaylist"+player.Id);
		pEl.style.width = player.width+"px";
		pEl.style.height = player.height+"px";
		document.getElementById("ELHplTitle"+player.Id).style.height = "22px";
		document.getElementById("ELHplList"+player.Id).style.height = (player.height-27)+"px";
		document.getElementById("ELHplClose"+player.Id).onclick = function () {
			ENDtv.sp(PyIndex, false);
		}
		setTimeout("admtv.Players["+PyIndex+"].pause(true);", 300);
		return false;
	},
	sp : function(PyIndex, flag) {
		var player = admtv.Players[PyIndex];
		var pEl = document.getElementById(player.div_id);
		pEl.style.textAlign = "left";
		pEl.style.width = ((flag) ? "0" : player.width) + "px";
		pEl.style.height = ((flag) ? "0" : player.height) + "px";
		pEl.style.textIndent = ((flag) ? "-9000" : "0") + "px";
		document.getElementById("ELHplaylist"+player.Id).style.display = (flag) ? "block" : "none";
		if (flag) this.ss(PyIndex);
	}, 
	gp : function(PyIndex) {
		var player = admtv.Players[PyIndex];
		var actual = player.getCurrentItemInfo();
		var playlist = player.getPlaylistById(actual[0], actual[1]);
		var u = "";
		var it = playlist.Items.length;
		for (var i=0; i<it; i++) {
			u += '<table border="0" cellpadding="0" cellspacing="0" class="ENDtbIte" onclick="ENDtv.pv('+PyIndex+', ['+actual[0]+', '+actual[1]+', '+playlist.Items[i].Id+'])">';
			u += '<tr>';
				u += '<td><table border="0" cellpadding="0" cellspacing="0"><tr>';
					u += '<td><img class="ENDthumb" src="'+admtv.getThumbnailURL(player.Content.Id, playlist.Items[i], "s")+'" \/><\/td>';
					u += '<td id="texto">'+playlist.Items[i].Title+' <span id="textoHora"><img src="'+_imgHost+'hm_tmr.gif" width="9" height="9" \/>&nbsp;'+formatTime(playlist.Items[i].Assets[0].Length/1000)+'<\/span><\/td>';
				u += '<\/tr><\/table><\/td>';
			u += '<\/tr>';
			u += '<\/table>';
		}
		return u;
	}
}
function formatTime(t) {
	var m = Math.floor(t/60);
	var s = Math.floor(t%60);
	if (s<10) s = ("0"+s);
	if (m<10) m = ("0"+m);
	return m+":"+s;
}