// JavaScript Document

if (!Upc) {
	var Upc = {};
}
if (!Upc.Component) {
	Upc.Component = {};
}

Upc.apply = function(o, c, defaults){
	// no "this" reference for friendly out of scope calls
	if(defaults){
		Upc.apply(o, defaults);
	}
	if(o && c && typeof c == 'object'){
		for(var p in c){
			o[p] = c[p];
		}
	}
	return o;
};

Upc.applyIf = function(o, c){
	if(o){
		for(var p in c){
			if(Ext.isEmpty(o[p])){ 
				o[p] = c[p]; 
			}
		}
	}
	return o;
};
var thumbs = false;
var bande = true;
var pag = 2;

Upc.Component.DatosPortada = function(config){
	this.url = "";
	this.data = [];
	this.images = [];
	this.idPrincipal = "#notaAltaImagen";
	this.imagePanel = "";
	this.imageCache = "";
	this.textPanel = "";
	this.totalRecords = 0;
	this.seccion = 0;
	this.intervalo = 10000;
	this.tiempo = 0;
	this.size = 636;
	this.nextRecord = 0;
	this.prevRecord = 0
	this.timer = null;
	var total_notas = 0;	
	Upc.apply(this, config);
}

Upc.Component.DatosPortada.prototype = {
	load : function(num_registro, mostrar){
		
		$.ajax({
			url: this.url,
			type: "POST",
			owner: this,
			data: "noticia="+num_registro,
			success: function(res){			
				var res = eval("("+res+")");
				if(this.owner.totalRecords == 0){
					this.owner.totalRecords = res.num_notas;
					this.owner.createThumbs(res.num_notas, num_registro);
					if(res.num_notas > 1){						
					}
				}
				
				if(res.num_notas > 0){
					
					for(var i = 0; i<res.notas.length; i++){
						
						var element = document.createElement("img");
						element.id = 'imagenAlta'+res.notas[i].id_thumb;
						element.src = res.notas[i].ruta_imagen;					
						$(element).css("width", this.owner.size+"px");
						$(element).removeAttr("height");
						$(element).removeAttr("width");
												
						var owner = this.owner;
						owner.showLoading();
						
						$(element).load(function(){	
												 
							$(owner.imageCache).append(this);
							$("#"+this.id).removeAttr("height");
							$("#"+this.id).removeAttr("width");
							owner.hideLoading();
						});
						this.owner.data.push(res.notas[i]);
						this.owner.images.push(res.notas[i]);						
					}
					if(mostrar){
						this.owner.showImage(num_registro);
					}				
				}				
			}			
		});
	},
	
	createThumbs : function(num, num_registro){		
		var obj = this;		
		$.ajax({
			url: "request/requestPortadaAltaThumbs.php?seccion="+obj.seccion,
			type: "POST",
			owner: this,
			data: "noticia="+num_registro,
			success: function(res){
				var res = eval("("+res+")");				
				var num_paginas = (Math.round(res.num_notas / 6)+1);
				obj.total_notas = res.num_notas;			
				/*Crea las imagenes thumb*/
				if(res.num_notas > 0){					
					for(var j = 1; j < (num_paginas); j++){	
						var divmain = document.createElement("div");								
						divmain.id = "pagina"+j;
						$("#contedorThumbsDetalles").append(divmain);
						//$("#pagina" + j).addClass("notaAltaThumbs"+j);						
						
						divContenedorThumbs = document.createElement("div");
						divContenedorThumbs.id = "ContenedorThumb"+j;
						$("#pagina" + j).append(divContenedorThumbs);					
						
						$("#ContenedorThumb"+j).css("background-color","#483f38");
						
						divContenedorDetalles = document.createElement("div");
						divContenedorDetalles.id = "ContenedorDetalles"+j;
						$("#pagina" + j).append(divContenedorDetalles);						
						
						$("#ContenedorDetalles"+j).addClass("bgGrisObscuroDegradado");						
					}				
					
					var cont = 0
					
					for(var j = 1; j < (num_paginas); j++){							
						
						for(var i = cont; i < (j * 6) && i <= (obj.total_notas - 1); i++){							
							
							var div1 = document.createElement("div");
							div1.id = "notaAltaDiv"+i;
							$("#ContenedorThumb" + j).not($("div.cloned")).append(div1);
							
							var eldiv = document.createElement("div");
							eldiv.id = "notaAltaThumbDiv"+i;						
							$("#notaAltaDiv"+i).not($("div.cloned")).append(eldiv);
							
							var el = document.createElement("img");
							el.id = "notaAltaThumb"+i;
							
							el.src = res.notas[i].ruta_imagen_thumb;																			
							$(el).removeAttr("height");
							$(el).css("width","90px");							
							
							el.setAttribute("class", "notaAltaThumb");						
							$(el).click(function(){
								obj.showImageThumb($(this).attr("id"));								
							});
							
							if(i == 0){
								$(el).css("margin-left", "0px");
							}
							
							$("#notaAltaThumbDiv"+i).not($("div.cloned")).append(el);							
							
							/*Elementos debajo de las imagenes thumb*/
							
							var divDetalle = document.createElement("div");
							divDetalle.id = "detallesThumbDiv"+i;
							$("#ContenedorDetalles" + j).append(divDetalle);
							$("#detallesThumbDiv" + i).css("width","95px");
							$("#detallesThumbDiv" + i).css("padding-left","10px");
							$("#detallesThumbDiv" + i).css("text-align","left");
							
							$("#detallesThumbDiv"+i).append("<span class='TextoNaranja'>"+res.notas[i].seccion+"</span>");
							$("#detallesThumbDiv"+i).append("<div style='width:84px; height:42px; overflow:hidden'><a class='TextoGrisObscuro' href='publicacion.php?noticia="+res.notas[i].nota+"'>"+res.notas[i].titulo+"</a></div>");
							cont = cont + 1;
						}			
							
					}
					$("#chained").scrollable({
						circular: false, mousewheel: false, next:'.next1', prev:'.prev1'
						}).navigator().autoscroll({
							interval:00000,
							autoplay:false							
					});				
					api = $("#chained").data("scrollable");
					thumbs = true;
					$(".cloned").remove();
					$(".items").css("left","0px");
				}//end if					
					
			}//end success				
		});		
	},	
	textTpl : function(rec){
		
		var relaciones = "";
		var padding_left = 0;
		
		if(rec.rel_aud > 0){			
			relaciones += "<a style='text-decoration:none' onclick='JavaScript: ventanaAudio("+'"audio='+rec.nota+'"'+")'><span class='MasterSprite audioIcon'><span class='MasterSprite audioIcon'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></a>";
		}
		if(rec.rel_gal > 0){			
			relaciones += "<a class='TextoGrisMuyObscuro linkGaleria' style='text-decoration:none'  href='request/requestFotogaleria.php?noticia="+rec.nota+"'><span class='MasterSprite galeriaIcon'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></a>";
		}
		if(rec.rel_vid > 0){			
			relaciones += "<a style='text-decoration:none' href='JavaScript: ventanaVideo("+'"id_nota_video='+rec.nota+'"'+")'><span class='MasterSprite videoIcon'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></a>";
		}
		/*if(rec.rel_pod > 0){			
			relaciones += "<span class='MasterSprite podcastIcon'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>";
		}*/
		
		var rel = "";
		if(rec.rel_aud == 0 && rec.rel_gal == 0 && rec.rel_vid == 0 && rec.rel_not == 0){
			rel = "";
			padding_left = 0;
		}
		else{
			rel = relaciones;
			if(rel != "")
				padding_left = 10;
		}
		
		var fecha;
		if(rec.esdeldia == "S"){
			fecha = "<b>"+rec.hora+"</b>";
		}else{
			fecha = rec.fecha;
		}
		
		/*var tpl = [
			'<div style="width:611px; padding:12px; float:left;">',
				'<table>',
				'<tr><td align="left" vaign="top"><span class="PortadaAltaSeccion TextoBlanco"><b>'+rec.seccion+'</b></span></td></tr>',
				'<div style="text-align:left; float:left; width:610px; height:22px; overflow:hidden"><a class="PortadaAltaTitulo TextoNaranja TextoGrande" href="publicacion.php?noticia='+rec.nota+'"><b>'+rec.titulo+'</b></a></div>',
				'<br />',
				'<div class="PortadaAltaFecha TextoAmarillo TextoChico" style="float:left">'+fecha+'&nbsp Por '+rec.author+'</div>',
				'',
				'<div style="text-align:left; float:left; width:569px;" class="PortadaAltaSumario TextoBlanco"><span style="padding-right:'+padding_left+'px">'+rec.sumario+'</span>'+rel+' </div><br />',
				'</table>',
			'</div>'			
			];*/
		
		var tpl = [
			'<div style="width:611px; float:left; height:81px; overflow:hidden; text-align:left; padding:12px;">',
				'<table cellpadding="0" cellspacing="0" border="0" style="float:left;">',
				'<tr><td align="left" valign="top"><span class="PortadaAltaSeccion TextoBlanco"><b>'+rec.seccion+'</b></span></td></tr>',
				'<tr><td align="left" valign="top"><a class="PortadaAltaTitulo TextoNaranja TextoGrande" href="publicacion.php?noticia='+rec.nota+'"><b>'+rec.titulo+' </b></a>',
				'</td></tr>',
				'<tr><td align="left" valign="top"><span class="PortadaAltaFecha TextoAmarillo TextoChico">'+fecha+'&nbsp Por '+rec.author+'</span></td></tr>',
				'',
				'<tr><td align="left" valign="top"><div style="height:29px; overflow:hidden"><span class="PortadaAltaSumario TextoBlanco" style="padding-right:'+padding_left+'px;">'+rec.sumario+' &nbsp;&nbsp;&nbsp;'+rel+'</span></div></td></tr> ',
				'</table>',
			'</div>'			
			];
		
		
		
		return tpl.join("");
	},
	
	updatePrevNext : function(num){
	
		this.prevRecord = (num == 0) ? this.totalRecords - 1 : num - 1;
			
		this.nextRecord = num + 1;

		if(this.nextRecord >= this.totalRecords){
			this.nextRecord = 0;
		}
		if(!this.find(this.nextRecord)){
			this.load(this.nextRecord, false);
		}
			//this.createTimer();
	},
	
	showText : function(num){		
		var obj = this;
		if(obj.textPanel == ""){
			obj.updatePrevNext(num);
		} else {
			$(obj.textPanel).fadeOut('fast', function(){
				$(this).empty();
				$(this).append(obj.textTpl(obj.find(num)));
				$(this).fadeIn('fast');				
				obj.updatePrevNext(num);				
			});
		}
	},
	
	showImageThumb : function(idThumb){
		
		var id = idThumb.replace("notaAltaThumb", "");
		$("#notaAltaThumb"+id).addClass("notaAltaActiva");
		$("#notaAltaThumbDiv"+id).css("padding-top","20px");
		$("#notaAltaThumbDiv"+id).addClass("flechaArribaGris");
		$("#notaAltaThumb"+id).css("border","#e2702a 1px solid");
		$("#notaAltaDiv"+id).css("background-color","#000");
		$("#detallesThumbDiv"+id).css("visibility","hidden");
		this.stopTimer();
		this.showImage(parseInt(id));
	},
	
	find : function(num){
		for(var i = 0; i < this.data.length; i++){
			if(this.data[i].id_thumb == num){
				return this.data[i];
			}
		}
		return false;
	},
	
	
	showImage : function(num){		
		var obj = this;
		var cont = 0;
		if(!num && num != 0) {num = this.nextRecord; }
		var record = this.find(num);
		
		if(record){			
			$("#notaAltaThumb"+(obj.nextRecord - 1)).removeClass("notaAltaActiva");
			$("#notaAltaThumbDiv"+(obj.nextRecord - 1)).css("padding-top","7px");						
			$("#notaAltaThumbDiv"+(obj.nextRecord - 1)).removeClass("flechaArribaGris");
			$("#notaAltaThumb"+(obj.nextRecord - 1)).css("border","none");
			$("#notaAltaDiv"+(obj.nextRecord - 1)).css("background-color","#483f38");
			$("#detallesThumbDiv"+(obj.nextRecord - 1)).css("visibility","visible");
			
			var cont = 0;
			if(!$("#imagenAlta"+num, $(obj.imageCache)).length){	
				//obj.stopTimer();
				var element = document.createElement("img");
				element.id = 'imagenAlta'+num;
				element.src = record.ruta_imagen;
				$(element).css("width", obj.size+"px");
				$(element).css("cursor","pointer"); 
				if (record.publicacion) {
					
				}
				$(element).removeAttr("height");
				$(element).removeAttr("width");			
				
				$(element).load(function(){					 		
									
					$("#"+element.id).removeAttr("height");
					$("#"+element.id).removeAttr("width");
					
					$(obj.imageCache).append(element);
					obj.hideLoading();							
					obj.showImage(num);
					
				});
				$(element).error(function(){
					obj.showImage(num);
				});
				
			} else {
				
				var posicion = false;
				obj.hideLoading();
				
				$(obj.imagePanel).fadeOut('fast', function(){
					$(obj.imagePanel).unbind();
					if(record.onclick){
						$(obj.imagePanel).click(function(){
							eval(record.onclick);
						})
					}	
					
					$("#notaAltaThumb"+num).addClass("notaAltaActiva");
					$("#notaAltaThumbDiv"+num).css("padding-top","20px");
					$("#notaAltaThumbDiv"+num).addClass("flechaArribaGris");
					$("#notaAltaThumb"+num).css("border","#e2702a 1px solid");
					$("#notaAltaDiv"+num).css("background-color","#000");
					$("#detallesThumbDiv"+num).css("visibility","hidden");					
					
					for(var x = 0; x < obj.total_notas; x++ ){
						if(x != num){
							$("#notaAltaThumb"+(x)).removeClass("notaAltaActiva");
							$("#notaAltaThumbDiv"+(x)).css("padding-top","7px");						
							$("#notaAltaThumbDiv"+(x)).removeClass("flechaArribaGris");
							$("#notaAltaThumb"+(x)).css("border","none");
							$("#notaAltaDiv"+(x)).css("background-color","#483f38");
							$("#detallesThumbDiv"+(x)).css("visibility","visible");
						}
					}
					
					if(obj.totalRecords != 1) {
						obj.hideLoading();						
					}
					else{						
						$(obj.imagePanel).children().appendTo(obj.imageCache);				
						$("#imagenAlta"+num).empty();
						$("#imagenAlta"+num).appendTo(obj.imagePanel);						
					}
					
					$(obj.imagePanel).children().appendTo(obj.imageCache);		
					$("#imagenAlta"+num).empty();
					$("#imagenAlta"+num).appendTo(obj.imagePanel);
					
					$(obj.imagePanel).fadeIn('fast');
					if(obj.nextRecord == 0 ){
						$("#notaAltaThumb"+(obj.totalRecords - 1)).removeClass("notaAltaActiva");						
						
					} else {
						/*Acciones para las notas thumbs que NO estan seleccionadas*/
						$("#notaAltaThumb"+(obj.nextRecord - 1)).removeClass("notaAltaActiva");
						$("#notaAltaThumbDiv"+(obj.nextRecord - 1)).css("padding-top","7px");						
						$("#notaAltaThumbDiv"+(obj.nextRecord - 1)).removeClass("flechaArribaGris");
						$("#notaAltaThumb"+(obj.nextRecord - 1)).css("border","none");
						$("#notaAltaDiv"+(obj.nextRecord - 1)).css("background-color","#483f38");
						$("#detallesThumbDiv"+(obj.nextRecord - 1)).css("visibility","visible");						
					}
					
					/*Acciones para las notas thumbs que SÍ estan seleccionadas*/					
					/*setTimeout('num1 = '+(obj.nextRecord - 1)+';$("#notaAltaThumb"+(num1)).removeClass("notaAltaActiva");$("#notaAltaThumbDiv"+(num1)).css("padding-top","7px"); $("#notaAltaThumbDiv"+(num1)).removeClass("flechaArribaGris"); $("#notaAltaThumb"+(num1)).css("border","none");$("#notaAltaDiv"+(num1)).css("background-color","#483f38");$("#detallesThumbDiv"+(num1)).css("visibility","visible");',500);				*/
					/*$(obj.imagePanel).children().appendTo(obj.imageCache);		
						$("#imagenAlta"+num).empty();
						$("#imagenAlta"+num).appendTo(obj.imagePanel);*/
					
					
					
					/*if(num == 0){
						setTimeout('api = $("#chained").data("scrollable"); obj = this',2500);
						setTimeout('api.onSeek(function(){num = (this.getIndex() * 6); $("#notaAltaThumbDiv"+num).css("padding-top","20px"); $("#notaAltaThumbDiv"+num).addClass("flechaArribaGris");$("#notaAltaThumb"+num).css("border","#e2702a 1px solid");$("#notaAltaDiv"+num).css("background-color","#000");$("#detallesThumbDiv"+num).css("visibility","hidden"); })',4000);						
					}else{*/
						if(thumbs == true){
							api = $("#chained").data("scrollable");
							setTimeout('$(".linkGaleria").click	(function(){$("#galeria").remove();$("body").append("<div id="+"galeria"+" style="+"display:none;"+"></div>");$("#galeria").load(this.href);return false;});',400);
							
							api.onSeek(function() {							
								$("#notaAltaThumb"+(obj.nextRecord - 1)).removeClass("notaAltaActiva");
								$("#notaAltaThumbDiv"+(obj.nextRecord - 1)).css("padding-top","7px");						
								$("#notaAltaThumbDiv"+(obj.nextRecord - 1)).removeClass("flechaArribaGris");
								$("#notaAltaThumb"+(obj.nextRecord - 1)).css("border","none");
								$("#notaAltaDiv"+(obj.nextRecord - 1)).css("background-color","#483f38");
								$("#detallesThumbDiv"+(obj.nextRecord - 1)).css("visibility","visible");						
								num = (api.getIndex() * 6);
								obj.showImage(num);			
								
								$("#notaAltaThumb"+num).addClass("notaAltaActiva");
								$("#notaAltaThumbDiv"+num).css("padding-top","20px");
								$("#notaAltaThumbDiv"+num).addClass("flechaArribaGris");					
								$("#notaAltaThumb"+num).css("border","#e2702a 1px solid");
								$("#notaAltaDiv"+num).css("background-color","#000");
								$("#detallesThumbDiv"+num).css("visibility","hidden");							
								//obj.showText(num);	
							});	
						}
					//}
					//var numItem = api.getIndex();					
					/*console.log(num);
					console.log(6 * (numItem +1));
					if(num == (6 * (numItem +1)))
						obj.movePageTo(num);*/
					
					
					obj.showText(num);					
				});
				
				}		
			} else {				
				obj.load(num, true);
		}
	},
	
	showNext : function(){
		this.showImage(this.nextRecord);
	},
	
	showPrev : function(){
		this.showImage(this.prevRecord);
	},
	movePageTo: function(num){
		var obj = this;
		var move = $("#chained").data("scrollable");
		//console.log("pagina "+(move.getIndex()+1));				
		move.move((move.getIndex()+1));
	},	
	init : function(){
		var obj = this;			
		this.load(0, true);		
		var self = this;
		$(this.imagePanel).hover(function(){
			//self.stopTimer();
		}, function(){
			//self.createTimer();
		});

		$(this.textPanel).hover(function(){
			//self.stopTimer();
		}, function(){
			//self.createTimer();
		});	
	},
	
	createTimer : function(){
		if(this.totalRecords <= 1) return true;		
		if(this.tiempo == 0 && this.intervalo > 0){
			var t = this;
			this.timer = setInterval(function(){
				t.showImage();
			}, this.intervalo);
			this.tiempo = this.intervalo;
		}		
	},
	
	stopTimer : function(){
		if(this.tiempo > 0){
			var t = this;
			clearInterval(this.timer);
			this.timer = null;
			this.tiempo = 0;
		}
	},
	
	showLoading : function(){
		$("#loadMask", this.idPrincipal).css("z-index", "1000");
		$("#loadMask", this.idPrincipal).css("display", "block");
	},
	
	hideLoading :  function(){
		$("#loadMask", this.idPrincipal).css("z-index", "-1000");
		$("#loadMask", this.idPrincipal).css("display", "none");
	}
}

Upc.Component.ContentView = function(main, config){
	
	if (main) {
		this.main = main;
	}
	
	this.id = '';
	
	this.idCom = "";
	
	this.elDom = '';
	
	/*Url a donde se va realizar la peticion de datos*/
	this.url = '';
	
	this.pageSize =  2;
	
	this.loadSize = 0;
	
	this.updateType = 'innerhtml'; /*json*/
	
	/*Object que guarda la respuesta del evento load mas el callback funcion y config del scroll*/
	this.responseSuccess = '';
	
	//Si ya se visualizo una vez 
	this.firstShow = false;
	
	this.scroll = true;
	
	this.autoPos = true;
	
	this.pagesLoader = [];
	
	// Indica si ya termino de mostrar el contenido (Si tiene animacion se ejecuta hasta que termina la animacion);
	this.showComplete = true;
	
	this.isLoading = false;
	
	this.loadMask = "loadMask";
	
	this.initEventsOnLoad = true;
	
	this.activateTimer = false;
	
	this.timeToChange = 10000;
	
	Upc.apply(this, config);
	
	this.initComponent = function(){
		this.onRender();
	}
	this.initComponent();
};

Upc.Component.ContentView.prototype = {
		
	onRender: function(){
		
		if(this.loadSize == 0){
			this.loadSize = this.pageSize;
		}
		
		if(!this.elDom){
			this.elDom = $('#'+this.id);
		};		

		this.contentDom = $("."+this.cssContentDom, $(this.elDom));	
		this.scrollDom = $("."+this.cssScrollDom, $(this.elDom));	
		
		if (this.scroll) {
			this.scrollBar = new Upc.Component.ScrollBar({
				ownerCt: this,
				elDom: this.elDom, //this.scrollDom,
				targetScroller: this.contentDom,
				movePx: parseInt(this.movePx),
				moveTime: 350,
				autoPos: this.autoPos,
				pageSize: parseInt(this.pageSize),
				loadSize: parseInt(this.loadSize),
				activateTimer: this.activateTimer,
				timeToChange: this.timeToChange
			});
		}
		
		if(this.autoLoad){
			this.load();
		}
		this.initEvents();
	},
	
	firstView: function(){
	
	},
	
	initEvents: function(){
		// Ejemplo para que se sobre escriba la funcionalidad en base a los items cargador via ajax.
		// Por que? el jquery no agrega el evento a los nuevos items generados, cada que cae uno se tiene que setear su evento.
		/*
		var t = this;
		$('.items', $('#idcomponente')).click(function(){
			t.verinfo();										   
		});
		*/
	},
	
	onShow : function(){
		
	},
	
	
	showLoadMask : function(){
		$("."+this.loadMask, $(this.elDom)).css("z-index", "1000");
		$("."+this.loadMask, $(this.elDom)).css("display", "block");
	},
	
	hideLoadMask : function(){
		$("."+this.loadMask, $(this.elDom)).css("z-index", "-1000");
		$("."+this.loadMask, $(this.elDom)).css("display", "none");
	},
	
	load : function(callback, config){
		this.isLoading = true;
		this.showLoadMask();
		var t = this;
		var data;		
		if(!this.params){
			data = '&code='+t.id;
		}else{
			data = this.params;
		}
		
		//if(t.scrollBar){
			data = data +''+'&limit='+t.scrollBar.limit+'&start='+t.scrollBar.start;
		//}
		
		$.ajax({
			type: 'POST',
			url: t.url,
			data: data,
			success: function(response){
				t.isLoading = false;
				t.responseSuccess = {
					response: response,
					callback: callback,
					config: config
				}
				if (t.updateType = 'innerhtml') {
					t.updateInner();
				}else{
					t.updateJson();
				}
				if(t.id == "podcastLista"){
					t.Player();
					$("#player_pause").css("display","block");	
				}
				
				if(t.id == "podcastRecientesLista"){
					t.PlayerRecientes();					
				}
				
				if(t.id == "podcastEscuchadasLista"){
					t.PlayerEscuchados();					
				}
				
				if(t.id == "MMListaNotasMas" || t.id == "comentadasListaNotasMas" || t.id == "leidasListaNotasMas" || t.id == "enviadasListaNotasMas" || t.id == "contenidoModuloHomeDeportes" || t.id == "contenidoModuloHomeEspectaculos" || t.id == "contenidoModuloCartonesActual"){
					t.Slide();					
				}
				
				if(t.id == "fotogaleriaListaMultimedia"){
					t.Galeria();					
				}				
			},
			failure: function(){
			}
		});
	},
	PlayerEscuchados: function(){
		
	},
	PlayerRecientes: function(){
	
	},	
	Player : function(){
		
	},
	Galeria : function(){
		
	},
	Slide : function(){
	},
	updateInner : function(){
		var response = this.responseSuccess.response;
		pos = response.indexOf('|');
		//if(this.scrollBar){
			this.scrollBar.total = parseInt(response.substring(0, pos));
		//}
		var inner = response.substring(pos+1, response.length);
		
		$(this.contentDom).append(inner);
		if(!this.firstShow) {
			this.firstShow = true;
			this.firstView();
			if (this.main != null) {
				this.main.cargar();
			}
		}
			this.hideLoadMask();
		//if(this.scrollBar){
			this.scrollAction();
		//}
		
		
		if(this.initEventsOnLoad){
			this.initEvents();
		}
	},
	
	updateJson : function(){
		var t = this;
		var response = this.responseSuccess.response;
		$(this.contentDom).append(t.tpl);
		this.hideLoadMask();
		this.scrollAction();
		
		if(this.initEventsOnLoad){
			this.initEvents();
		}
	},
	
	scrollAction: function(){
		var r = this.responseSuccess;
		this.scrollBar.page = parseInt(this.pagesLoader.length) + 1;
		this.pagesLoader.push(this.scrollBar.page);
		if (r.callback) {
			//Se ejecuta una funcion de retorno enviando unos parametros.
			this.scrollBar[r.callback](r.config);
			return;
		}
		if(this.activateTimer){
			this.scrollBar.initTimer();
		}
		
		this.scrollBar.pageSize > 0 ? this.scrollBar.disEnableControlsPage() : this.scrollBar.disEnableControls();
	}
	
};


Upc.Component.ScrollBar = function(config){
	
	this.idScrollBar = '';
	
	this.targetScroller = '';

	this.movePx  = 5;
	
	this.moveTime  = 350;
	
	this.moveClck  = true;
	
	this.moveOver  = false;
	
	this.completeMove  = true;
	
	/*Atributos para paginado*/
	this.start = 0;
	
	this.limit = 2;
	
	this.total = 0,
	
	// Cantidad de contenidos (filas, registros; etc) por vista
	this.pageSize = 2;
	
	// Cantidad de registros ques se cargarán por página.
	this.loadSize = 0;
	
	this.autoPos = true;
	
	this.posicionActual = 0;
	
	this.page = 0;
	
	this.pagesContent = [];
	
	// Controles
	this.top = '';
	
	this.bottom = '';
	
	this.left = '';
	
	this.right = '';
	
	//this.limit = 2;
	
	this.activateTimer = false;
	
	this.timer = '';
	
	this.timeToChange = 10000;
	
	Upc.apply(this, config);
	
	this.initComponent = function(){
		this.onRender();
	}
	
	this.initComponent();
};
   
Upc.Component.ScrollBar.prototype = {

	onRender : function(config){
		var t = this;
		
		if(this.loadSize == 0){
			this.loadSize = this.pageSize;
		}
		
		//this.limit = this.pageSize;
		this.limit = this.loadSize;

		this.ctr = {};
		/*Se agrega el tag del Dom a los atributos del objeto scrolbar*/
		$('a[direction]', $(this.elDom)).each(function(){
			var dir = $(this).attr('direction');
			t.ctr[dir] = this;
		});
		
		$(this.targetScroller).css("top", "0px");
		
		this.initEvents();
	},
	
	initEvents : function(){
		var t = this;

		$('a[direction]', $(this.elDom)).click(function(){
			switch ($(this).attr('direction')) {
				case 'top':
					t.onMoveTop(this);
					break;
				case 'bottom':
					t.onMoveBottom(this);
					break;
				case 'left':
					t.onMoveLeft(this);
					break;
				case 'right':
					t.onMoveRight(this);
					break;
			}
		});
	},
	
	onMoveTop : function(tag){
		if($('img', $(tag)).hasClass('disable')) return;
		$('img', $(tag)).addClass('disable');
		
		if(this.autoPos === true){
			var posAct = $(this.targetScroller).position()['top'];
		} else {
			var posAct = this.posicionActual;
		}

		if (!this.pageSize) {
			var posNew = posAct + this.movePx;
		}else{	
			var posNew = posAct + this.movePx; //(this.movePx *  this.pageSize);
			this.page = this.page - 1;
		}
		this.posicionActual = posNew;		
		this.scrollMove({top : posNew+'px'});		
	},
	
	onMoveBottom : function(tag){
		if($('img', $(tag)).hasClass('disable') || this.ownerCt.isLoading) return;
		$('img', $(tag)).addClass('disable');	

		if(this.autoPos === true){
		var posAct = $(this.targetScroller).position()['top'];
		} else {

			var posAct = this.posicionActual;	
		}
		if(!this.pageSize) {//El movimiento va hacer local
			var posNew = posAct - this.movePx;
			this.scrollMove({top : posNew+'px'});
			return;
		}
		
		var posNew = posAct - this.movePx; //(this.movePx *  this.pageSize);

		// Si la pagina no existe se crea; Se pone numero de la pagina ya que es un arreglo y este comienza en 0
		if(!this.ownerCt.pagesLoader[this.page]){
			//this.start = this.start + this.pageSize;
			this.start = this.start + this.loadSize;
			this.ownerCt.isLoading = true;
			this.ownerCt.load('scrollMove', {top : posNew+'px'});
			this.posicionActual = posNew;
		}else{
			this.page = this.page +  1;
			this.scrollMove({top : posNew+'px'});
			this.posicionActual = posNew;
		}
				
	},
	
	onMoveLeft : function(tag){
		if($('img', $(tag)).hasClass('disable')) return;
		$('img', $(tag)).addClass('disable');
		
		if(this.autoPos === true){
		var posAct = $(this.targetScroller).position()['left'];
		//var posNew = posAct - 1;
		} else {
			var posAct = this.posicionActual;	
		}
		if (!this.pageSize) {
			var posNew = posAct - this.movePx;
		}else{	
			var posNew = posAct + this.movePx; //(this.movePx *  this.pageSize);
			this.page = this.page - 1;
		}
		this.posicionActual = posNew;
		this.scrollMove({left : posNew+'px'});	
	},
	
	onMoveRight : function(tag){
		if($('img', $(tag)).hasClass('disable') || this.ownerCt.isLoading) return;
		$('img', $(tag)).addClass('disable');
		if(this.autoPos === true){
		var posAct = $(this.targetScroller).position()['left'];
		} else {
			var posAct = this.posicionActual;	
		}
		if(!this.pageSize) {//El movimiento va hacer local
			var posNew = posAct - this.movePx;
			this.scrollMove({left : posNew+'px'});
			return;
		}
		
		var posNew = posAct - this.movePx; //(this.movePx *  this.pageSize);
		// Si la pagina no existe se crea; Se pone numero de la pagina ya que es un arreglo y este comienza en 0
		
		if(!this.ownerCt.pagesLoader[this.page]){
			
			//this.start = this.start + this.pageSize;
			this.start = this.start + this.loadSize;
			this.ownerCt.load('scrollMove', {left : posNew+'px'});
			this.posicionActual = posNew;
		}else{
			this.page = this.page +  1;
			this.scrollMove({left : posNew+'px'});
			this.posicionActual = posNew;
		}	
		
	},
	
	scrollMove : function(config, fast){
		if(!this.completeMove){ return;}
		this.completeMove = false;
				
		var t = this;
		

		if(!fast) fast = 1;

		$(t.targetScroller).animate(
			config, 
			(t.moveTime / fast), 
			null, 
			function(){
				if(t.activateTimer){
					t.initTimer();
				}
				t.pageSize > 0 ? t.disEnableControlsPage() : t.disEnableControls();
				t.completeMove = true;
			}
		);
	},
	
	disEnableControlsPage : function(v){
		/* Agregar o quitar clase de disable a controles top y left*/
		if(this.page == 1){
			if (this.ctr.top)	$('img', $(this.ctr.top)).addClass('disable'); 
			if (this.ctr.left)	$('img', $(this.ctr.left)).addClass('disable');
		}else{
			if (this.ctr.top)	$('img', $(this.ctr.top)).removeClass('disable'); 
			if (this.ctr.left)	$('img', $(this.ctr.left)).removeClass('disable');
		}
		

		/* Agregar o quitar clase de disable a controles bottom y right*/
		//console.log(Math.ceil(this.total/this.pageSize)+"---"+  this.page);
		
		if(this.page == Math.ceil(this.total/this.pageSize) || this.total == 0){
			if (this.ctr.bottom)	$('img', $(this.ctr.bottom)).addClass('disable'); 
			if (this.ctr.right)		$('img', $(this.ctr.right)).addClass('disable');
		
		}else{
			if (this.ctr.bottom)	$('img', $(this.ctr.bottom)).removeClass('disable'); 
			if (this.ctr.right)		$('img', $(this.ctr.right)).removeClass('disable');
			
		}
	},
	
	disEnableControls : function(v){
		var pos = this.ownerCt.contentDom.position();
		var posValue;
		/* Agregar o quitar clase de disable a controles top y left*/
		if(pos.top >= 0){
			if (this.ctr.top)	$('img', $(this.ctr.top)).addClass('disable'); 
			if (this.ctr.left)	$('img', $(this.ctr.left)).addClass('disable');
		}else{
			if (this.ctr.top)	$('img', $(this.ctr.top)).removeClass('disable'); 
			if (this.ctr.left)	$('img', $(this.ctr.left)).removeClass('disable');
		}
		
		this.ownerCt.firstChildContent = $(':first', this.ownerCt.contentDom);
		if (this.ctr.top) {
			posValue = (this.ownerCt.contentDom.height() + Math.abs(pos.top)) - this.movePx;
		}else{
			posValue = (this.ownerCt.contentDom.height() + Math.abs(pos.left)) - this.movePx;
		}
		
		if(posValue >= this.ownerCt.firstChildContent.height()){
			if (this.ctr.bottom)	$('img', $(this.ctr.bottom)).addClass('disable'); 
			if (this.ctr.right)		$('img', $(this.ctr.right)).addClass('disable');
		}else{
			if (this.ctr.bottom)	$('img', $(this.ctr.bottom)).removeClass('disable'); 
			if (this.ctr.right)		$('img', $(this.ctr.right)).removeClass('disable');
		}
	},
	
	initTimer : function(){
		var t = this;
		clearInterval(t.timer);
		t.timer = setInterval(function(){
			t.onChange();
		}, t.timeToChange);
	},
	
	clearTimer : function(){
		var t = this;
		clearInterval(t.timer);
	},
	
	onChange : function(){
		//Si hay paginas posteriores.
		if(this.page < Math.ceil(this.total/this.pageSize)){ 
			this.onMoveRight(this.ctr.right);
		}else{
			this.page = 1;
			this.scrollMove({left : '0px'}, 10);	
		}
	}
};


