﻿/**
* @author Ismael
*/
function aleatorio(inferior,superior){
numPosibilidades = superior - inferior
aleat = Math.random() * numPosibilidades
aleat = Math.round(aleat)
return parseInt(inferior) + aleat
} 
function copy(o) { 
if (typeof o != "object" || o === null) return o;
var r = o.constructor == Array ? [] : {};
for (var i in o) {
	r[i] = copy(o[i]);
}
return r;
}
function GetFormatHour(time) {
var xString = "";
xString += time.getHours().toString().length < 2 ? "0" + time.getHours().toString() : time.getHours().toString();
xString += ":";
xString += time.getMinutes().toString().length < 2 ? "0" + time.getMinutes().toString() : time.getMinutes().toString();
xString += ":";
xString += time.getSeconds().toString().length < 2 ? "0" + time.getSeconds().toString() : time.getSeconds().toString();
return xString;
}
var __now = null;
function Now() {
if (__now == null) {
	var strTime = Data.LoadFile('gettime.php');
	__now = parseFloat(strTime);
	setInterval(Tick,1000);
}
return new Date(__now);
}
function Tick() {
__now = __now + 1000;
}
function SetTime(divTime) {
var xDiv = getElement(divTime);
xDiv.innerHTML = getDate();
}
function CreatePlayer(player,video) {
var f = player.flashvars, p = player.params, a = player.attributes;
$('#'+Config.Player.player1.container).html('');
//swfobject.embedSWF(Config.Player.path, p.id, a.width, a.height, Config.Player.flashVersion, false, flashvars, params, attributes);
var config_flowplayer = { 
    clip: { 
		url: f.file,
        //url: 'http://82.165.129.12/~rtvc/mp4/test2.mp4',
		provider:'pseudo',
		autoPlay: true,
		live: true,
        onBegin: function() { 
            this.getControls().fadeIn(5000); 
			setTimeout(function() {
				$f(Config.Player.player1.container).getPlugin("myContent").fadeOut(1500); 
			}, 5000);
			if (f.controlbar=="none") {
				$f().unmute;
				$f().setVolume(eval(f.volume));
			};
        },
	onLastSecond: function() {
	},
	onStart: function(metadata) {
	    var flow = $f();
	    var seconds = 2;
	    flow.onCuepoint(metadata.duration*1000-seconds*1000,function() {
		setTimeout(function(){
		    if (($f().getTime()+seconds)>=$f().getClip().duration){
			I.Next(p.id);
			return false;
		    }
		},seconds*1000);
	    });
	}
    },
	contextMenu: [ 
        {'EmiraTV Player 1.5': function() { 
            location.href = 'http://www.emira.tv';     
        }} 
    ],
	key: Config.Player.keyFlowplayer,
    plugins: {
	controls: {
		play: f.controlbar != "none",
		scrubber: f.controlbar != "none"
	},
        pseudo: {
            url: 'flowplayer.pseudostreaming-3.1.2.swf'
        },
        influxis: { 
            url: 'flowplayer.rtmp-3.1.0.swf', 
            netConnectionUrl: f.streamer
		},
		myContent: {
			url: 'flowplayer.content-3.1.0.swf',
			borderRadius: 10,
			//backgroundImage: 'url(pattern.png)',
			//stylesheet: 'content-plugin.css',
			style: {
				'.title': {
					fontSize: 12,
					fontFamily: 'verdana,arial,helvetica',
					width: '100%',
					margin: '5px'
				},
				'.video': {
					fontSize: 16,
					fontWeight: 'bold'
				}
			},
			closeButton:true,
			botton:10,
			height:60,
			opacity:0.97,
			html: '<p class="title">Está usted viendo:<br/><span class="video">' + replace(video.name,"'","\u0022") + ': ' + replace(video.caption,"'","\u0022") + '</span></p>',
			onClick: function() {
				this.hide();
			}
		} 
    }
};
if (f.start && f.file!=Config.Player.live) {
	config_flowplayer.clip.start = f.start;
}
var flow = flowplayer(Config.Player.player1.container, p, config_flowplayer);

}
//*****************************************************************************************
// @FunciÃ³n: dayWeek(day,month,year)
// @Author: Ismael
// @Fecha: 14/07/2008
// @DescripciÃ³n: Determina el dÃ­a de la semana segÃºn el sistema universal
// (0=Lunes, 1=Martes, 2=MiÃ©rcoles, 3=Jueves, 4=Viernes, 5=Sabado, 6=Domingo)
//*****************************************************************************************
function getDate() {
var arrDay = new Array("Domingo", "Lunes", "Martes", "Mi&eacute;rcoles", "Jueves", "Viernes", "S&aacute;bado");
var arrMonth = new Array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
var objDate = Now();
var intYear = objDate.getYear();
if (intYear < 1000) {
	intYear += 1900;
}
var intDay = objDate.getDay();
var intMonth = objDate.getMonth();
var intDayMonth = objDate.getDate();
if (intDayMonth < 10) {
	intDayMonth = "0" + intDayMonth;
}
var strCurrerntDate = arrDay[intDay] + ", " + intDayMonth + " de " + arrMonth[intMonth]  + " de " + intYear;
return strCurrerntDate;
}

// Funciones auxiliares
function getNumeroVisitas() {
var xVisitas;

xVisitas = leerCookie("numVisto");
if (xVisitas == null || !isNumeric(xVisitas)) {

	xVisitas = 0;
}

return xVisitas;
}
function RegistrarVisita() {
var xVisitas = getNumeroVisitas();
xVisitas++;
document.cookie="numVisto=" + xVisitas.toString();
}
function showError(error) {
var flvplayer = $('#'+Config.Player.player1.container);
flvplayer.html("");
if (!isNull(flvplayer))
	getElement(Config.HTML.CONTENEDOR).removeChild(flvplayer);

var div = document.createElement('DIV');
div.id = Config.Player.player1.attributes.id;
div.className = "pequeno";
div.style.visibility = 'visible';

var h3 = document.createElement('H4');
h3.innerHTML = 'Para poder ver la televisi&oacute;n por internet correctamente, por favor inst&aacute;lese la &uacute;ltima versi&oacute;n de flash haciendo click en la imagen de abajo. Al terminar, pulse F5 o cierre y vuelva a entrar a nuestra web.<br />Gracias';

var pImage = document.createElement('P');
pImage.setAttribute('class','image');
pImage.innerHTML = '<a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Descargar Adobe Flash player" /></a>';

var pLink = document.createElement('P');
pLink.setAttribute('class','link');
pLink.innerHTML = 'Si ya tiene la &uacute;ltima versi&oacute;n de flash instalado pero sigue tiene alguna dificultad env&iacute;enos un email a <a href="mailto:soporte@emira.tv">soporte@emira.tv</a>';

var pError = document.createElement('P');
pError.className = 'error';
pError.innerHTML = 'Descripcion del error: ' + error;

div.appendChild(h3); div.appendChild(pImage); div.appendChild(pLink); div.appendChild(pError);
getElement(Config.Player.player1.container).innerHTML = "";
getElement(Config.Player.player1.container).appendChild(div);

throw new Error(error);
}
function isNull(object) {
if (object == undefined) return true;
if (object == null) return true;
return false;
}
function isUrl(url) {
if (url == null) return false;
if (url.substring(1,8) == "http://" || url.substring(1,5) =="www." || url.substring(0,7) == "http://" || url.substring(0,4) =="www.") return true;
else return false;
}
function leerCookie(nombre) {
a = document.cookie.substring(document.cookie.indexOf(nombre + '=') + nombre.length + 1,document.cookie.length);
if(a.indexOf(';') != -1)a = a.substring(0,a.indexOf(';'))
return a;
}
function replace(texto,s1,s2){
return texto.split(s1).join(s2);
}
function getElement(ElementId) {
if (isNull(ElementId)) throw new Error("Identificador del elemento nulo.");
if (isEmptyString(ElementId)) throw new Error("El identificador del elemento es una cadena vacÃ­a.");

var xElement = $('#'+ElementId)[0];

if (isNull(xElement)) throw new Error("No existe ning\u00FAn elemento con el ID: " + ElementId.toString() + ".");

return xElement;
}
function getChildElementsByTagName(element, tagName) {
if (isNull(element)) return null;
if (isNull(tagName)) throw new Error('Tag a buscar no v\u00E1lido.');
if (isEmptyString(tagName)) throw new Error('Tag a buscar no v\u00E1lido');

var xListNodes = new Array();
for (var i = 0; i < element.childNodes.length; i++) {
	if (element.childNodes[i].nodeType == 3)
		continue;
	if (element.childNodes[i].nodeName.toUpperCase() == tagName.toUpperCase()) {
		xListNodes.push(element.childNodes[i]);
	}
}

return xListNodes;
}
function isNumeric(numero){
if (/^([0-9])*$/.test(numero)) return true;
else return false;
}
function isEmptyString(string) {
if (typeof string == "string") {
	if (string == "") return true;
}
return false;
}
function isElement(element) {
if (element == undefined) return false;
if (element == null) return false;
if (element.nodeType == 1 || element.nodeType == 8) {
	return true;
} else {
	return false;
}
}
function hideElement(id) {
var xElement = $('#'+id)[0];
if (!isNull(xElement)) {
	xElement.style.display = "none";
}
}
function ValidarEmail(valor) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)) {
	return true;
} else {
	return false;
}
}

function openPopup(url,title,width,height,scrolls) {
	var str = "";
	if (!isNaN(width)) {str += ("width=" + width + ",")};
	if (!isNaN(height)) {str += ("height=" + height + ",")};
	if (scrolls===true) {str += ("scrollbars=YES")} else if (scrolls===false){str += ("scrollbars=NO")};
	window.open(url,title,str) ;
}

var __PLAYER1,__PLAYING_I, __PLAYING_LIST, __PLAYING_CACHEANIMATION, __TIMEOUT = 0, __PLAYERRESET = false;
function get__PLAYING_I() {
return __PLAYING_I;
}
function set__PLAYING_I(newValue) { 
__PLAYING_I = newValue;
}
function playing(video,player,start) {
if (isNull(video)) {

	__PLAYING_I++;
	if (!isNull(__PLAYING_LIST)) {
		if (__PLAYING_I > __PLAYING_LIST.length) {
			I.Next(Config.Player.player1.attributes.id);
			return;
		}
	}

	var xPublicidad = __PLAYING_LIST[__PLAYING_I - 1];
	if (isNull(xPublicidad.Item)) {
		__TIMEOUT = 0;
		__PLAYERRESET = false;
		var xPlayer = copy(player);
		xPlayer.flashvars.file = xPublicidad.file;
		xPlayer.flashvars.streamer = xPublicidad.streamer;
		xPlayer.flashvars.start = start;
		CreatePlayer(xPlayer,xPublicidad);
	}
	else {
		if (!isNull(xPublicidad.Item.composition)) {
			// Publicidad
			if (xPublicidad.Item.composition.length == 0) {
				playing(null,player,start);
				return;
			}

			var xLink = xPublicidad.Item.link;
			var xOwner = xPublicidad.Owner;
			var xHasFilm = false;
			for (var i = 0; i < xPublicidad.Item.composition.length; i++) {
				var xPublicidadItem = xPublicidad.Item.composition[i];
				if (!isNull(xPublicidadItem.film)) {
					// Film
					var xPlayer;

					xPlayer = getPlayer(xPublicidadItem.player);
					if (isNull(xPlayer))
						showError('No se puede mostrar el video. El player no ha sido creado.');

					xPlayer.sendEvent("LOAD", {
						file: xPublicidadItem.film.file,
						type: "commercial"
					});
					getElement(Config.HTML.PUBLICIDAD_INFO).style.display = "block";
					xHasFilm = true;
					
				}
				else {
					if (!isNull(xPublicidadItem.frames)) {
						// Animacion
						if (xPublicidadItem.frames.length == 0)
							continue;

						__PLAYING_CACHEANIMATION = new Core.Motion(xPublicidadItem, xLink, xOwner, "I.PlayerMain");
						__PLAYING_CACHEANIMATION.Play();
					}
					else {
						if (!isNull(xPublicidadItem.image)) {
							// Imagen
							var xDiv = document.createElement('div');
							xDiv.setAttribute('id', Config.HTML.PUBLICIDAD_IMAGE + '_' + xOwner);
							xDiv.style.left = isNull(xPublicidadItem.position.x) ? '' : (xPublicidadItem.position.x + 'px');
							xDiv.style.top = isNull(xPublicidadItem.position.y) ? '' : (xPublicidadItem.position.y + 'px');
							xDiv.style.width = isNull(xPublicidadItem.size.width) ? '' : (xPublicidadItem.size.width + 'px');
							xDiv.style.height = isNull(xPublicidadItem.size.height) ? '' : (xPublicidadItem.size.height + 'px');
							xDiv.style.display = 'block';
							xDiv.style.position = 'absolute';

							var xImg = document.createElement('IMG');
							xImg.cssName = xPublicidadItem.css;
							xImg.setAttribute('border', '0');
							xImg.src = xPublicidadItem.image;

							var xA = document.createElement('A');
							xA.setAttribute('href', xLink);
							xA.setAttribute('target', '_blank');

							xA.appendChild(xImg);
							xDiv.appendChild(xA);
							getElement(Config.HTML.CONTENEDOR).appendChild(xDiv);

							if (xPublicidadItem.duration > -1)
								setTimeout("hideElement('" + xDiv.id.toString() + "');", xPublicidadItem.duration * 1000);
						}
						else {
							if (!isNull(xPublicidadItem.text)) {
								// Texto
								var xDiv = document.createElement('div');
								xDiv.setAttribute('id', Config.HTML.PUBLICIDAD_TEXT);
								if (!isNull(xPublicidadItem.position.x)) xDiv.style.left = xPublicidadItem.position.x;
								if (!isNull(xPublicidadItem.position.y)) xDiv.style.top = xPublicidadItem.position.y;
								if (!isNull(xPublicidadItem.size.widt)) xDiv.style.width = xPublicidadItem.size.width + 'px';
								if (!isNull(xPublicidadItem.size.height)) xDiv.style.height = xPublicidadItem.size.height + 'px';
								if (!isNull(xPublicidadItem.color)) xDiv.style.color = xPublicidadItem.color;
								xDiv.style.display = 'block';
								xDiv.style.position = 'absolute';
								xDiv.className = xPublicidadItem.css.toString();

								if (isNull(xLink) || xLink == "") {
									xDiv.innerHTML = xPublicidadItem.text;
								} else {
									var xA = document.createElement('A');
									xA.setAttribute('href', xLink);
									if (xLink.substring(0, 11) == "javascript:") {
										xA.setAttribute('target','_self');
									}
									else {
										xA.setAttribute('target', '_blank');
									}
									xA.innerHTML = xPublicidadItem.text

									xDiv.appendChild(xA);
								}
								getElement(Config.HTML.CONTENEDOR).appendChild(xDiv);

								if (xPublicidadItem.duration != "" && xPublicidadItem.duration > -1) {
									setTimeout("hideElement('" + xDiv.id.toString() + "');", xPublicidadItem.duration * 1000);
								}
							}
						}
					}
				}
			}
			if (!xHasFilm) {
				playing(null,player,start);
				return;
			}
		} else {
			// Unknown
			playing(null,player,start);
			return;
		}
	}
}
else {
	var xPublicidad;

	__PLAYING_LIST = new Array(0);
	__PLAYING_I = 0;

	if (Config.Player.publicityEnabled == true) {
		if (video.publicitystart != null && video.publicitystart.length > 0) {
			for (var i = 0; i < video.publicitystart.length; i++) {
				var xPublicidadItem = typeof video.publicitystart[i] == "object" ? video.publicitystart[i].Text : video.publicitystart[i];
				xPublicidadItem = I.Publicidad.FindById(xPublicidadItem);
				if (isNull(xPublicidadItem)) {
					throw new Error('Spot publicitario ' + video.publicitystart[i].Text + ' no encontrado.');
				} else {
					__PLAYING_LIST.push({
						Item: xPublicidadItem,
						Owner: video.publicitystart[i].Owner
					});
				}
			}
		}
	}
	__PLAYING_LIST.push(video);
	if (Config.Player.publicityEnabled == true) {
		if (video.publicityend != null && video.publicityend.length > 0) {
			for (var i = 0; i < video.publicityend.length; i++) {
				var xPublicidadItem = typeof video.publicityend[i] == "object" ? video.publicityend[i].Text : video.publicityend[i];
				xPublicidadItem = I.Publicidad.FindById(xPublicidadItem);
				if (isNull(xPublicidadItem)) {
					throw new Error('Spot publicitario ' + video.publicityend[i].Text + ' no encontrado.');
				} else {
					__PLAYING_LIST.push({
						Item: xPublicidadItem,
						Owner: video.publicityend[i].Owner
					});
				}
			}
		};
	}
	playing(null,player,start);
	return;
}
};
function clipFloat(num,dec){ 
var t=num+"";
num = parseFloat(t.substring(0,(t.indexOf(".")+dec+1)));
return (num)
}

var currentPosition = 0;
function objectToString(object) {
var xString = '{';
for (var i in object) {
	if (xString != '{') xString += ',\n';
	xString += (i + ":'" + object[i] + "'");
}
xString += '}';
return xString;
}
function stringToObject(string) {
var xObject = eval(string);
return xObject;
}
function secs2hms(secs) {
var iHours = Math.floor(secs/3600);
var iMinutes = Math.floor((secs/60) - (iHours*60));
var iSeconds = Math.floor(secs % 60);

if (iSeconds == 60) {
	iMinutes++; iSeconds = 0;
}
if (iMinutes == 60) {
	iHours++; iMinutes = 0;
}

return(iHours+':'+iMinutes+':'+iSeconds);
}
var __time = null;
var __iCreatingPlayerMain = 0; __iCreatingPlayerAux = 0; __doResizer=true;
function Main() {
	SetTime("cabecera_fecha");
	RegistrarVisita();

	preConfigPlayer();
	I = new View.WebPlayer();
	configPlayer();
	I.Start(true,__doResizer);
}
var Data = {
Cache: {
	XPathCommand: {}
},
// Functions
LoadFile: function(filePath,asXML,fnAjax){


	if (typeof fnAjax == "string" || typeof fnAjax == "function") {
		// Llamada asÃ­ncrona
		if (typeof fnAjax == "string") {
			$.get(filePath,null,function(data){
				eval(fnAjax);
			});
		} else {
			$.get(filePath,null,fnAjax);
		}
	} else {

		// Llamada sÃ­ncrona
		var xData = '';
		var http_request = false;

		if (window.XMLHttpRequest) {
			http_request = new XMLHttpRequest();
			/*
			if (http_request.overrideMimeType) {
				http_request.overrideMimeType('text');
			}
			*/
		}
		else {
			if (window.ActiveXObject) {
				try {
					http_request = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch (e) {
					try {
						http_request = new ActiveXObject("Microsoft.XMLHTTP");
					}
					catch (e) {
					}
				}
			}
		}

		http_request.open('GET', filePath, false);
		http_request.send(null);

		if (http_request.status == 200) {
			if (asXML == true) {
				xData = http_request.responseXML;
			}
			else {
				xData = http_request.responseText;
			}
			this.StatusOpen = true;

			http_request = null;
			return xData;
		} else {
			this.StatusOpen = false;
			throw new Error('Error ' + http_request.status + ' al llamar al fichero ' + filePath);
			http_request = null;
			return null;
		}
	}
},
LoadJson: function(filePath) {
	var json;
	try {
		json = Data.LoadFile(filePath);
		return eval(json);
	} catch (e) {
		if (filePath != "json/default.json") {
			json = Data.LoadJson("json/default.json");
			return json;
		} else {
			throw new Error(e);
		}
	}
},
LoadXML: function(filePath,strFunction) {
	var xResult = null;
	if (typeof strFunction == "string") {
		strFunction = "var xData=http_request.responseXML;\n" +
		"if (xData == null) {throw new Error('El XML " + filePath + " es ilegible.');}\n " +
		"xData = $.xmlToJSON(xData);" +
		strFunction;
		Data.LoadFile(filePath,null,strFunction);
	} else {
		xResult = Data.LoadFile(filePath,true);
		if (xResult == null) {
			throw new Error(filePath + ' no existe.');
		} else {
			return $.xmlToJSON(xResult);
		}
	}
},
DoGet: function(filePath,params) {
	var strParams = '';
	var http_request = false;

	if (typeof params == "object") {
		for (var i in params) {
			if (strParams == '') {
				strParams = '?';
			} else {
				strParams += '&';
			}
			strParams += i;
			strParams += '=';
			strParams +=params[i];
		}
	}
	if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text');
		}
	}
	else
	if (window.ActiveXObject) {
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
			//TODO: nothing?
			}
		}
	}

	http_request.open('GET', filePath + strParams, true);
	http_request.send(strParams);
	http_request = null;
},
Chrono: {
	Get: function(date) {
		var xPath, xFile = '';

		xPath = Config.Player.pathJson;
		xPath += date.getDate();
		xPath += '_';
		xPath += date.getMonth()+1;
		xPath += '_';
		xPath += date.getFullYear();
		xPath += '.json';

		xFile = Data.LoadJson(xPath);
		for (var i in xFile) {
			if (typeof xFile[i].time == "string") {
				var xTime = xFile[i].time.split(",");

				xFile[i].time = new Date(xTime[0],xTime[1],xTime[2],xTime[3],xTime[4],xTime[5]);
			}
		}

		return xFile;
	},
	GetCurrentProgram: function(chrono,time) {
		var xIndex = null;
		for (var i in chrono) {
			if (chrono[i].time < time) {
				if (xIndex == null || (chrono[xIndex].time < chrono[i].time)) {
					xIndex = i;
				}
			} else if (chrono[i].time > time) {
				if ((xIndex == null) || (chrono[xIndex].time > chrono[i].time)) {
					xIndex = i;
				}
			} else if (chrono[i].time == time) {
				xIndex = i;
				break;
			}
		}
		return xIndex;
	},
	OrderByTime: function(object) {
		var xList = new Array(0);

		while (object.length > 0) {
			var xVideo, xLossTime, xIndex;

			xIndex = 0;
			xVideo = object[xIndex];
			xLossTime = xVideo.time;
			for (var i in object) {
				if (object[i].time < xLossTime) {
					xIndex = i;
					xLossTime = object[i].time;
				}
			}
			xVideo = object[xIndex];
			xList.push(xVideo);
			object.splice(xIndex,1);
		}

		return xList;
	}
},
Canales: {
	// Functions
	GetData: function(){
		var url = Config.XML.main;
		var xData = Data.LoadXML(url);
		return xData.channel;
	}
},
RSS: {
	Get: function(path,strFunction) {
		if (typeof strFunction == "string") {
			$.get(path,null,function(data) {
				var xData = $.xmlToJSON(data);
				eval(strFunction);
			},"xml");
		}else {
			throw new Error('No puede recuperarse las RSS. Falta el controlador.');
		}
	}
},
Secciones:{
	GetDataByChannel: function(channelID){
		if (isNull(channelID)) {
			throw new Error("Debe especificar un canal v\u00E1lido.");
		}

		var xChannels = Data.Canales.GetData();
		for (var i in xChannels) {
			var xChannelItem = xChannels[i];
			if (xChannelItem.id == channelID) {
				return xChannelItem.seccion;
				break;
			}
		}
		return null;
	}
},
Videos: {
	GetDataBySeccion: function(seccion) {

		if (isNull(seccion)) {
			throw new Error("Debe especificar una secci\u00F3n v\u00E1lida.");
		}
		if (typeof seccion.listtrack == "string" && seccion.listtrack.length > 0) {
			var url = Config.Player.host + '/' + seccion.listtrack;
			var xSections = Data.LoadXML(url);
			return xSections.track;
		} else return [];

	},
	Get: function(videoID) {
		var xChannelItems = Data.Canales.GetData();
		for (var i = 0; i < xChannelItems.length; i++){
			var xSectionsItems = xChannelItems[i].seccion;
			for (var j = 0; j < xSectionsItems.length; j++){
				var xVideosItems = Data.Videos.GetDataBySeccion(xSectionsItems[j]);
				if (xVideosItems == null) continue;
				for (var k = 0; k < xVideosItems.length; k++){
					var xVideo = xVideosItems[k];
					if (xVideo.id == videoID) {
						return xVideo;
						break; break; break;
					}
				}
			}
		}
		return null;
	}
},
Publicidad: function(){

	// Fields
	var _groups;
	var _formats;
	var _timeZones;
	var _filmItems;

	// Constructor

	// Functions
	this.GetData = function(date){
		if (isNull(date))
			throw new Error("Debe especificar una fecha v\u00E1lida.");

		var strQuery, xCommand, xReader, xLista;

		// 0. Abro la conexiÃ³n
		xCommand = new Data.XPathCommand(Config.XML.publicity);
		xCommand.Open();

		// 1. Cargo los grupos
		_groups = new Array(0);

		strQuery = "/publicidad/group/item";
		xCommand.CommandText = strQuery;
		xReader = xCommand.ExecuteReader();

		while (xReader.Read()) {
			var xGroup = new DTO.Publicidad.PublicityGroup();
			xGroup.id = xReader.RowIndex;
			xGroup.name = xReader.Item();

			if (xGroup.IsValid())
				_groups.push(xGroup);
		}

		// 2. Cargo los formatos de video disponibles
		_formats = new Array(0);

		strQuery = "/publicidad/format/item";
		xCommand.CommandText = strQuery;
		xReader = xCommand.ExecuteReader();

		while (xReader.Read()) {
			var xFormat = new DTO.Player.DisplayFormat();
			xFormat.id = xReader.RowIndex;
			xFormat.name = xReader.Item();

			if (xFormat.IsValid())
				_formats.push(xFormat);
		}

		// 3. Cargo las zonas horarias
		_timeZones = new Array(0);

		strQuery = "/publicidad/timezone/item";
		xCommand.CommandText = strQuery;
		xReader = xCommand.ExecuteReader();

		while (xReader.Read()) {
			var xTimeZone = new DTO.DateTime.TimeZone();
			xTimeZone.id = xReader.Item("id");
			xTimeZone.name = xReader.Item("name");

			_timeZones.push(xTimeZone);
		}

		for (var i = 0; i < _timeZones.length; i++) {
			var xTimeZone = _timeZones[i];
			xCommand.CommandText = strQuery + "[@id=" + xTimeZone.id.toString() + "]/add";
			xTimeZone.item = new Array();

			xReader = xCommand.ExecuteReader();
			while (xReader.Read()) {
				var xTimeZoneItem = new DTO.DateTime.TimeZoneItem();
				xTimeZoneItem.dayweek = xReader.Item("dayweek");
				xTimeZoneItem.start = xReader.Item("start");
				xTimeZoneItem.end = xReader.Item("end");

				if (xTimeZoneItem.IsValid())
					xTimeZone.item[xTimeZone.item.length] = xTimeZoneItem;
			}
			if (!xTimeZone.IsValid())
				_timeZones.splice(i, 1);
		}

		// 4. Cargo la lista de films publicitarios
		_filmItems = new Array(0);

		strQuery = "/publicidad/film/item";
		xCommand.CommandText = strQuery;
		xReader = xCommand.ExecuteReader();

		while (xReader.Read()) {
			var xFilmItem = new DTO.Multimedia.FilmItem();

			xFilmItem.id = xReader.Item("id");
			xFilmItem.file = xReader.Item("file");

			if (xFilmItem.IsValid())
				_filmItems.push(xFilmItem);
		}

		// X. Cargo la publicidad
		xLista = new Array(0);

		strQuery = "/publicidad/publicity/item[@id]";
		xCommand.CommandText = strQuery;
		xReader = xCommand.ExecuteReader();

		while (xReader.Read()) {
			var xPublicidad = new DTO.Publicidad.Publicity();

			xPublicidad.id = xReader.Item("id");
			xPublicidad.description = xReader.Item("description");
			xPublicidad.fechaemision = xReader.Item("fechaemision");
			xPublicidad.fechacaducidad = xReader.Item("fechacaducidad");
			xPublicidad.prioridad = xReader.Item("prioridad");
			xPublicidad.link = xReader.Item("link");
			xPublicidad.groups = this._serializeGroup(xReader.Item("groups"));
			xPublicidad.formats = this._serializeFormat(xReader.Item("formats"));
			xPublicidad.timezones = this._serializeTimezone(xReader.Item("timezones"));
			xPublicidad.composition = this._serializeComposition(xReader.Item("composition"));

			if (xPublicidad.IsValid())
				xLista.push(xPublicidad);
		}
		xCommand.Close();

		return xLista;
	};
	this.GetDataByGroup = function(date, group){
		var xAllElements = this.GetData(date);
		var xFilterElements = new Array(0);

		for (var i = 0; i < xAllElements.length; i++) {
			var xElement = xAllElements[i];
			for (var j = 0; j < xElement.groups.length; j++) {
				var xGroup = xElement.groups[j];
				if (xGroup.name == group) {
					xFilterElements.push(xElement);
				}
			}
		}

		return xFilterElements;
	};
	this._serializeGroup = function(listGroups){
		if (listGroups == null){
			return null;
		}

		for (var i = 0; i < listGroups.length; i++) {
			var xGroupID = listGroups[i];

			if (isNumeric(xGroupID)) {
				xGroupID = parseInt(xGroupID);
				listGroups[i] = _groups[xGroupID];
			}
			else {
				throw new Error('Grupo no v\u00E1lido.');
			}
		}

		return listGroups;
	};
	this._serializeFormat = function(listFormats){
		if (listFormats == null) {
			return null;
		}
		for (var i = 0; i < listFormats.length; i++) {
			var xFormatID = listFormats[i];

			if (!isNull(xFormatID)) {
				if (isNumeric(xFormatID)) {
					xFormatID = parseInt(xFormatID);
					listFormats[i] = _formats[xFormatID];
				}
				else {
					if (xFormatID != "") {
						throw new Error('Formato de publicidad no v\u00E1lido: ' + xFormatID);
					}
				}
			}
		}

		return listFormats;
	};
	this._serializeTimezone = function(listTimeZones){
		if (listTimeZones == null){
			return null;
		}
		for (var i = 0; i < listTimeZones.length; i++) {
			var xTimeZoneID = listTimeZones[i];

			if (isNumeric(xTimeZoneID)) {
				xTimeZoneID = parseInt(xTimeZoneID);
				listTimeZones[i] = _timeZones[xTimeZoneID];
			}
			else {
				throw new Error('Zona horaria no v\u00E1lida.');
			}
		}

		return listTimeZones;
	};
	this._serializeComposition = function(DOMObjects){
		if (DOMObjects == null){
			return null;
		}
		var xComposition = new Array(0);
		var i;
		var xListFilms = DOMObjects.getElementsByTagName("film");
		for (i = 0; i < xListFilms.length; i++) {

			var xFilmItem = new DTO.Multimedia.Film();
			var xPlayerID = xListFilms[i].attributes.getNamedItem("playerID");
			var xFilm = xListFilms[i].attributes.getNamedItem("filmID");

			xFilmItem.player = (isNull(xPlayerID)) ? '' : xPlayerID.nodeValue;
			xFilmItem.film = (isNull(xFilm)) ? '' : xFilm.nodeValue;

			if (isNumeric(xFilmItem.film)) {
				xFilmItem.film = parseInt(xFilmItem.film);
				xFilmItem.film = _filmItems[xFilmItem.film];
			}
			else {
				throw new Error('Film seleccionado no v\u00E1lido.');
			}

			if (xFilmItem.IsValid())
				xComposition.push(xFilmItem);

		}

		var xListGraphics = DOMObjects.getElementsByTagName("graphic");
		for (i = 0; i < xListGraphics.length; i++) {

			for (var j = 0; j < xListGraphics.length; j++) {
				var xGraphic = new DTO.Multimedia.GraphicItem();

				var x = xListGraphics[i].attributes.getNamedItem("x");
				var y = xListGraphics[i].attributes.getNamedItem("y");
				var width = xListGraphics[i].attributes.getNamedItem("width");
				var height = xListGraphics[i].attributes.getNamedItem("height");
				var css = xListGraphics[i].attributes.getNamedItem("css");
				var image = xListGraphics[i].attributes.getNamedItem("image");
				var duration = xListGraphics[i].attributes.getNamedItem("duration");

				if (!isNull(x)) {
					if (isNumeric(x.nodeValue))
						x = parseInt(x.nodeValue);
					else
						throw new Error('Coordenada de la X no v\u00E1lida.');
				}
				if (!isNull(y)) {
					if (isNumeric(y.nodeValue))
						y = parseInt(y.nodeValue);
					else
						throw new Error('Coordenada de la Y no v\u00E1lida.');
				}
				if (!isNull(width)) {
					if (isNumeric(width.nodeValue))
						width = parseInt(width.nodeValue);
					else
						throw new Error('TamaÃ±o no v\u00E1lido.');
				}
				if (!isNull(height)) {
					if (isNumeric(height.nodeValue))
						height = parseInt(height.nodeValue);
					else
						throw new Error('Altura no v\u00E1lida.');
				}

				xGraphic.position = new DTO.Multimedia.Position(x, y);
				xGraphic.size = new DTO.Multimedia.Size(width, height);
				xGraphic.image = (isNull(image)) ? '' : image.nodeValue;
				xGraphic.duration = (isNull(duration)) ? '' : duration.nodeValue;
				xGraphic.css = (isNull(css)) ? undefined : css.nodeValue;

				if (xGraphic.IsValid())
					xComposition.push(xGraphic);

			}
		}

		var xListTexts = DOMObjects.getElementsByTagName("text");
		for (i = 0; i < xListTexts.length; i++) {

			var xText = new DTO.Multimedia.TextItem();

			var x = xListTexts[i].attributes.getNamedItem("x");
			var y = xListTexts[i].attributes.getNamedItem("y");
			var width = xListTexts[i].attributes.getNamedItem("width");
			var height = xListTexts[i].attributes.getNamedItem("height");
			var color = xListTexts[i].attributes.getNamedItem("color");
			var css = xListTexts[i].attributes.getNamedItem("css");
			var text;
			if (xListTexts[i].textContent)
				text = xListTexts[i].textContent;
			else
				text = xListTexts[i].text;
			var duration = xListTexts[i].attributes.getNamedItem("duration");

			if (!isNull(x)) {
				if (isNumeric(x.nodeValue))
					x = parseInt(x.nodeValue);
			}
			if (!isNull(y)) {
				if (isNumeric(y.nodeValue))
					y = parseInt(y.nodeValue);
			}
			if (!isNull(width)) {
				if (isNumeric(width.nodeValue))
					width = parseInt(width.nodeValue);
			}
			if (!isNull(height)) {
				if (isNumeric(height.nodeValue))
					height = parseInt(height.nodeValue);
			}

			xText.position = new DTO.Multimedia.Position(x, y);
			xText.size = new DTO.Multimedia.Size(width, height);
			xText.text = text;
			xText.duration = (isNull(duration)) ? '' : duration.nodeValue;
			xText.color = (isNull(color)) ? '' : color.nodeValue;
			xText.css = (isNull(css)) ? '' : css.nodeValue;

			if (xText.IsValid())
				xComposition.push(xText);

		}

		var xListAnimations = DOMObjects.getElementsByTagName("animation");
		for (i = 0; i < xListAnimations.length; i++) {

			var xAnimation = new DTO.Multimedia.AnimationItem();
			var xImage = xListAnimations[i].attributes.getNamedItem("image");
			var xRepeat = xListAnimations[i].attributes.getNamedItem("repeat");
			var xDuration = xListAnimations[i].attributes.getNamedItem("duration");

			xAnimation.image = (isNull(xImage)) ? '' : xImage.nodeValue;
			xAnimation.repeat = (isNull(xRepeat)) ? '' : xRepeat.nodeValue;
			xAnimation.duration = (isNull(xDuration)) ? 0 : parseInt(xDuration.nodeValue);
			xAnimation.frames = new Array(0);

			var xFramesDOM = xListAnimations[i].getElementsByTagName('frame');
			for (var k = 0; k < xFramesDOM.length; k++) {

				var xFrame = new DTO.Multimedia.Frame();

				var x = xFramesDOM[k].attributes.getNamedItem("x").nodeValue;
				var y = xFramesDOM[k].attributes.getNamedItem("y").nodeValue;
				var width = xFramesDOM[k].attributes.getNamedItem("width").nodeValue;
				var height = xFramesDOM[k].attributes.getNamedItem("height").nodeValue;
				var time = xFramesDOM[k].attributes.getNamedItem("time").nodeValue;

				if (!isNaN(parseFloat(x)))
					x = parseFloat(x);
				else
					throw new Error('Coordenada de la X no v\u00E1lida.');
				if (!isNaN(parseFloat(y)))
					y = parseFloat(y);
				else
					throw new Error('Coordenada de la Y no v\u00E1lida.');
				if (isNumeric(width))
					width = parseInt(width);
				else
					throw new Error('TamaÃ±o no v\u00E1lido.');
				if (isNumeric(height))
					height = parseInt(height);
				else
					throw new Error('Altura no v\u00E1lida.');
				if (!isNaN(parseFloat(time)))
					time = parseFloat(time);
				else
					throw new Error('Tiempo especificado no v\u00E1lido.');

				xFrame.time = time;
				xFrame.position = new DTO.Multimedia.Position(x, y);
				xFrame.size = new DTO.Multimedia.Size(width, height);

				if (xFrame.IsValid())
					xAnimation.frames.push(xFrame);

			}

			if (xAnimation.IsValid())
				xComposition.push(xAnimation);

		}

		return xComposition;
	}

},
XPathReader: function(iterator){

	// Fields
	var _iterator = iterator;
	var _data = null;
	this.RowIndex = -1;

	// Constructor

	// Functions
	this.Read = function(){
		this.RowIndex++;

		if (document.evaluate) {
			_data = _iterator.iterateNext();
		}
		else {
			_data = _iterator[this.RowIndex];
		}

		return _data;
	};
	this.Item = function(nodeName){

		// value
		if (!nodeName) {
			if (_data.textContent)
				return _data.textContent;
			else
			if (_data.text)
				return _data.text;
			else
				return _data;
		}

		// busco en el atributo del nodo...
		var xData = _data.attributes;
		if (xData.getNamedItem(nodeName))
			return xData.getNamedItem(nodeName).nodeValue;

		// busco un nodo con el nombre del atributo...
		xData = _data.getElementsByTagName(nodeName);
		if (xData.length == 0) {
			return null;
		}
		else
		if (xData.length == 1) {

			if (xData[0].nodeName == nodeName) { // nodo compuesto ? nodo compuesto
				if ((xData[0].childNodes.length == 1 && xData[0].firstChild.nodeType == 3) || (xData[0].childNodes.length == 0 && xData[0].nodeType == 1)) {
					if (xData[0].textContent !== undefined)
						return xData[0].textContent; // nodo simple
					else
						return xData[0].text; // nodo compuesto
				}
				else
				if (getChildElementsByTagName(xData[0], 'add').length > 0) {
					var xListResult = new Array();
					var xListDOM = xData[0].getElementsByTagName('add');

					for (var i = 0; i < xListDOM.length; i++) {
						var xItem;

						if (xListDOM[i].textContent !== undefined)
							xItem = xListDOM[i].textContent;
						else
							xItem = xListDOM[i].text;

						xListResult.push(xItem);
					}

					return xListResult;
				}
				else
					return xData[0];
			}
			else { // nodo simple ...
				if (xData[0].textContent !== undefined)
					return xData[0].textContent;
				else
					return xData[0].text;
			}

		}
		else
		if (xData.length > 1) { // nodo compuesto ...

			// Busco por los nodos (sin profuncizar)...
			var xResult = new Array();
			for (var i = 0; i < _data.childNodes.length; i++) {
				var xNode = _data.childNodes[i];

				if (xNode.nodeType == 1 && xNode.tagName == nodeName) {
					if (xNode.textContent) {
						xResult.push(xNode.textContent);
					} else {
						xResult.push(xNode.text);
					}
				}
			}

			if (xResult.length == 1) {
				return xResult[0];
			} else {
				// Resultado compuesto
				return xData;
			}

		}
		else {
			throw new Exception('Dato desconocido.');
		}

	};
},
XPathCommand: function(xmlPath){
	if (isNull(xmlPath)) {
		throw new Error('Falta la cadena de conexi\u00F3n.');
	}

	// Fields
	var _data;

	// Properties
	this.CommandText = "";
	this.XmlPath = xmlPath;
	this.StatusOpen = false;

	// Constructor

	// Functions
	this.Open = function(){

		// Pre-validation
		_data = Data.Cache.XPathCommand[xmlPath];
		if (_data != null) {
			this.StatusOpen = true;
			return;
		}

		this.http_request = false;

		if (window.XMLHttpRequest) {
			http_request = new XMLHttpRequest();
			if (http_request.overrideMimeType) {
				http_request.overrideMimeType('text/xml');
			}
		}
		else
		if (window.ActiveXObject) {
			try {
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
				}
			}
		}

		http_request.open('GET', xmlPath, false);
		http_request.send(null);

		switch (http_request.status) {
			case 200:
				_data = http_request.responseXML;
				checkDocumentXML(_data.childNodes);
				Data.Cache.XPathCommand[xmlPath] = _data;
				this.StatusOpen = true;
				break;
			default:
				throw new Error(http_request.statusText + ': ' + xmlPath)
				break;
		}
		http_request = null;
	};
	this.Close = function(){
		_data = null;

		this.StatusOpen = false;
	};
	this.ExecuteReader = function(){
		var xReader, xIterator;

		if (!this.StatusOpen)
			throw new Error("Los datos no est\u00E1n cargados o ha dejado una conexi\u00F3n abierta anteriormente.");
		if (document.evaluate) {
			xIterator = _data.evaluate(this.CommandText, _data, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
			if (xIterator.invalidIteratorState)
				throw new Error('Se produjo un error al intentar ejecutar la consulta.');
		}
		else {
			xIterator = _data.selectNodes(this.CommandText);
		}
		xReader = new Data.XPathReader(xIterator);

		return xReader;
	};
	this.ScalarQuery = function(){
		var xResult;

		// is number?
		xResult = _data.evaluate(this.CommandText, _data, null, XPathResult.NUMBER_TYPE, null).numberValue;
		if (!xResult)
			return xResult;

		// is string?
		xResult = _data.evaluate(this.CommandText, _data, null, XPathResult.STRING_TYPE, null).stringValue;
		if (!xResult)
			return xResult;

		// is boolean?
		xResult = _data.evaluate(this.CommandText, _data, null, XPathResult.BOOLEAN_TYPE, null).booleanValue;
		if (!xResult)
			return xResult;

		// is singleNode?
		xResult = _data.evaluate(this.CommandText, _data, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
		if (!xResult)
			return xResult;

		return xResult;
	};

	// Private metodhos
	var checkDocumentXML = function(aNodes) {

		for (var i = 0; i < aNodes.length; i++) {
			var xNode = aNodes[i];
			if (xNode.tagName == "parsererror") {
				if (xNode.textContent) {
					throw new Error(xNode.textContent);
					break;
				}
				else {
					throw new Error(xNode.text);
					break;
				}
			}
			if (xNode.childNodes.length > 0) {
				checkDocumentXML(xNode.childNodes);
			}
		}

	}
}
};
var DTO = {

Menu: function(aElement, aNumeroElementos, aWidth) {

	// Fields
	this.id = aElement;
	this.numeroElementos = aNumeroElementos;
	this.width = aWidth;

	return this;
},
Publicidad: {
	Owners: {
		CHANNEL: 0,
		VIDEO: 1
	},
	Publicity: function() {

		// Fields
		this.id = undefined;
		this.description = undefined;
		this.fechaemision = undefined;
		this.fechacaducidad = undefined;
		this.prioridad = undefined;
		this.link = undefined;
		this.groups = undefined;
		this.formats = undefined;
		this.timezones = undefined;
		this.composition = undefined;

		// Functions
		this.IsObsolete = function() {
			if (Global.CurrentDate < this.fechaemision || Global.CurrentDate > this.fechacaducidad) {
				return true;
			} else {
				return false;
			}
		};
		this.IsValid = function() {
			if (isNull(this.id) || isNull(this.composition) || isNull(this.formats)) {
				return false;
			} else {
				return true;
			}
		};

	},
	PublicityGroup: function() {

		// Fields
		this.id = undefined;
		this.name = undefined;

		// Functions
		this.IsValid = function() {
			if (isNull(this.id) || isNull(this.name)) {
				return false;
			} else {
				return true;
			}
		};
	}
},
Player: {
	DisplayFormat: function() {

		// Fields
		this.id = undefined;
		this.name = undefined;

		// Functions
		this.IsValid = function() {
			if (isNull(this.id) || isNull(this.name)) {
				return false;
			} else {
				return true;
			}
		};
	},
	Player: function() {

		// Fields
		this.id = undefined;
		this.htmlID = undefined;
		this.description = undefined;

	}
},
DateTime: {
	TimeZone: function() {

		// Fields
		this.id = undefined;
		this.name = undefined;
		this.item = undefined;

		// Functions
		this.IsValid = function() {
			if (isNull(this.id) || isNull(this.name) || isNull(this.item)) {
				return false;
			} else if (this.item.length > 0) {
				return true;
			} else {
				return false;
			}
		};
	},
	TimeZoneItem: function() {

		// Fields
		this.dayweek = undefined;
		this.start = undefined;
		this.end = undefined;

		// Functions
		this.IsValid = function() {
			if (isNull(this.dayweek) || isNull(this.start) || isNull(this.end)) {
				return false;
			} else {
				return true;
			}
		};
	},
	Daysweek: {
		Lunes: 0,
		Martes: 1,
		Miercoles: 2,
		Jueves: 3,
		Viernes: 4,
		Sabado: 5,
		Domingo: 6,
		Festivo: 7
	}
},
Multimedia: {
	AnimationItem: function() {

		// Fields
		this.image = undefined;
		this.repeat = undefined;
		this.frames = undefined;
		this.duration = undefined;

		// Functions
		this.IsValid = function() {
			if (isNull(this.image) || isNull(this.repeat) || isNull(this.frames)) {
				return false;
			} else if (this.frames.length > 0) {
				return true;
			} else {
				return false;
			}
		};

	},
	FilmItem: function() {

		// Fields
		this.id = undefined;
		this.file = undefined;

		// Functions
		this.IsValid = function() {
			if (isNull(this.id) || isNull(this.file)) {
				return false;
			} else {
				return true;
			}
		};
	},
	Film: function() {

		// Fields
		this.playerID = Config.Player.player1.attributes.id;
		this.film = undefined;

		// Functions
		this.IsValid = function() {
			if (isNull(this.film) || isNull(this.player)) {
				return false;
			} else {
				return true;
			}
		};
	},
	Frame: function() {

		// Fields
		this.time = undefined;
		this.position = undefined;
		this.size = undefined;

		// Frames
		this.IsValid = function() {
			if (isNull(this.time) || isNull(this.position) || isNull(this.size)) {
				return false;
			} else {
				return true;
			}
		};
	},
	GraphicItem: function() {

		// Fields
		this.position = undefined;
		this.size = undefined;
		this.image = undefined;
		this.duration = undefined;

		// Functions
		this.IsValid = function() {
			if (isNull(this.position) || isNull(this.size) || isNull(this.image) || isNull(this.duration)) {
				return false;
			} else {
				return true;
			}
		};
	},
	Position: function(x, y) {

		// Fields
		this.x = x;
		this.y = y;
	},
	Priority: function() {

		// Fields
		this.id = undefined;
		this.description = undefined;
		this.value = undefined;
	},
	Size: function(width, height) {

		// Fields
		this.width = width;
		this.height = height;
	},
	TextItem: function() {

		// Fields
		this.color = undefined;
		this.css = undefined;
		this.duration = undefined;
		this.position = undefined;
		this.size = undefined;
		this.text = undefined;

		// Functions
		this.IsValid = function() {
			if (isNull(this.position) || isNull(this.size) || isNull(this.text) || isNull(this.duration)) {
				return false;
			} else {
				return true;
			}
		};
	}
}
};

// Author: Ismael
// Type: CORE OBJECTS
// Date: 04/07/2008
var Core = {

Chrono: function() {
	var _chrono, _currentIndexProgram, _interval1, _interval2;
	this.Init = function() {
		_chrono = Data.Chrono.Get(Now());
		if (_chrono == null) {
			alert('En este momento no hay programaci\u00F3n en directo. En breve reanudaremos la emisi\u00F3n. Gracias.');
		}
		else {
			_chrono = Data.Chrono.OrderByTime(_chrono);
			this.Play();
			//_interval2 = setInterval("I.Chrono.Reset()",30000);
		}
	}
	this.Finish = function() {
		_currentIndexProgram++;
		this.SetCurrentProgram(_currentIndexProgram);
		this.Play();
	}
	this.Play = function() {
		_currentIndexProgram = Data.Chrono.GetCurrentProgram(_chrono, Now());
		View.ChronoWeb.PlayingVideo(this.GetCurrentVideo());
		I.SetPlayListChrono(_chrono, this.GetCurrentProgram());
		Core.ChronoPlayer.Play(this.GetCurrentVideo());
		if (_interval1 == null) {
			_interval1 = setInterval("I.Chrono.Refresh()",5000);
		}
		this.Status = 1;
	}
	this.Refresh = function() {
		switch (this.Status) {
			case 1:
				var xRefreshIndexProgram = Data.Chrono.GetCurrentProgram(_chrono, Now());
				if (_currentIndexProgram != xRefreshIndexProgram) {
					this.Play();
				}
				break;
			case 0:
				clearInterval(_interval);
				break;
		}
	}
	this.Reset = function() {
		_chrono = Data.Chrono.Get(Now());
		if (_chrono == null) {
			alert('En este momento no hay programaci\u00F3n en directo. En breve reanudaremos la emisi\u00F3n. Gracias.');
		}
		else {
			_chrono = Data.Chrono.OrderByTime(_chrono);
		}
	}
	this.SetCurrentProgram = function(newIndex) {
		xCurrentIndexProgram = newIndex;
	}
	this.Status = 0;
	this.Stop = function() {
		this.Status = 0;
	}
	this.GetCurrentProgram = function() {
		var xCurrentProgram = _chrono[_currentIndexProgram];

		return xCurrentProgram;
	}
	this.GetCurrentVideo = function() {
		return this.GetCurrentProgram();
	}
},
ChronoPlayer: {
	playerRegister: false,
	PLAYER1: function() {
		return getPlayer(I.PlayerMain.ID);
	},
	Play: function(video) {
		// Calculo el segundo de arranques
		var start = ((Now()) - video.time);
		start = start/100/60;
		//TODO: comprobar DURATION del video para poner cortinella
		var xPlayer = copy(Config.Player.player1);
		xPlayer.flashvars.controlbar = "none";
		xPlayer.flashvars.displayclick = "fullscreen";
		xPlayer.flashvars.volume = "100";
		I.playVideo(video,xPlayer,start);
	},
	Next: function(obj, aChrono) {
		switch (obj.newstate) {
			case "COMPLETED":
				aChrono.Finish();
				break;
			case "BUFFERING":
				if (obj.oldstate == "PLAYING") {
				//TODO: implementar
				}
				else if (obj.oldstate == "IDLE") {
				//TODO: implementar
				}
				//TODO: imiplementar
				break;
			case "PLAYING":
				//TODO: implementar
				break;
		}
	}
},
Motion: function(AnimationInfo, Owner, Link, Caller) {

	// Fields
	var xDiv = undefined;
	var xImg = undefined;
	var _contenedor = getElement(Config.HTML.CONTENEDOR);
	var _currentFrame = undefined;
	var _numRepeated = undefined

	this.frames = undefined;
	this.interval = undefined;
	this.Data = undefined;
	this.Link = undefined;
	this.Owner = undefined;
	this.Caller = undefined;

	// Public Functions
	this.StopAndClear = function() {
		this.Stop();
		xDiv.style.display = 'none';
		_currentFrame = -1;
	};
	this.Play = function() {
		xDiv.style.display = 'block';
		if (this.Data.duration > -1) {
			setTimeout(this.StopAndClear, this.Data.duration*1000);
		}

		this.interval = setInterval("__PLAYING_CACHEANIMATION.nextFrame()", (1000 / Config.Player.framesPerSecond));
	};
	this.Stop = function() {
		if (!isNull(__PLAYING_CACHEANIMATION))
			clearInterval(__PLAYING_CACHEANIMATION.interval);
		__PLAYING_CACHEANIMATION.interval = null;
	};

	// Private Functions
	this.nextFrame = function() {
		_currentFrame++;
		if (_currentFrame == 0) _numRepeated++;

		if (_currentFrame >= this.frames.length) {
			if ((this.Data.repeat == -1) || (this.Data.repeat > _numRepeated)) {
				_currentFrame = -1;
				return;
			} else {
				this.Stop();
				return;
			}
		}
		if (isNull(this.frames[_currentFrame])) {
			_currentFrame++;
			return;
		}

		xImg.style.width = parseInt(this.frames[_currentFrame].size.width).toString() + 'px';
		xImg.style.height = parseInt(this.frames[_currentFrame].size.height).toString() + 'px';

		xDiv.style.left = parseInt(this.frames[_currentFrame].position.x).toString() + 'px';
		xDiv.style.top = parseInt(this.frames[_currentFrame].position.y).toString() + 'px';
		xDiv.style.width = parseInt(this.frames[_currentFrame].size.width).toString() + 'px';
		xDiv.style.height = parseInt(this.frames[_currentFrame].size.height).toString() + 'px';

	};
	this.init = function () {
		xDiv = document.createElement('div');
		xDiv.setAttribute('id', Config.HTML.PUBLICIDAD_ANIMATION + '_' + Owner);
		xDiv.style.left = this.Data.frames[0].position.x + 'px';
		xDiv.style.top = this.Data.frames[0].position.y + 'px';
		xDiv.style.width = this.Data.frames[0].size.width + 'px';
		xDiv.style.height = this.Data.frames[0].size.height + 'px';
		xDiv.style.display = 'block';
		xDiv.style.position = 'absolute';

		xImg = document.createElement('IMG');
		xImg.setAttribute('width',this.Data.frames[0].size.width + 'px');
		xImg.setAttribute('height',this.Data.frames[0].size.height + 'px');
		xImg.setAttribute('border','0');
		xImg.src = this.Data.image;

		var xA = document.createElement('A');
		xA.setAttribute('href',this.Link);
		xA.setAttribute('target','_blank');

		xA.appendChild(xImg);
		xDiv.appendChild(xA);

		for (var i = 0; i < this.Data.frames.length; i++) {

			var X, Y, W, H;
			if (i > 0) {
				var T1 = this.Data.frames[i].time;
				var X1 = this.Data.frames[i].position.x;
				var Y1 = this.Data.frames[i].position.y;
				var W1 = this.Data.frames[i].size.width;
				var H1 = this.Data.frames[i].size.height;

				var T0 = this.Data.frames[i - 1].time;
				var X0 = this.Data.frames[i - 1].position.x;
				var Y0 = this.Data.frames[i - 1].position.y;
				var W0 = this.Data.frames[i - 1].size.width;
				var H0 = this.Data.frames[i - 1].size.height;

				X = X1 - X0;
				Y = Y0 - Y1 ;
				W = W1 - W0;
				H = H1 - H0;

				var nFs = Config.Player.framesPerSecond * (T1 - T0);
				var Vx = clipFloat(X / nFs,6);
				var Vy = clipFloat(Y / nFs,6);
				var Vw = clipFloat(W / nFs,6);
				var Vh = clipFloat(H / nFs,6);

				for (var j = 0; j < nFs; j++) {
					var xLastFrame = this.frames[this.frames.length - 1];

					var xPosition = new DTO.Multimedia.Position(
						xLastFrame.position.x + Vx,
						xLastFrame.position.y - Vy);

					var xSize = new DTO.Multimedia.Size(
						xLastFrame.size.width + Vw,
						xLastFrame.size.height + Vh);

					this.frames.push(
					{
						position: xPosition,
						size: xSize
					}
					);
				}
			} else if (i == 0) {
				this.frames = new Array(1);
				_currentFrame = -1;
				_numRepeated = -1;

				X = this.Data.frames[i].position.x;
				Y = this.Data.frames[i].position.y;
				W = this.Data.frames[i].size.width;
				H = this.Data.frames[i].size.height;

				this.frames[0] = {
					position: new DTO.Multimedia.Position(X, Y),
					size: new DTO.Multimedia.Size(W, H)
				};
			}
		}
		_contenedor.appendChild(xDiv);
	};

	// Constructor
	this.Data = AnimationInfo;
	this.Link = Link;
	this.Owner = Owner;
	this.init();
},
// TODO: No se estÃ¡ usando esta funciÃ³n
Canales: function() {
	// Fields
	this.dataCANALES = Data.Canales;

	// Functions
	this.ChangeToChannel = function(channel) {
		if (channel != this.CurrentChannelDisplayed) {
			this.CurrentChannelDisplayed = channel;

			Status.ChannelChanged();
		}
	};
	this.LoadData = function() {
		this.Item = this.dataCANALES.GetData();


		for (var xIndexItem in this.Item) {
			var xChannelItem = this.Item[xIndexItem];
			// Publicidad de arranque
			if (Config.Player.publicityEnabled == true && xChannelItem.publicitystart != null) {
				for (var i = 0; i < xChannelItem.publicitystart.length; i++) {
					var xPublicityStart = xChannelItem.publicitystart[i];
					if (xPublicityStart.substring(0, 5) == "group") {
						var group = xPublicityStart.split(":")[1];
						var xLoopTime = xPublicityStart.split(":")[2];
						var xPublicidadCore = new Core.Publicidad.Publicity();
						xPublicidadCore.LoadDataByGroup(group);

						if (!isNull(xLoopTime) && xLoopTime > 0) {

						}
						else {
							var xIndice = aleatorio(0, (xPublicidadCore.Item.length > 1) ? xPublicidadCore.Item.length - 1 : 0);
							var xAnuncio = xPublicidadCore.Item[xIndice];

							if (isNull(xAnuncio))
								throw new Error('Spot publicitario no encontrado.');
							xChannelItem.publicityStart[i] = {
								ID: xAnuncio.id,
								Owner: DTO.Publicidad.Owners.CHANNEL
							};
						}
					}
					else {
						xChannelItem.publicityStart[i] = {
							ID: xPublicityStart,
							Owner: DTO.Publicidad.Owners.CHANNEL
						};
					}
				}
			}
			// Publicidad de fin
			if (Config.Player.publicityEnabled == true && xChannelItem.publicityend != null) {
				for (var i = 0; i < xChannelItem.publicityend.length; i++) {
					xPublicityEnd = xChannelItem.publicityend[i];
					if (xPublicityEnd.substring(0, 5) == "group") {
						var group = xPublicityEnd.split(":")[1];
						var xPublicidadCore = new Core.Publicidad.Publicity();
						xPublicidadCore.LoadDataByGroup(group);
						var xIndice = aleatorio(0, xPublicidadCore.Item.length - 1);
						var xAnuncio = xPublicidadCore.Item[xIndice];

						xChannelItem.publicityEnd[i] = {
							ID: xAnuncio.id,
							Owner: DTO.Publicidad.Owners.CHANNEL
						}
					}
					else {
						xChannelItem.publicityEnd[i] = {
							ID: this.CurrentChannelDisplayed.publicityEnd,
							Owner: DTO.Publicidad.Owners.CHANNEL
						}
					}
				}
			}
		}

		this.SetCurrentIndex(-1);
	};
	this.GetStartingChannel = function() {
		return this.GetItemStart();
	};
},
Secciones: function() {

	// Fields
	this.dataSECCIONES = Data.Secciones;

	// Public Functions
	this.LoadDataOfChannel = function(channel) {
		this.Item = this.dataSECCIONES.GetDataByChannel(channel.id);
		this.SetCurrentIndex(-1);
	},
	this.GetStartingSeccion = function() {
		return this.GetItemStart();
	};

},
Videos: function() {

	// Public Functions
	this.LoadDataOfSeccion = function(seccion) {
		if (typeof seccion.listtrack == "string") {
			this.Item = Data.Videos.GetDataBySeccion(seccion);
			this.SetCurrentIndex(-1);
			return true;
		} else {
			return false;
		}
	};

	// Static Functions
	this.SendVideo = function(video) {
		var xDestino, xMensaje, xTitulo;

		xDestino = getElement(Config.HTML.SENDVIDEO_DESTINO).value;
		if (!ValidarEmail(xDestino)) {
			alert('Direcci\xf3n de email no v\xe1lida.');
			return false;
		}

		xMensaje = getElement(Config.HTML.SENDVIDEO_MENSAJE).value;
		xMensaje = unescape(xMensaje);

		xTitulo = Config.Player.sendvideo_subject;

		//TODO: Do Post
		//document.location.href = "mailto:" + xDestino + "?subject=" + xTitulo + "&body=" + xMensaje;
		$.post("sendMail.php", { 
				"asunto": xTitulo,
				"destino": xDestino,
				"cuerpo": xMensaje
			},
			function(data){
				if (data=="OK ") {
					alert('Mensaje enviado correctamente. Gracias.');
				}
			}
		);
		return true;
	};

	return this;
},
Player: function(player) {
	if (isNull(player)) throw new Error('No ha especificado el identificador.');

	// Private Fields
	this.ID = player.attributes.id;

	// Public Fields
	this.ListaReproduccion = new Core.ListaReproduccion();
	this.GetChannelCurrentVideo = function() {
		return this.ListaReproduccion.GetCurrentItem().seccion.channel
	};
	this.GetSeccionCurrentVideo = function() {
		return this.ListaReproduccion.GetCurrentItem().seccion
	};
	this.GetCurrentVideo = function() {
		return this.ListaReproduccion.GetCurrentItem()
	};

	// Public Functions
	this.Play = function(video) {
		if (isNull(video)) {

			video = this.ListaReproduccion.GetItemStart();
		}
		if (isNull(video)) {
			alert('No se puede reproducir el video. Pruebe con otro video.');
			throw new Error('El video indicado a reproducir es null.');
		}
		if (isNull(video.file)) {
			alert('No se puede reproducir el video. Pruebe con otro video.');
			throw new Error('El video ' + video.id + ' no tiene ruta.');
		}

		this.ListaReproduccion.SetCurrentItem(video);
	};
	this.Stop = function() {
		this.CurrentVideo = null;
	//TODO: implementar
	};
	this.Next = function() {
		var xIndex = this.ListaReproduccion.GetCurrentIndex();
		var xLength = this.ListaReproduccion.Count();

		if (xLength > 0) {
			xIndex++;

			if (xIndex >= xLength) {
				xIndex = 0;
			}
			this.ListaReproduccion.SetCurrentIndex(xIndex);

			return this.ListaReproduccion.GetCurrentItem();
		}

		return null;
	};

	// Private Functions
	this.loadFile = function(xFile) {
		thisMovie(_HTMLid).loadFile(xFile);
	};

	// Constructor
	this.ListaReproduccion = new Core.ListaReproduccion();
},
ListaReproduccion: function() {

	// Public Functions
	this.SetLista = function(listaVideos) {
		this.Item = listaVideos;
	}
},
Publicidad: {
	Publicity: function() {

		// Private Fields
		var dataPUBLICIDAD = new Data.Publicidad();

		// Public Functions
		this.LoadData = function(){
			this.Item = dataPUBLICIDAD.GetData(Now());
			this.SetCurrentIndex(-1);
		};
		this.LoadDataByGroup = function(group) {
			this.Item = dataPUBLICIDAD.GetDataByGroup(Now(),group);
			this.SetCurrentIndex(-1);
		};
		this.Stop = function() {
			__PLAYING_I = 0;
			__PLAYING_LIST = null;
			if (!isNull(__PLAYING_CACHEANIMATION)) {
				clearInterval(__PLAYING_CACHEANIMATION.interval);
				__PLAYING_CACHEANIMATION = null;
			}
			var xItem = $('#'+Config.HTML.PUBLICIDAD_TEXT)[0];
			while (xItem) {
				xItem.parentNode.removeChild(xItem);
				xItem = $('#'+Config.HTML.PUBLICIDAD_TEXT)[0];
			}

			xItem = $('#'+Config.HTML.PUBLICIDAD_INFO)[0];
			while (xItem) {
				xItem.parentNode.removeChild(xItem);
				xItem = $('#'+Config.HTML.PUBLICIDAD_INFO)[0];
			}

			xItem = $('#'+Config.HTML.PUBLICIDAD_IMAGE)[0];
			while (xItem) {
				xItem.parentNode.removeChild(xItem);
				xItem = $('#'+Config.HTML.PUBLICIDAD_IMAGE)[0];
			}

			xItem = $('#'+Config.HTML.PUBLICIDAD_ANIMATION)[0];
			while (xItem) {
				xItem.parentNode.removeChild(xItem);
				xItem = $('#'+Config.HTML.PUBLICIDAD_ANIMATION)[0];
			}
		};

	}
},
Rss: {
	GetRSS: function(path) {
		var xResult;

		xResult = Data.RSS.get(path);

		return xResult;
	}
},
Collection: {
	BaseCollection: function() {

		// Fields
		var _currentIndex = -1;
		this.Item = undefined;

		// Functions
		this.Add = function(item) {
			this.Item.push(item);
		};
		this.SetCurrentIndex = function(newItemIndex) {
			if (isNull(newItemIndex)) return;

			_currentIndex = newItemIndex;
		};
		this.SetCurrentItem = function(newItem) {
			if (isNull(newItem)) return;

			if (this.Item == null) {
				this.Item = [newItem];
				_currentIndex = 0;
				return 0;
			} else {
				for (var i = 0; i < this.Item.length; i++) {
					if (this.Item[i] == newItem) {
						_currentIndex = i;
						return i;
						break;
					}
				}
			}
			return null;
		};
		this.Clear = function() {
			this.Item = new Array();
			_currentIndex = -1;
		};
		this.Count = function() {
			if (isNull(this.Item))
				return 0;
			else
				return this.Item.length;
		};
		this.GetCurrentIndex = function() {
			return _currentIndex;
		};
		this.GetCurrentItem = function() {
			if (isNull(this.Item))
				return null;
			else
				return this.Item[_currentIndex];
		};
		this.Find = function(key,value) {
			var xResult = undefined;

			if (isNull(key)) {
				return null;
			}
			if (value === undefined) {
				return null;
			}

			for (var i = 0; i < this.Item.length; i++) {
				for (var xPropertyItem in this.Item[i]) {
					if (xPropertyItem.toString().toUpperCase() == key.toUpperCase()) {
						xResult = this.Item[i];
						break;
					}
				}
				if (xResult !== undefined) break;
			}

			return xResult;
		};
		this.FindById = function(itemID) {
			var xResult = undefined;

			for (var i = 0; i < this.Item.length; i++) {
				if (isNull(this.Item[i].id)) continue;
				if (this.Item[i].id == itemID) {
					xResult = this.Item[i];
					break;
				}
			}

			return xResult;
		};
		this.GetItemStart = function() {
			var xIndex = this.startIndex();
			if (xIndex == -1) {


				return null;
			} else {

				return this.Item[xIndex];
			}

		};
		this.startIndex = function() {
			var xIndexStart = -1;

			if (this.Item.length == 0) return xIndexStart;

			xIndexStart = 0;
			for (var i = 0; i < this.Item.length; i++) {
				if (this.Item[i].position === undefined) continue;
				if (this.Item[i].position === null) this.Item[i].position = -1;

				if ((this.Item[i].position == getNumeroVisitas()) && (this.Item[xIndexStart].position < this.Item[i].position)) {
					xIndexStart = i;
					break;
				}
				else {
					if ((this.Item[i].position < getNumeroVisitas()) && (this.Item[i].position > this.Item[xIndexStart].position)) {
						xIndexStart = i;
					}
				}
			}

			return xIndexStart;
		};

		return this;
	},
	Dictionary: function() {
		// Fields
		var _itemCached = new Array();
		var _keyCached = new Array();

		// Functions
		this.Add = function(key, value) {
			if (isNull(key)) throw new Error('No se puede a\u00F1adir este elemento. Debe indicar una key v\u00E1lida.');
			if (value === undefined) throw new Error('No se puede a\u00F1adir este element. Debe indicar un valor v\u00E1lido.');

			_keyCached.push(key);
			_itemCached.push(value);
		};
		this.Count = function() {
			return _keyCached.length;
		};
		this.Exist = function(key) {

			if (isNull(key)) return false;

			for (var i = 0; i < _itemCached.length; i++) {
				if (key === _keyCached[i]) {
					return true;
					break;
				}
			}

			return false;
		},
		this.FindByKey = function(key) {
			var xResult = undefined;

			if (isNull(key)) return xResult;

			for (var i = 0; i < _itemCached.length; i++) {
				if (key === _keyCached[i]) {
					xResult = {
						key: _keyCached[i],
						value: _itemCached[i]
					};
					break;
				}
			}

			return xResult;
		},
		this.FindByValue = function(value) {
			var xResult = new Array();

			if (isNull(value)) return xResult;

			for (var i = 0; i < _itemCached.length; i++) {
				if (value === _itemCached[i]) {
					xResult.push({
						key: _keyCached[i],
						value: _itemCached[i]
					});
				}
			}

			return xResult;
		}
	}
}
};
// Core Objects Inherits
Core.Canales.prototype = new Core.Collection.BaseCollection();
Core.Secciones.prototype = new Core.Collection.BaseCollection();
Core.Videos.prototype = new Core.Collection.BaseCollection();
Core.Publicidad.Publicity.prototype = new Core.Collection.BaseCollection();
Core.ListaReproduccion.prototype = new Core.Collection.BaseCollection();
var View = {
Status: {
	NULL: 0,
	CREATING: 1,
	READY: 2,
	ERROR: 3
},
StatePlayer: {
	MAIN: 0,
	AUX: 0
},
StatusDownUpIng: {
	Empty: 0,
	Loaded: 1,
	Upping: 2,
	Downing: 3
},
ChronoWeb: {

	PlayingVideo: function(video) {
		var HTMLTituloVideo = $('#'+'titulovideo')[0];
		HTMLTituloVideo.innerHTML = video.name;
	}
},
LectorRSS: function(rssPath, container, itemHeight) {
	// Fields
	var _interval, _tick, _container, _height;

	// Properties
	this.CurrentIndex = -1;
	this.ItemBoxes = null;
	this.Items = null;
	this.NumberItems = 0;
	this.NumberItemsForDisplay = 0;
	this.Status = View.StatusDownUpIng.Empty;

	// Private functions
	this.__builderItem = function(list,initTop,variationTop) {
		var top = initTop;
		var xItemBox = new ItemBox(_container);

		for (var i = 0; i < list.length; i++) {
			xItemBox.Append(list[i], top);
			top += variationTop;
		}
		return xItemBox;
	}
	this._builderCenterItems = function(list) {
		this.ItemBoxes.Center = this.__builderItem(list,0,_height);
	}
	this._builderUpItems = function(list) {
		var xInitTop = 0 - _height * this.NumberItemsForDisplay;
		var xVariation = _height;
		this.ItemBoxes.Up = this.__builderItem(list,xInitTop, xVariation);
	}
	this._builderDownItems = function(list) {
		var xInitTop = _height * (this.NumberItemsForDisplay);
		var xVariation = _height;
		this.ItemBoxes.Down = this.__builderItem(list,xInitTop,xVariation);
	}
	this._stopLoop = function(seconds) {
		if (!isNull(_interval)) {
			_interval = clearInterval(_interval);
			if (seconds > 0) {
				setTimeout("I.LectorRSS.StartLoop();", seconds * 1000);
			}
		}
	}
	this._builderArrows = function(loop) {
		var xArrowLeft, xArrowRight;

		xArrowLeft = document.createElement('A');
		xArrowLeft.id = Config.HTML.RSS_ARROW_UP;
		xArrowLeft.href = "javascript:I.LectorRSS.PrevItems(true);";

		xArrowRight = document.createElement('A');
		xArrowRight.id = Config.HTML.RSS_ARROW_DOWN;
		xArrowRight.href = "javascript:I.LectorRSS.NextItems(true);";

		_container.parentNode.appendChild(xArrowLeft);
		_container.parentNode.appendChild(xArrowRight);

		if (loop) {
			this.StartLoop();
		}
	}

	// Subclass
	var ItemBox = function(container, top) {
		// Fields
		this.Container = container;
		this.Items = new Array(0);
		this.Elements = new Array(0);
		this.Top = top;
		// Functions
		this.Append = function(item, top) {
			if (!isNull(item)) {
				var li, a, b;

				b = document.createElement("B");
				b.innerHTML = item.description[0].Text + " - ";

				a = document.createElement("A");
				a.href = item.link[0].Text;
				a.target = "_blank";
				a.appendChild(b);
				a.innerHTML += item.title[0].Text;

				li = document.createElement("LI");
				li.appendChild(a);
				li.style.top = top + 'px';

				this.Elements.push(li);
				this.Items.push(item);

				this.Container.appendChild(li);
			}
		}
		this.Clear = function() {
			var xElement;
			for (var i = 0; i < this.Elements.length; i++) {
				xElement = this.Elements[i];
				this.Container.removeChild(xElement);
			}
			this.Items = new Array(0);
			this.Elements = new Array(0);
		}
		this.Remove = function(item) {
			var xItem;
			for (var i = 0; i < this.Items.length; i++) {
				if (item == this.Items[i]) {
					this.Container.removeChild(xItem);
					this.Items.splice(i,1);
					this.Elements.splice(i,1);
					break;
				}
			}
		}
	}


	// Public Functions
	this.Init = function() {
		if (this.Items.length == 0) throw new Error('No se puede iniciar el LectorRSS porque la RSS es err\u00F3nea o est\u00E1 vac\u00EDa.');

		this.NumberItems = this.Items.length;
		if (this.NumberItems > 0) {
			this.CurrentIndex = 0;
		}
		if (this.NumberItems > this.NumberItemsForDisplay) {

			var xListItems;

			//Up
			xListItems = new Array(0);
			while (xListItems.length < this.NumberItemsForDisplay) {
				var i = this.CurrentIndex - this.NumberItemsForDisplay + xListItems.length;
				if (i < 0) {
					i = this.NumberItems + i;
				}
				xListItems.push(this.Items[i])
			}
			this._builderUpItems(xListItems);

			// Center
			xListItems = new Array(0);
			while (xListItems.length < this.NumberItemsForDisplay) {
				var i = this.CurrentIndex + xListItems.length;
				if (i >= this.NumberItems) {
					i = this.NumberItems - i;
				}
				xListItems.push(this.Items[i]);
			}
			this._builderCenterItems(xListItems);

			// Down
			xListItems = new Array(0);
			while (xListItems.length < this.NumberItemsForDisplay) {
				var i = this.CurrentIndex + this.NumberItemsForDisplay + xListItems.length;
				if (i >= this.NumberItems) {
					i = this.NumberItems - i;
				}
				xListItems.push(this.Items[i]);
			}
			this._builderDownItems(xListItems);

			this._builderArrows(true);
		} else {
			var xListItems = new Array();
			for (var i = 0; i < this.NumberItems; i++) {
				xListItems.push(this.Items[i]);
			}
			this._builderCenterItems(xListItems);
		}

		this.Status = View.StatusDownUpIng.Loaded;
	}
	this.NextItems = function(stopLoop) {
		var xUpItems, xCenterItems, xListNextItems, xUpTops, xCenterTops;

		if (this.Status == View.StatusDownUpIng.Loaded) {
			this.Status = View.StatusDownUpIng.Upping;

			// preparo la lista de los siguientes items
			xListNextItems = new Array(0);
			while (xListNextItems.length < this.NumberItemsForDisplay) {
				var i = this.CurrentIndex + this.NumberItemsForDisplay + xListNextItems.length;
				if (i >= this.NumberItems) {
					i = i - this.NumberItems;
				}
				xListNextItems.push(this.Items[i]);
			}

			// get TOPs...
			xUpTops = new Array(0);
			for (var i = 0; i < this.ItemBoxes.Up.Elements.length; i++) {
				var xTop = this.ItemBoxes.Up.Elements[i].style.top;
				xUpTops.push(xTop);
			}
			xCenterTops = new Array(0);
			for (var i = 0; i < this.ItemBoxes.Center.Elements.length; i++) {
				var xTop = this.ItemBoxes.Center.Elements[i].style.top;
				xCenterTops.push(xTop);
			}

			// set TOPs...
			for (var i = 0; i < this.ItemBoxes.Center.Elements.length; i++) {
				var xItem = this.ItemBoxes.Center.Elements[i];
				xItem.style.top = xUpTops[i];
			}
			for (var i = 0; i < this.ItemBoxes.Down.Elements.length; i++) {
				var xItem = this.ItemBoxes.Down.Elements[i];
				xItem.style.top = xCenterTops[i];
			}

			// borro los items q ya no sirven y los rehubico, construyo los nuevos items
			this.ItemBoxes.Up.Clear();
			this.ItemBoxes.Up = this.ItemBoxes.Center;
			this.ItemBoxes.Center = this.ItemBoxes.Down;
			this._builderDownItems(xListNextItems);

			// set this.CurrentIndex
			this.CurrentIndex = (this.CurrentIndex + this.NumberItemsForDisplay);
			if (this.CurrentIndex >= this.NumberItems) {
				this.CurrentIndex = (this.CurrentIndex - this.NumberItems);
			}

			// reviso Loop
			if (stopLoop) {
				this._stopLoop(Config.Player.TimeLoopRSS * 2);
			}

			this.Status = View.StatusDownUpIng.Loaded;
		}
	}
	this.PrevItems = function(stopLoop) {
		var xCenterItems, xDownItems, xListPrevItems, xCenterTops, xDownTops;

		if (this.Status == View.StatusDownUpIng.Loaded) {
			this.Status = View.StatusDownUpIng.Downing;

			// preparo la lista de los siguientes items
			xListPrevItems = new Array(0);
			while (xListPrevItems.length < this.NumberItemsForDisplay) {
				var i = this.CurrentIndex - this.NumberItemsForDisplay + xListPrevItems.length;
				if (i < 0) {
					i = this.NumberItems + i;
				}
				xListPrevItems.push(this.Items[i])
			}

			// get TOPs...
			xCenterTops = new Array(0);
			for (var i = 0; i < this.ItemBoxes.Center.Elements.length; i++) {
				var xTop = this.ItemBoxes.Center.Elements[i].style.top;
				xCenterTops.push(xTop);
			}
			xDownTops = new Array(0);
			for (var i = 0; i < this.ItemBoxes.Down.Elements.length; i++) {
				var xTop = this.ItemBoxes.Down.Elements[i].style.top;
				xDownTops.push(xTop);
			}

			// set TOPs...
			for (var i = 0; i < this.ItemBoxes.Center.Elements.length; i++) {
				var xItem = this.ItemBoxes.Center.Elements[i];
				xItem.style.top = xDownTops[i];
			}
			for (var i = 0; i < this.ItemBoxes.Up.Elements.length; i++) {
				var xItem = this.ItemBoxes.Up.Elements[i];
				xItem.style.top = xCenterTops[i];
			}

			// borro los items q ya no sirven y los rehubico, construyo los nuevos items
			this.ItemBoxes.Down.Clear();
			this.ItemBoxes.Down = this.ItemBoxes.Center;
			this.ItemBoxes.Center = this.ItemBoxes.Up;
			this._builderUpItems(xListPrevItems);

			// set this.CurrentIndex
			this.CurrentIndex = (this.CurrentIndex - this.NumberItemsForDisplay);
			if (this.CurrentIndex < 0) {
				this.CurrentIndex = (this.NumberItems + this.CurrentIndex);
			}

			// reviso Loop
			if (stopLoop) {
				this._stopLoop(Config.Player.TimeLoopRSS * 2);
			}

			this.Status = View.StatusDownUpIng.Loaded;
		}
	}
	this.StartLoop = function() {
		_interval = setInterval("I.LectorRSS.NextItems();", Config.Player.TimeLoopRSS * 1000)
	}

	// Constructor
	_container = $('#'+container)[0];
	_height = itemHeight;
	this.ItemBoxes = {
		Up: null,
		Center: null,
		Down: null
	};
	this.NumberItemsForDisplay = 2;

},
WebPlayer: function() {

	// Fields
	var builder = new View.HTMLBuilder();
	var canalesDisplayed = new Core.Canales();
	var seccionesDisplayed = new Core.Secciones();
	var videosDisplayed = new Core.Videos();
	var contadorBuffering = 0;
	var videosSteppedByBuffering = 0;
	var errorMessageShowed = false;

	this.CurrentChannelDisplayed = undefined;
	this.CurrentSeccion = null;
	this.CurrentSkin = Config.Player.skinDefault;
	this.LectorRSS = null;
	this.PlayerMain = null;
	this.PlayerAux = null;
	this.Publicidad = null;
	this.Chrono = null;
	this.Builder = function() {
		return builder;
	};

	// Public Functions
	this.CheckSpecialInfo = function() {
		var strFunction = '' +
		   ' var xSpecialText = data;\n' +
		   ' if (typeof xSpecialText=="string" && xSpecialText.length>0) {\n' +
		   '	 if (Config.Player.timeLoopSpecialInfo/1000/xSpecialText.length/2 < 12) {\n' +
		   '		 xSpecialText = xSpecialText.split(\r\n);\n' +
		   '		 I.Builder().ViewSpecialInfo(xSpecialText,0);\n' +
		   '	 } else {\n' +
		   '		 throw new Error("Mensaje especial no valido. Demasiado largo.");\n' +
		   '	 }\n' +
		   ' }';
		var xSpecialText = Data.LoadFile(Config.Player.fileSpecialInfo,false,strFunction);
	};
	this.GoChannel = function(channel) {
		if (Config.Player.publicityEnabled == true) {
			builder.clearPublicidad(DTO.Publicidad.Owners.CHANNEL);
			if (this.Publicidad.Owner == DTO.Publicidad.Owners.CHANNEL) {
				this.Publicidad.Stop();
			}
		}

		this.CurrentChannelDisplayed = canalesDisplayed.FindById(channel);
		this.Start(false);
	};
	this.HideDescription = function() {
		builder.HideDescription();
		
		var video = I.PlayerMain.ListaReproduccion.GetCurrentItem();
		if (video.rotator) {
			if (typeof video.rotator == "string") {
				if (video.rotator.length > 0) {
					this.ViewImageRotator(video.rotator);
				}
			}
		}
	};
	this.HideHelp = function() {
		builder.HideHelp();
		
		var video = I.PlayerMain.ListaReproduccion.GetCurrentItem();
		if (video.rotator) {
			if (typeof video.rotator == "string") {
				if (video.rotator.length > 0) {
					this.ViewImageRotator(video.rotator);
				}
			}
		}
	};
	this.HideLink = function() {
		builder.HideLink();
		
		var video = I.PlayerMain.ListaReproduccion.GetCurrentItem();
		if (video.rotator) {
			if (typeof video.rotator == "string") {
				if (video.rotator.length > 0) {
					this.ViewImageRotator(video.rotator);
				}
			}
		}
	};
	this.Next = function(playerID) {
		var xCurrentVideo = this.PlayerMain.GetCurrentVideo();
		if (this.CurrentSeccion.chrono) {
			Core.ChronoPlayer.Next(playerID, this.Chrono);
			return;
		}
		this.next(playerID);
	};
	this.next = function(id) {
		if (!isNull(__PLAYING_LIST) && !isNull(__PLAYING_I)) {
			if (__PLAYING_LIST.length > __PLAYING_I) {
				playing(null,Config.Player.player1);
				return;
			}
		}

		var xVideo;
		switch (id) {
			case Config.Player.player1.attributes.id:
				xVideo = this.PlayerMain.Next();
				break;
			default:
				throw new Error('Player no existente. No puedo saltar el video.');
				break;
		}
		this.playVideo(xVideo,null);
	};
	this.PlayVideo = function(id) {
		var xVideoSelected;

		xVideoSelected = videosDisplayed.FindById(id);
		if (isNull(xVideoSelected)) throw new Error('El video que intenta reproducir no existe.');

		this.playVideo(xVideoSelected,null);
	};
	this.playVideo = function(video,player,start) {
		if (player == null) player = Config.Player.player1;

		// --> paro contador
		clearTimeout(contadorBuffering);

		// Pongo la publicidad de canal
		if (Config.Player.publicityEnabled) {
			//Paro la publicidad
			builder.clearPublicidad(DTO.Publicidad.Owners.VIDEO);
			this.Publicidad.Stop(DTO.Publicidad.Owners.VIDEO);

			var publicitystart,publicityend;

			//PublicityStart
			if (typeof I.CurrentChannelDisplayed.publicityStart == "object") {
				if (video.publicitystart == null) video.publicitystart = [];
				publicitystart = video.publicitystart;
				for (var i = 0; i <I.CurrentChannelDisplayed.publicityStart.length; i++) {
					publicitystart.push(I.CurrentChannelDisplayed.publicityStart[i]);
				}
			}

			//PublicitEnd
			if (typeof I.CurrentChannelDisplayed.publicityEnd == "object") {
				if (video.publicityend == null) video.publicityend = [];
				publicityend = video.publicityend;
				for (var i = 0; i < I.CurrentChannelDisplayed.publicityEnd.length; i++) {
					publicityend.push(I.CurrentChannelDisplayed.publicityEnd[i]);
				}
			}

		}
		// --> reproduzco el nuevo video
		this.PlayerMain.ListaReproduccion.SetLista(videosDisplayed.Item);
		this.PlayerMain.Play(video);
		this.RegistrarVideo(video);

		var xTitle = I.PlayerMain.GetCurrentVideo();
		if (xTitle) xTitle=xTitle.name;
		var xUrl =  View.Page().getURL();
		var xMensaje = this.GetLink(xUrl,video,true);
		
		$('a.btnFacebook').attr("href","http://www.facebook.com/sharer.php?u="+xMensaje+"&t="+xTitle);
		$('#'+player.title).text(video.name);
		$("div[id^='video_']").removeClass("active");
		$('div#video_'+video.id).addClass("active");
		if (typeof video.rotator == "string") {
			if (video.rotator.length > 0) {
				this.ViewImageRotator(video.rotator);
			}
		}

		//resetPlayer(player,video.file,video.streamer);
		playing(video,player,start);

		//quito la publicidad del canal
		if (Config.Player.publicityEnabled) {
			//PublicityStart
			if (typeof I.CurrentChannelDisplayed.publicityStart == "object") {
				for (var i = 0; i <I.CurrentChannelDisplayed.publicityStart.length; i++) {
					video.publicitystart.pop();
				}
			}
			if (typeof I.CurrentChannelDisplayed.publicityEnd == "object") {
				for (var i = 0; i < I.CurrentChannelDisplayed.publicityEnd.length; i++) {
					video.publicityend.pop();
				}
			}
		}
	};
	this.RegistrarVideo = function(video) {
		var xEstadistica = {
			type: 'video',
			videoId: video.id,
			seccionId: this.CurrentSeccion.id,
			canalId: this.CurrentChannelDisplayed.id,
			client:Config.Player.id
		}
		Data.DoGet(Config.Player.phpRegister,xEstadistica);
	}
	this.Scroll = function(bodyID) {

		// Fields
		var body = null, container = null;

		// Constructor
		var Scroll = function(){
			body = $('#'+bodyID)[0];
			if (isNull(body))
				throw new Error('No se puede crear un scroll de un elemento que no existe.');
			else
				container = body.parentNode
		}; Scroll();

		// Functions
		this.Go = function(direction) {
			cronometro = setInterval("I.Scroll('" + bodyID + "').roll(" + direction + ");", 40);
		};
		this.roll = function(direction) {

			switch (direction)
			{
				case 0: // izquierda
					if (parseInt(body.style.marginLeft) >= 0) {
						clearInterval(cronometro);
					} else {
						this.moveRightEjeX();
					}
					break;
				case 1: // derecha
					if (parseInt(body.style.marginLeft) < (container.offsetWidth - body.offsetWidth)) {
						clearInterval(cronometro);
					} else {
						this.moveLeftEjeX();
					}
					break;
			}
		};
		this.Stop = function() {
			clearInterval(cronometro);
		};
		this.moveRightEjeX = function() {
			body.style.marginLeft = (parseInt(body.style.marginLeft) + 10) + 'px';
		};
		this.moveLeftEjeX = function() {
			body.style.marginLeft = (parseInt(body.style.marginLeft) - 10) + 'px';
		};

		return this;
	};
	this.SendCurrentVideo = function() {
		var xVideo = this.PlayerMain.GetCurrentVideo();
		if (Core.Videos().SendVideo(xVideo)) {
			this.HideLink();
		}
	};
	this.SetChrono = function(chronoID) {
		var xSeccionSelected = seccionesDisplayed.FindById(chronoID);
		if (isNull(xSeccionSelected)) return null;

		if (xSeccionSelected.chrono) {
			this.CurrentSeccion = xSeccionSelected;
			seccionesDisplayed.SetCurrentItem(xSeccionSelected);

			if (this.Publicidad) { this.Publicidad.Stop();}
			this.SetSkin(xSeccionSelected.skin);
			getElement(Config.HTML.LISTAREPRODUCCION_TITULO).innerHTML = xSeccionSelected.name;

			this.Chrono = new Core.Chrono();
			this.Chrono.Init();

			return true;
		}
		return false;
	};
	this.SetPlayListChrono = function(playList, currentVideo) {
		this.PlayerMain.ListaReproduccion.SetLista(playList);
		this.PlayerMain.ListaReproduccion.SetCurrentItem(currentVideo);
		builder.SetPlayListChrono(playList,currentVideo);
	};
	this.SetSkin = function(skin) {
		if (isNull(skin)) return;
		if (isEmptyString(skin)) return;
		if (isNull(this.CurrentChannelDisplayed)) return;
		if (this.CurrentSkin != skin) {
			Config.Player.pathImages = "skins/" + skin + "/";
			$("#skin")[0].href = "skins/" + skin + "/css/skin.css";
			var xNodes = $('img');

			if (!xNodes) return;
			for (var i = 0; i < xNodes.length; i++) {
				var xFileName = xNodes[i].src.split("/").pop();
				xNodes[i].src = "skins/" + skin + "/imagenes/" + xFileName;
			}
			this.CurrentSkin = skin;
		}
	};
	this.Start = function(checkUrl,doResizer) {
		var xStartSeccion = undefined;
		var xStartVideo = undefined;


		// set size player
		if (doResizer) builder.Resizer();

		// canales
		canalesDisplayed.LoadData();
		if (canalesDisplayed.Count() == 0) {
			showError('No existe la lista de canales del player.');
		}

		// canal --> secciones...
		if (checkUrl) {
			var cidParam = View.Page().QueryString("cid");
			if (!isNull(cidParam)) {
				if (!isEmptyString(cidParam)) {
					this.CurrentChannelDisplayed = canalesDisplayed.FindById(cidParam);
				}
			}
		}

		if (isNull(this.CurrentChannelDisplayed)) {
			this.CurrentChannelDisplayed = canalesDisplayed.GetStartingChannel();
		}

		// Set skin ...
		this.SetSkin(this.CurrentChannelDisplayed.skin);

		// and builder secciones
		seccionesDisplayed.LoadDataOfChannel(this.CurrentChannelDisplayed);
		builder.ListaSecciones(seccionesDisplayed);

		// publicidad...
		if (Config.Player.publicityEnabled == true) {
			if (this.Publicidad == null) this.Publicidad = new Core.Publicidad.Publicity();
			this.Publicidad.LoadData();
		}

		// set special info
		if (Config.Player.marqueeEnabled == true){
			setInterval("I.CheckSpecialInfo()", Config.Player.timeLoopSpecialInfo)
		}

		// secciones --> videos...
		if (checkUrl) {
			var sidParam = View.Page().QueryString("sid");
			if (!isNull(sidParam))
				xStartSeccion = seccionesDisplayed.FindById(sidParam);
		}
		if (isNull(xStartSeccion)) {
			xStartSeccion = seccionesDisplayed.GetStartingSeccion();
		}
		
		if (!isNull(xStartSeccion)) {
			// videos...
			var vidParam;
			if (checkUrl) {
				var vidParam = View.Page().QueryString("vid");
				if (vidParam == "") vidParam = null;
			}

			// play video
			this.ViewSeccion(xStartSeccion.id,vidParam);
			if (!vidParam){
				var xVideo = this.PlayerMain.ListaReproduccion.GetItemStart();
				this.playVideo(xVideo);
			}

			return true;
		}
	};
	this.StepVideo = function(id) {
		videosSteppedByBuffering++;
		this.next(id);
	};
	this.ViewDescription = function(id) {
		var xVideoSelected;

		for (var i in I.PlayerMain.ListaReproduccion.Item) {
			var xVideoItem = I.PlayerMain.ListaReproduccion.Item[i];
			if (xVideoItem.id == id) {
				xVideoSelected = xVideoItem;
				break;
			}
		}
		if (xVideoSelected == null) xVideoSelected = videosDisplayed.FindById(id);
		if (isNull(xVideoSelected)) return;

		builder.ViewDescription(xVideoSelected);
	};
	this.ViewImageRotator = function(listImages) {
		builder.ViewImageRotator(listImages);
	};
	this.ViewHelp = function() {
		builder.ViewHelp();
	};
	this.ViewInfoPublicidad = function(result) {
		builder.ViewInfoPublicidad(result);
	};
	this.ViewLink = function() {
		var xVideo = this.PlayerMain.GetCurrentVideo();

		var xUrl =  View.Page().getURL();
		var xMensaje = this.GetLink(xUrl,xVideo);

		xMensaje = replace(Config.Player.sendvideo_body, '[XXX]', xMensaje);
		builder.ViewLink(xMensaje);
	};
	this.GetLink = function(url,video,parse) {
		var xLink = '';
		if (url == undefined) url = '';
		for (var i = 0; i < url.length; i++) {
		    if (xLink == "&") break;
		    xLink += url.charAt(i);
		}
		if (isNull(I.CurrentSeccion) || isNull(I.CurrentChannelDisplayed)) {
		    throw new Error('Video mal formado. No se puede generar una ruta v\u00E1lida.');
		} else {
		    xLink += "?cid=" + I.CurrentChannelDisplayed.id;
		    xLink += "&sid=" + I.CurrentSeccion.id;
		    if (video != null) xLink += "&vid=" + video.id;
		}
		if (parse) {
		    xLink = replace(xLink,":","%3A");
		    xLink = replace(xLink,"?","%3F");
		    xLink = replace(xLink,"=","%3D");
		    xLink = replace(xLink,"&","%26");
		}
		
		return xLink;
	};
	this.ViewRss = function(path) {
		var div, ul;

		div = document.createElement("div");
		div.id = Config.HTML.PANELRSS;

		ul = document.createElement("UL");
		ul.id = Config.HTML.RSS_UL;

		div.appendChild(ul);
		contenedor.appendChild(div);

		this.LectorRSS = new View.LectorRSS(path, Config.HTML.RSS_UL, 30);
		Data.RSS.Get(path, " \nI.LectorRSS.Items = xData.channel[0].item;\n I.LectorRSS.Init();");

	};
	this.ViewSeccion = function(id,video) {
		var xSeccionSelected = seccionesDisplayed.FindById(id);
		$("div[id^='seccion_']").removeClass("active");
		$('div#seccion_'+id).addClass("active");
		if (typeof xSeccionSelected == "object") {
			if (xSeccionSelected.chrono == "true") {
				this.CurrentSeccion = xSeccionSelected;
				this.SetChrono(id);
			} else if (videosDisplayed.LoadDataOfSeccion(xSeccionSelected)) {
				this.CurrentSeccion = xSeccionSelected;
				seccionesDisplayed.SetCurrentItem(xSeccionSelected);

				this.SetSkin(xSeccionSelected.skin);

				getElement(Config.HTML.LISTAREPRODUCCION_TITULO).innerHTML = xSeccionSelected.name;
				this.PlayerMain.ListaReproduccion.SetLista(videosDisplayed.Item);
				if (isNull(this.PlayerMain.ListaReproduccion.GetCurrentItem())) {
					builder.ListaVideos(videosDisplayed);
				} else {
					builder.ListaVideos(videosDisplayed, this.PlayerMain.ListaReproduccion.GetCurrentItem());
				}
				if (video) {
					var xVideo = this.PlayerMain.ListaReproduccion.FindById(video);
					this.playVideo(xVideo,null);
				} else if (xSeccionSelected.autoplay.length > 0) {
					var xVideo = this.PlayerMain.ListaReproduccion.FindById(xSeccionSelected.autoplay);
					this.PlayerMain.ListaReproduccion.SetCurrentItem(xVideo);
					this.playVideo(xVideo,null);
				}
			}
		}
	};
	this.ZoomIn = function(player) {
		$("#"+player.container).animate({ 
			width: "100%",
			height: "100%",
			top: "0",
			left: "0"
		}, 1500 );
		var xRestaurarWindow = getElement("player_restaurar");
		xRestaurarWindow.style.display = "block";
		
		return false;
	};
	this.ZoomOut = function(player) {
		$("#"+player.container).animate({ 
			width: player.width,
			height: player.height,
			top: player.top,
			left: player.left
		}, 1500 );

		var xRestaurarWindow = getElement("player_restaurar");
		xRestaurarWindow.style.display = "none";
	};

	// Private Functions

	// Constructor
	this.WebPlayer = function() {
		
		// --> Player Main
		var player=Config.Player.player1;
		this.PlayerMain = new Core.Player(Config.Player.player1);
		this.PlayerMain.Status = 0;
		if (isNull(this.PlayerMain)) {
			showError(new Error('El objeto PlayerMain est\u00E1 corrupto.'));
		};
		Config.Player.player1.left = $("#"+Config.Player.player1.container).position().left;
		Config.Player.player1.top = $("#"+Config.Player.player1.container).position().top;
		Config.Player.player1.width = $("#"+Config.Player.player1.container).width();
		Config.Player.player1.height = $("#"+Config.Player.player1.container).height();
	};

	this.WebPlayer();
	this.CurrentSkin = Config.Player.skinDefault;
},
HTMLBuilder: function() {

	// Fields
	var mainContainer = getElement(Config.HTML.CONTENEDOR);
	var seccionesContainer = null;
	var videosContainer = null;
	var panelEnviarVideo = getElement(Config.HTML.PANELINFO_ENVIARVIDEO);
	var panelImageRotator = $('#'+Config.HTML.PANELINFO_IMAGEROTATOR);
	var panelAyuda = getElement(Config.HTML.PANELINFO_PANELAYUDA);
	var panelDescripcionVideo = getElement(Config.HTML.PANELINFO_DESCRIPCION);
	var panelInfo = getElement(Config.HTML.PANELINFO);
	var panelTitleInfo = getElement(Config.HTML.PANELTITLEINFO);
	var panelPublicidadInfo;
	var textSpecialInfo = null,iSpecialInfo = null,syncSpecialInfo = null,rollSpecialInfo = null;

	// Constructor
	seccionesContainer = $(Config.HTML.SECCIONES)[0];

	videosContainer = getElement(Config.HTML.LISTAREPRODUCCION_BODY);

	if (isNull(seccionesContainer)) {
		showError(new Error('No ha especificado un contenedor de secciones v\u00E1lido.'));
	}
	if (isNull(videosContainer)) {
		showError(new Error('No ha especificado un contenedor de videos v\u00E1lido.'));
	}

	// Functions

	this.Resizer = function() {
		if (mainContainer.offsetTop < 0) {
			mainContainer.style.marginTop = '0';
			mainContainer.style.top = '0';
		}
	};
	this.SetPlayListChrono = function(playList, currentVideo) {
		this.ClearListaVideos();
		for (var i in playList) {

			if (playList[i].time >= currentVideo.time && playList[i].visible == true) {
				var nodo_image = document.createElement("span");
				nodo_image.className = "nodo_image";
				nodo_image.style.backgroundImage = "url(" + playList[i].image + ")";
				nodo_image.style.backgroundRepeat = "no-repeat";

				var nodo_title = document.createElement("span");
				nodo_title.className = "nodo_title";
				nodo_title.innerHTML = playList[i].name;

				var nodo_descripcion = document.createElement("span");
				nodo_descripcion.className = "nodo_descripcion";
				nodo_descripcion.innerHTML = playList[i].caption;

				var nodo_time = document.createElement("span");
				nodo_time.className = "nodo_time";
				nodo_time.innerHTML = GetFormatHour(playList[i].time);

				var nodo_ver;
				nodo_ver = document.createElement("span");
				nodo_ver.className = "nodo_ver";

				var nodo_longDescription = document.createElement("a");
				nodo_longDescription.className = "nodo_longDescription";
				nodo_longDescription.href = "javascript:I.ViewDescription('" + playList[i].id.toString() + "');";

				var nodo_a = document.createElement("a");
				nodo_a.className = "nodo_a";
				if (!isNull(currentVideo)) {
					if (playList[i].id == currentVideo.id)
						nodo_a.className += " active";
				}
				nodo_a.setAttribute("href", "javascript:I.ViewSeccion('" + I.CurrentSeccion.id + "');");
				nodo_a.appendChild(nodo_image);
				nodo_a.appendChild(nodo_title);
				nodo_a.appendChild(nodo_descripcion);
				nodo_a.appendChild(nodo_time);
				nodo_a.appendChild(nodo_ver);

				var li = document.createElement("div");
				li.appendChild(nodo_a);
				li.appendChild(nodo_longDescription);

				videosContainer.appendChild(li);
			}

		}
	};
	this.ViewLink = function(link) {

		getElement('tbMensaje').value = link;
		this.ViewPanel(panelEnviarVideo);


	};
	this.ViewHelp = function() {
		this.ViewPanel(panelAyuda);
	};
	this.ViewPanel = function(panel) {
		this.resetPanelInfo();
		//this.setOpacity(Config.Player.opacityDefault);
		$('#lrCuerpo div').hide();
		panel.style.display = "block";
	};
	this.ViewDescription = function(video) {
		var strTitulo = video.name;
		var strDescripcion = video.caption;

		// cambio el tÃ­tulo de la descripciÃ³n
		var tituloDescripcion = $("#descripcionVideo_title")[0];
		tituloDescripcion.innerHTML = strTitulo;

		// cambio la descripcion completa del video
		var descripcionLarga = $("#descripcionVideo_cuerpo")[0];
		descripcionLarga.innerHTML = strDescripcion;

		this.ViewPanel(panelDescripcionVideo);
	};
	this.ViewImageRotator = function(pathimages) {
		$.getJSON(pathimages, function(data) {
			var result = "";
			for (var i=0;i<data.imagelist.length;i++){
				result += "<div class=\"s3sliderImage\">\n<a href=\""+data.imagelist[i].link+"\" target=\""+data.imagelist[i].target+"\"><img src=\""+data.imagelist[i].location+"\" /></a>\n<span class=\"" + data.imagelist[i].position + "\"><strong>"+data.imagelist[i].title+"</strong><br />\n"+data.imagelist[i].description+"</span>\n</div>";
			}
			result += "<div class=\"clear s3sliderImage\">";
			
			I.Builder().ViewPanel($("#s3slider")[0]);
			$('#s3sliderContent').html(result);
			$('#s3slider').s3Slider({
				timeOut: 10000
			});
		})
	};
	this.ViewInfoPublicidad = function(result) {
		if (panelPublicidadInfo) {
			if (panelPublicidadInfo.style.display == "block") {
				var xRemaning = parseInt(result.duration - result.position);
				panelPublicidadInfo.innerHTML = replace(Config.Player.infoPublicidad_TextDefault, "XXX", xRemaning.toString());
			}
		}
	};
	this.ViewSpecialInfo = function(text, i) {
		if (syncSpecialInfo != null) clearTimeout(syncSpecialInfo);
		if (rollSpecialInfo != null) clearTimeout(rollSpecialInfo);
		if (typeof text == "object" && typeof i == "number") {
			textSpecialInfo = text;
			iSpecialInfo = i;

			this.refreshSpecialInfo();
			this.rollContainer();
		}

	};
	this.refreshSpecialInfo = function() {
		try {
			var xTime = Config.Player.timeLoopSpecialInfo/(textSpecialInfo.length);
			var xContainer = $('#'+Config.HTML.SPECIALINFO)[0];
			if (iSpecialInfo < textSpecialInfo.length) {
				xContainer.innerHTML = "<div style='margin-left:" + xContainer.offsetWidth + "px'>" + textSpecialInfo[iSpecialInfo] + "</div>";
				iSpecialInfo++;
				syncSpecialInfo = setTimeout(I.Builder().refreshSpecialInfo,xTime);
			} else {
				textSpecialInfo = null;
				iSpecialInfo = null;
				xContainer.innerHTML = "";
				clearTimeout(rollSpecialInfo);
				clearTimeout(syncSpecialInfo);
			}
		} catch (e) {
		//TODO: log error
		}
	};
	this.rollContainer = function() {
		var xTime = Config.Player.timeLoopSpecialInfo/(textSpecialInfo.length);
		var xContainer = $('#'+Config.HTML.SPECIALINFO)[0].childNodes[0];
		var f = 1000/Config.Player.framesPerSecond;
		var w = xContainer.offsetWidth+xContainer.parentNode.offsetWidth;
		var x = f*w/xTime;
		xContainer.style.marginLeft = (parseFloat(xContainer.style.marginLeft) - x).toString() + "px";
		rollSpecialInfo = setTimeout(I.Builder().rollContainer,f);
	};

	this.HideLink = function() {
		this.clearOpacity();
		this.resetPanelInfo();
	};
	this.HideImageRotator = function() {
		this.clearOpacity();
		this.resetPanelInfo();
	};
	this.HideHelp = function() {
		this.clearOpacity();
		this.resetPanelInfo();
	};
	this.HideDescription = function() {
		this.clearOpacity();
		this.resetPanelInfo();
	};
	this.ListaSecciones = function(secciones) {
		seccionesContainer.innerHTML="";
		seccionesContainer.style.left='';

		for (var i = 0; i < secciones.Count(); i++) {
			if (secciones.Item[i].visible == "true") {

				// Creo el A
				var a = document.createElement("a");
				if (secciones.Item[i].tourl.length > 0) {
					if (isUrl(secciones.Item[i].tourl)) {
						a.setAttribute("href", secciones.Item[i].tourl);
						if (typeof secciones.Item[i].target == "string") {
							a.setAttribute("target", secciones.Item[i].target);
						} else {
							a.setAttribute("target", "_blank");
						}
						$(a).addClass(secciones.Item[i].css);

					}
				} else {
					if (secciones.Item[i].tochannel.length > 0) {
						a.setAttribute("href", "javascript:I.GoChannel('" + secciones.Item[i].tochannel + "');");
					}
					else {
						if (secciones.Item[i].listtrack.length > 0) {
							a.setAttribute("href", "javascript:void(I.ViewSeccion('" + secciones.Item[i].id + "'));");
						} else if (eval(secciones.Item[i].chrono) == true) {
							a.setAttribute("href", "javascript:void(I.SetChrono('" + secciones.Item[i].id +"'))");
						}
					}
				}
				var xButtonHTML = Config.Player.buttonSection;
				xButtonHTML = replace(xButtonHTML,"[XXX]",secciones.Item[i].name);
				xButtonHTML = replace(xButtonHTML,"[YYY]",secciones.Item[i].id);
				a.innerHTML = xButtonHTML;

				// Creo el LI (HTMLsection)
				var li = document.createElement("div");

				li.appendChild(a);
				li.id = "seccion_"+secciones.Item[i].id;
				seccionesContainer.appendChild(li);
			}
		}
		if (Config.Player.scroll) {
			setTimeout(function() {
				$(Config.HTML.SECCIONES)[0].style.left = '0';
			},500);
			var api = $(Config.Player.scroll).scrollable({ 
				items:'div.items', size: Config.Player.scrollItems, clickable:false
			});
			if (Config.Player.scrollInited) {
				api.begin();
				api.reload();
			} else {
				Config.Player.scrollInited = true;
			}
		}



	};
	this.ListaVideos = function(videos) {

		this.ClearListaVideos();
		for (var i = 0; i < videos.Count(); i++) {

            if (videos.Item[i].visible=="false") continue;

			var nodo_image = document.createElement("span");
			nodo_image.className = "nodo_image";
			nodo_image.style.backgroundImage = "url(" + videos.Item[i].image + ")";
			nodo_image.style.backgroundRepeat = "no-repeat";

			var nodo_title = document.createElement("span");
			nodo_title.className = "nodo_title";
			nodo_title.innerHTML = videos.Item[i].name;

			var nodo_descripcion = document.createElement("span");
			nodo_descripcion.className = "nodo_descripcion";
			nodo_descripcion.innerHTML = videos.Item[i].caption;

			var nodo_time = document.createElement("span");
			nodo_time.className = "nodo_time";
			nodo_time.innerHTML = videos.Item[i].time;

			var nodo_ver;
			nodo_ver = document.createElement("span");
			nodo_ver.className = "nodo_ver";

			var nodo_longDescription = document.createElement("a");
			nodo_longDescription.className = "nodo_longDescription";
			nodo_longDescription.href = "javascript:I.ViewDescription('" + videos.Item[i].id.toString() + "');";

			var nodo_a = document.createElement("a");
			nodo_a.className = "nodo_a";
			
			nodo_a.setAttribute("href", "javascript:I.PlayVideo('" + videos.Item[i].id.toString() + "',this);");

			nodo_a.appendChild(nodo_image);
			nodo_a.appendChild(nodo_title);
			nodo_a.appendChild(nodo_descripcion);
			nodo_a.appendChild(nodo_time);
			nodo_a.appendChild(nodo_ver);

			var li = document.createElement("div");
			li.appendChild(nodo_a);
			li.id = "video_"+videos.Item[i].id;
			li.appendChild(nodo_longDescription);

			videosContainer.appendChild(li);
		}

	};
	this.clearOpacity = function() {
		$('#lrCuerpo div').show();
		/*
		panelInfo.style.display = 'block';

		if (panelTitleInfo != null) {
			panelTitleInfo.style.backgroundColor = "";
			if (panelTitleInfo.style.filter != undefined) panelTitleInfo.style.filter = "";
			if (panelTitleInfo.style.opacity != undefined) panelTitleInfo.style.opacity = "";
		}
		*/
	};
	this.ClearListaVideos = function() {
		this.clearOpacity();
		this.resetPanelInfo();
		videosContainer.innerHTML = "";
	};
	this.setOpacity = function(opacity) {
		panelInfo.style.display = 'none';

		if (panelTitleInfo != null) {
			panelTitleInfo.style.backgroundColor = Config.Player.backgroundColor;
			if (panelTitleInfo.style.filter != undefined) panelTitleInfo.style.filter = "alpha(opacity=" + opacity + ")";
			if (panelTitleInfo.style.opacity != undefined) panelTitleInfo.style.opacity = opacity/100;
		}
	};
	this.resetPanelInfo = function() {
		var xPaneles = $('#'+Config.HTML.LISTAREPRODUCCION).children();
		for (var i = 0; i < xPaneles.length; i++) {
			if (xPaneles[i].id != Config.HTML.LISTAREPRODUCCION_TITULO || xPaneles[i].id != Config.HTML.LISTAREPRODUCCION_BODY) {
				xPaneles[i].style.display = "";
				if (xPaneles[i].id == "s3slider") {
					xPaneles[i].innerHTML = "<ul id=\"s3sliderContent\"><div class=\"clear s3sliderImage\"></ul>";
				}
			}
		}
	};
	this.clearPublicidad = function(Owner) {

		var _contenedor = getElement('contenedor');
		var xImagen = $('#'+Config.HTML.PUBLICIDAD_IMAGE + '_' + Owner)[0];
		var xTexto = $('#'+Config.HTML.PUBLICIDAD_TEXT + '_' + Owner)[0];
		var xAnimation = $('#'+Config.HTML.PUBLICIDAD_ANIMATION + '_' + Owner)[0];
		var clear = false;

		if (!isNull(xImagen)) {
			clear = true;
			xImagen.innerHTML="";
			xImagen.style.display = 'none';
			xImagen.style.left = '';
			xImagen.style.top = '';
			xImagen.style.width = '';
			xImagen.style.height = '';
			_contenedor.removeChild(xImagen);
		}
		if (!isNull(xTexto)) {
			clear = true;
			xTexto.innerHTML="";
			xTexto.style.display = 'none';
			xTexto.style.left = '';
			xTexto.style.top = '';
			xTexto.style.width = '';
			xTexto.style.height = '';
			_contenedor.removeChild(xTexto);
		}
		if (!isNull(xAnimation)) {
			clear = true;
			xAnimation.innerHTML="";
			xAnimation.style.display = 'none';
			xAnimation.style.left = '';
			xAnimation.style.top = '';
			xAnimation.style.width = '';
			xAnimation.style.height = '';
			_contenedor.removeChild(xAnimation);
		}

		if (clear) this.clearPublicidad(Owner);

	};

	return this;
},
Page: function() {

	// Fields
	this.getURL = function() {
		var url = window.location.href;
		url = unescape(url);
		url = url.replace(/\+/gi, " ");
		url = url.split("?")[0];

		return url;
	};
	this.getParameters = function() {
		var parameters = window.location.href;
		parameters = unescape(parameters);
		parameters = parameters.replace(/\+/gi, " ");
		parameters = parameters.split("?");
		parameters.shift();
		parameters = parameters.join("?");

		return parameters;
	};
	// Functions
	this.QueryString = function(key){
		var url, variable_pos;

		url = this.getParameters();

		variable_pos = url.indexOf(key);

		if (variable_pos != -1) {
			var pos_separador = url.indexOf("&", variable_pos);

			if (pos_separador != -1) {
				return url.substring(variable_pos + key.length + 1, pos_separador);
			}
			else {
				return url.substring(variable_pos + key.length + 1, url.length);
			}
		}
		else {
			return null;
		}
	};

	return this;
}
};

var Config = {
HTML: {
	CONTENEDOR: 'contenedor',


	PANELINFO: 'lrCuerpo',
	PANELTITLEINFO: 'lrTitulo',
	PANELINFO_ENVIARVIDEO: 'enviarVideo',
	PANELINFO_IMAGEROTATOR: 's3sliderContent',
	PANELINFO_PANELVELOCIDAD: 'panelVelocidad',
	PANELINFO_PANELAYUDA : 'panelAyuda',
	PANELINFO_DESCRIPCION: 'descripcionVideo',
	PANELRSS: 'panelRSS',

	PUBLICIDAD_INFO: 'pub_info',
	PUBLICIDAD_IMAGE: 'pub_image',
	PUBLICIDAD_TEXT: 'pub_text',
	PUBLICIDAD_ANIMATION: 'pub_animation',
	RSS_UL: 'ulRSS',
	RSS_ARROW_UP: 'rssArrowUp',
	RSS_ARROW_DOWN: 'rssArrowDown',
	SECCIONES: 'div.items',
	LISTAREPRODUCCION: 'ListaReproduccion',
	LISTAREPRODUCCION_TITULO: 'lrTitulo',
	LISTAREPRODUCCION_BODY: 'lrCuerpo',


	SENDVIDEO_DESTINO: 'tbDestino',
	SENDVIDEO_MENSAJE: 'tbMensaje',
	SPECIALINFO: 'specialInfo'
},
XML: {
	main: 'menu_pestanas.xml',
	publicity: 'publicidad.xml',
	RSS: ''
},
Player: {
	backgroundColor: 'Black',
	buttonSection: '<span></span>[XXX]',
	framesPerSecond: 25,
	flashVersion: '9.0.98',
	fileSpecialInfo: 'mensaje.php',
	host: (document.location.protocol + '//' + document.location.host),
	id: '',
	live: 'eldia_live',
	keyFlowplayer: '',
	infoPublicidad_TextDefault: 'Publicidad: [XXX]s',
	maxBuffering: 700000,
	marqueeEnabled: true,
	opacityDefault: 10,
	path: 'flash/flowplayer.commercial-3.1.1.swf',
	rotator: 'flash/imagerotator.swf',
	pathImages: 'skins/default/imagenes/',
	pathJson: 'json/',
	phpRegister: 'register.php',
	player1: {
		left:'41px',
		top:'157pt',
		width:'536px',
		height:'300px',
		container: 'playerMain',
		holder: 'flvplayer',
		title: 'titulovideo',
		flashvars: {
			abouttext: 'EmiraTV Player 1.4.2',

			aboutlink: 'http://www.emira.tv',
			controlbar: 'over',
			autostart: 'true',
			displayclick: null,
			file: null,
			fullscreen: 'true',
			plugins: null,
			mute: 'false',
			streamer: null,
			stretching: 'exactfit',
			start: 0,
			volume: 100
		},
		params: {
			id: 'flvplayer',
			play: 'true',
			loop: '0',
			menu: 'false',
			quality: 'high',
			scale: 'noscale',
			salign: null,
			wmode: 'transparent',
			bgcolor: '#000000',
			base: null,
			swliveconnect: null,
			flashvars: null,
			devicefont: null,
			seamlesstabbing: null,
			allowscriptaccess: 'always',
			allowfullscreen: 'true',
			allownetworking: null,
			src: 'flash/flowplayer.commercial-3.1.2.swf',
			movie: 'flash/flowplayer.commercial-3.1.2.swf'
		},
		attributes: {
			id: 'flvplayer',
			name: 'flvplayer',
			styleclass: null,
			width: '545',
			height: '302'
		}
	},
	publicityEnabled: false,
	scroll: null,
	scrollInited: false,
	scrollItems: 10,

	sendvideo_subject: 'Te recomiendo este video',
	sendvideo_body: 'Mira el video que adjunto en esta web: [XXX]',
	skinDefault: 'default',
	TimeLoopRSS: 15,
	timeLoopSpecialInfo: 30000
}
}

