window.addEvent('domready',function(){
	getTheme();
        /*
	$('atheme1').addEvent('click',function(e){
		e.stop();
		setTheme(1);
	});
	$('atheme2').addEvent('click',function(e){
		e.stop();
		setTheme(2);
	});
        */
	$('bnpanelabsolute').setStyle('display','block');
	$('afindtip').addEvent('click',function(e){
		$('divfindtip').fade(0);
		e.stop();
	});
	var skinslide = new Fx.Slide('divskins', {duration: 200, wait:true});
	onStart: skinslide.hide();
        /*
	$('toggler').addEvent('click', function(e){
		e.stop();
		skinslide.toggle();
	});
	if(hTheme == 1)$('toggler').set('html','<img class="askin imgtoggler" src="http://www.tvazteca.com/navegacion/barra/images/togglerb.jpg"/>');
	else $('toggler').set('html','<img class="askin imgtoggler" src="http://www.tvazteca.com/navegacion/barra/images/toggler.jpg"/>');
        */
	var today = new Date();
	$('hechos-divdate').set('html',tellDay(today.getDay()) + ' ' + today.getDate() + ' de ' + tellMonth(today.getMonth()));
	$('hechos-rssmain').setStyle('display','block');
	var minSlide = new Fx.Slide('uptabscont', {duration: 800, wait: true});
	var rssSlide1 = new Fx.Slide('rssslide1', {duration: 800, wait: true});
	var sendComsSlide = new Fx.Slide('divshowcoms', {duration: 800, wait: true});
	onStart: minSlide.hide(), rssSlide1.hide(), sendComsSlide.hide();
	$('uptabscont').setStyle('display','block');
	$('arssSlide1').addEvent('click',function(e){
		e.stop();
		scrollWindow('hechos-rssmain',0);
		rssSlide1.slideIn();
	});
	$('arssSlide2').addEvent('click',function(e){
		e.stop();
		scrollWindow('hechos-rssmain',0);
		rssSlide1.slideIn();
	});
	$('rssclose').addEvent('click',function(e){
		e.stop();
		rssSlide1.slideOut();
	});
	$('alastmin').addEvent('click',function(){
		setLastNews();
	});
	$('amymin').addEvent('click',function(){
		setMyNews();
	});
	if(Browser.Engine.trident){
		var catDivs = $('newCats').getElements('div[class=hechos-newDivCat]');
		catDivs.each(function(item,index){
			$(item).setStyle('padding','0px 5px 0px 5px');
			$(item).setStyle('height','25px');
		});
		$('bodylist').setStyle('height','186px');
	}
	['anewcat1','anewcat2','anewcat3','anewcat4','anewcat5','anewcat6','anewcat7','anewcat8'].each(function(item,index){
		$(item).addEvent('click',function(){
			var box = index + 1;
			updateBin(box);
		});
	});
	catsCookie();
	$('showmin').addEvent('click',function(e){
		e.stop();
		minSlide.show();
		$('hechos-topexpande').fade(0);
		if(!htriggered){
			pushNews(hjson.noticias);
		}
		else
		newsPlay();
	});
	$('hechos-stopmin').addEvent('click',function(e){
		newsStop();
	});
	$('hidemin').addEvent('click',function(e){
		e.stop();
		minSlide.slideOut();
		$('hechos-topexpande').fade(1);
		newsStop();
	});
	$('scrolltomin').addEvent('click',function(e){
		scrollWindow('minanchor',0);
		e.stop();
	});
	$('showcoms').addEvent('click',function(e){
		e.stop();
		sendComsSlide.toggle();
	});
	$('hechos-autoplay').addEvent('click',function(e){
		e.stop();
		stopAutoPlay();
	});
	$('aplist').addEvent('click',function(e){
		e.stop();
		showPlist();
	});
	$('abest').addEvent('click',function(e){
		e.stop();
		showBest();
	});
	$('alastnews').addEvent('click',function(e){
		e.stop();
		showLastNews();
	});
	$('alive').addEvent('click',function(e){
		e.stop();
		showLive();
	});
	$('aplaynext').addEvent('click',function(e){
		e.stop();
		skipToNext();
	});
	$('aactivateplay').addEvent('click',function(){
		autoplayCookie();
	});
	$('hechos-aalert').addEvent('click',function(e){
		e.stop();
		$('hechos-alert').setStyle('display','none');
	});
	$('pagerprev').addEvent('click',function(e){
		e.stop();
		fetchCatPrev();
	});
	$('pagernext').addEvent('click',function(e){
		e.stop();
		fetchCatNext();
	});
	['acat0','acat1','acat2','acat3','acat4','acat5','acat6','acat7','acat8'].each(function(item,index){
		$(item).addEvent('click',function(e){
			e.stop();
			setCat(index);
		});
	});
	$('hechos-vtecaexp').addEvent('click',function(e){
		e.stop();
		expandVideos();
	});
	minSlide.show();
	$('hechos-topexpande').fade('hide');
	pushNews(hjson.noticias);
	//newScroller();
	pushVidNews(vidjson.videonews);
	pushLive(livejson.live);
	pushTriggerLive(livejson.trigger);
	if (bestjson.total > 0) {
		pushBestNews(bestjson.bestnews);
		//$('divbest').tween('background-color', '#8d000c');
		$('divbest').tween('background-color', '#333333');
	}
	detectFlash();
	setCat(0);
	vtkScroller();
	expandVideos();
	fetchv = fetchVideoNews.delay(300000);
	$('txtfind').addEvent('keyup', function(e){
		var event = new Event(e);
		if (event.key == 'enter'){
			var escaped = this.value;
			escaped = escaped.stripScripts();
			escaped = escaped.escapeRegExp();
			escaped = escaped.clean();
			var invalid = false;			
			['SCRIPT','XTERM','FTP','TYPE','CMD','SELECT','INSERT','DROP','WHERE','UPDATE','script','xterm','ftp','type','select','insert','drop','where','update','=','@','%','\\','/','&','<','>'].each(function(item){
				if(escaped.contains(item))invalid = true;
			});
			if(invalid){
				$('txtfind').blur();
				$('hechos-alert').setStyle('top',(document.documentElement.scrollTop + 300).toString() + 'px');
				$('hechos-palert').set('html','El texto de búsqueda es inválido.');
				$('hechos-alert').setStyle('display','block');
				$('hechos-alert').fade('hide');
				$('hechos-alert').fade(1);
			}
			if(escaped.length < 3){
				invalid = true;
				$('txtfind').blur();
				$('hechos-alert').setStyle('top',(document.documentElement.scrollTop + 300).toString() + 'px');
				$('hechos-palert').set('html','El texto de búsqueda debe contener 3 o más caracteres.');
				$('hechos-alert').setStyle('display','block');
				$('hechos-alert').fade('hide');
				$('hechos-alert').fade(1);
			}
			if(escaped != '' && escaped != ' ' && escaped != null && !invalid){
				vtkwrap = vtkwrap + 180;
				var vtkwidth = vtkwrap + 'px';
				$('vtkswrapper').setStyle('width',vtkwrap);
				if(vtkwrap>870 && !vtkscrollable){
					vtkscrollable = true;
					$('hechos-vsl').setStyle('display','block');
					$('hechos-vsl').fade('hide');
					$('hechos-vsl').fade(1);
					$('hechos-vsr').setStyle('display','block');
					$('hechos-vsr').fade('hide');
					$('hechos-vsr').fade(1);
				}
				vtktabs++;
				var nextTab = vtktabs;
				var newtab = new Element('div',{'id':'divcat' + nextTab,'class':'hechos-tab hechos-taboff'});
				var newa = new Element('a',{'id':'acat' + nextTab,'class':'hechos-atabon','href':'javascript:void(0);','onfocus':'blur();','html':this.value + '&nbsp;&nbsp;'});
				var aclose = new Element('a',{'id':'avtkclose' + nextTab,'class':'hechos-aimg noboth','href':'javascript:void(0);'});
				var imgclose = new Element('img',{'class':'hechos-aimg','src':'http://static.hechos.tv/hechos/images2009/closetab.gif'});
				imgclose.inject(aclose);newa.inject(newtab);aclose.inject(newtab);newtab.inject($('vtklimit'),'before');
				escaped = escape(escaped);
				arrFind[nextTab.toString()] = escaped;
				vtkScroller();
				if (vtkscrollable) {
					var lastTab = $('vtkswrapper').getLast('div[id^=divcat]');
					var elX = ($('vtklimit').getPosition($('vtkswrapper'))).x;
					var elXTotal = eval(elX) - 870;
					vtkFxright.set(elXTotal, 0);
				}
				this.blur();this.value = 'Buscar Videos...';
				setCat(nextTab);
				$('acat' + nextTab).addEvent('click',function(e){
					e.stop();
					setCat(nextTab);
				});
				$('avtkclose' + nextTab).addEvent('click',function(e){
					e.stop();
					var tmpid = this.id
					var intId = tmpid.replace(/avtkclose/,'');
					intId = eval(intId);
					var isOn = $('divcat' + intId).hasClass('hechos-tab hechos-tabon');
					if(isOn){
						vtkFxleft.set(0, 0);
						setCat($random(0, 9));
					}					
					$('divcat' + nextTab).destroy();
					arrFind.erase(nextTab.toString());
					vtkwrap = vtkwrap - 180;
					var vtkwidth = vtkwrap + 'px';
					$('vtkswrapper').setStyle('width',vtkwidth);
					var elX = ($('vtklimit').getPosition($('vtkswrapper'))).x;
					var elXTotal = eval(elX) - 870;
					vtkFxright.set(elXTotal, 0);
					vtkScroller();
				});
			}
			event.stop();
		}
	});
	$('buttonfind').addEvent('click', function(e){
		var event = new Event(e);
		if (true){
                  var escaped = $('txtfind').value;
			escaped = escaped.stripScripts();
			escaped = escaped.escapeRegExp();
			escaped = escaped.clean();
			var invalid = false;			
			['SCRIPT','XTERM','FTP','TYPE','CMD','SELECT','INSERT','DROP','WHERE','UPDATE','script','xterm','ftp','type','select','insert','drop','where','update','=','@','%','\\','/','&','<','>'].each(function(item){
				if(escaped.contains(item))invalid = true;
			});
			if(invalid){
				$('txtfind').blur();
				$('hechos-alert').setStyle('top',(document.documentElement.scrollTop + 300).toString() + 'px');
				$('hechos-palert').set('html','El texto de búsqueda es inválido.');
				$('hechos-alert').setStyle('display','block');
				$('hechos-alert').fade('hide');
				$('hechos-alert').fade(1);
			}
			if(escaped.length < 3){
				invalid = true;
				$('txtfind').blur();
				$('hechos-alert').setStyle('top',(document.documentElement.scrollTop + 300).toString() + 'px');
				$('hechos-palert').set('html','El texto de búsqueda debe contener 3 o más caracteres.');
				$('hechos-alert').setStyle('display','block');
				$('hechos-alert').fade('hide');
				$('hechos-alert').fade(1);
			}
			if(escaped != '' && escaped != ' ' && escaped != null && !invalid){
				vtkwrap = vtkwrap + 180;
				var vtkwidth = vtkwrap + 'px';
				$('vtkswrapper').setStyle('width',vtkwrap);
				if(vtkwrap>870 && !vtkscrollable){
					vtkscrollable = true;
					$('hechos-vsl').setStyle('display','block');
					$('hechos-vsl').fade('hide');
					$('hechos-vsl').fade(1);
					$('hechos-vsr').setStyle('display','block');
					$('hechos-vsr').fade('hide');
					$('hechos-vsr').fade(1);
				}
				vtktabs++;
				var nextTab = vtktabs;
				var newtab = new Element('div',{'id':'divcat' + nextTab,'class':'hechos-tab hechos-taboff'});
				var newa = new Element('a',{'id':'acat' + nextTab,'class':'hechos-atabon','href':'javascript:void(0);','onfocus':'blur();','html':$('txtfind').value + '&nbsp;&nbsp;'});
				var aclose = new Element('a',{'id':'avtkclose' + nextTab,'class':'hechos-aimg noboth','href':'javascript:void(0);'});
				var imgclose = new Element('img',{'class':'hechos-aimg','src':'http://static.hechos.tv/hechos/images2009/closetab.gif'});
				imgclose.inject(aclose);newa.inject(newtab);aclose.inject(newtab);newtab.inject($('vtklimit'),'before');
				escaped = escape(escaped);
				arrFind[nextTab.toString()] = escaped;
				vtkScroller();
				if (vtkscrollable) {
					var lastTab = $('vtkswrapper').getLast('div[id^=divcat]');
					var elX = ($('vtklimit').getPosition($('vtkswrapper'))).x;
					var elXTotal = eval(elX) - 870;
					vtkFxright.set(elXTotal, 0);
				}
				$('txtfind').blur();$('txtfind').value = 'Buscar Videos...';
				setCat(nextTab);
				$('acat' + nextTab).addEvent('click',function(e){
					e.stop();
					setCat(nextTab);
				});
				$('avtkclose' + nextTab).addEvent('click',function(e){
					e.stop();
					var tmpid = this.id
					var intId = tmpid.replace(/avtkclose/,'');
					intId = eval(intId);
					var isOn = $('divcat' + intId).hasClass('hechos-tab hechos-tabon');
					if(isOn){
						vtkFxleft.set(0, 0);
						setCat($random(0, 9));
					}					
					$('divcat' + nextTab).destroy();
					arrFind.erase(nextTab.toString());
					vtkwrap = vtkwrap - 180;
					var vtkwidth = vtkwrap + 'px';
					$('vtkswrapper').setStyle('width',vtkwidth);
					var elX = ($('vtklimit').getPosition($('vtkswrapper'))).x;
					var elXTotal = eval(elX) - 870;
					vtkFxright.set(elXTotal, 0);
					vtkScroller();
				});
			}
			event.stop();
		}
	});
	$('txtfind').addEvent('click',function(e){
		e.stop();
		if(this.value == 'Buscar Videos...')this.value = '';
		this.addEvent('blur',function(e){
			e.stop();
			if(this.value == '' || this.value == ' ')this.value = 'Buscar Videos...';
		});
	});
	$('hcomsname').addEvent('focus',function(e){
		if(this.value == 'Nombre')this.value = '';
		e.stop();
	});
	$('hcomsmail').addEvent('focus',function(e){
		if(this.value == 'E-mail')this.value = '';
		e.stop();
	});
	$('hcomscom').addEvent('focus',function(e){
		if(this.value == 'Comentario...')this.value = '';
		e.stop();
	});
	$('hcomsname').addEvent('blur',function(e){
		if(this.value == '' || this.value == ' ')this.value = 'Nombre';
		e.stop();
	});
	$('hcomsmail').addEvent('blur',function(e){
		if(this.value == '' || this.value == ' ')this.value = 'E-mail';
		e.stop();
	});
	$('hcomscom').addEvent('blur',function(e){
		if(this.value == '' || this.value == ' ')this.value = 'Comentario...';
		e.stop();
	});
	$('postcoms').addEvent('click',function(e){
		var hcomsname = $('hcomsname').value;
		var hcomsmail = $('hcomsmail').value;
		var hcomscom = $('hcomscom').value;
		comescaped = hcomscom.stripScripts();
		comescaped = comescaped.escapeRegExp();
		comescaped = comescaped.clean();
		var seth = $('comsanchor').getPosition().y;
		seth = seth + 'px';
		$('hechos-alert').setStyle('top',seth);
		if(!mailcheck(hcomsmail)){
			$('hechos-palert').set('html','E-mail inválido.');
			$('hechos-alert').setStyle('display','block');
		}
		else if(hcomsname == null || hcomsname == 'Nombre' || hcomsmail == null || hcomsmail == 'E-mail' || hcomscom == null || hcomscom == 'Comentario...'){
			$('hechos-palert').set('html','Favor de llenar todos los campos en la forma de comentarios.');
			$('hechos-alert').setStyle('display','block');
		}
		else{
			var postCom = new Request.HTML({url: '/contactoweb/inserta',
				method: 'POST',
				onSuccess: function(html){
					sendComsSlide.slideOut();
					$('hcomsname').value = 'Nombre';
					$('hcomsmail').value = 'E-mail';
					$('hcomscom').value = 'Comentario...';
				}
			}).post({
				'sNombreAutor':hcomsname,
				'sEmailAutor':hcomsmail,
				'sContenido':comescaped
			});
		}
		e.stop();
          });
        playNext();
});
//END OF DOMREADY
function getTheme(){
	hTheme = Cookie.read('hTheme');
	if (hTheme == null || hTheme == 1) {
		Cookie.write('hTheme', 1);
		hTheme = 1;
	}
	else {
		Cookie.write('hTheme', 2);
		hTheme = 2;
	}
}
function setTheme(x){
	if (x == 1) {
		Cookie.write('hTheme', 1);
		hTheme = 1;
		window.location.reload();
	}
	else {
		Cookie.write('hTheme', 2);
		hTheme = 2;
		window.location.reload();
	}
}
function setBoxBanner(x,y,z){
	if(Browser.Engine.gecko){
		var boxplace = $('boxbanner');
		$('boxbanner').empty();
		var boxembed = new Element('embed',{'src':x,'name':'swfboxbanner','type':'application/x-shockwave-flash','allowscriptaccess':'always','allowfullscreen':'true','width':'385','height':'250','scale':'noscale','FlashVars':'oas=' + y,'wmode':'opaque'});
		boxembed.inject(boxplace);
	}
	else{
		var boxSwiff = new Swiff(x, {
			id: 'swfboxbanner',
			width:  385,
			height: 250,
			params: {
				wmode: 'opaque',
				allowFullScreen: true,
				quality: 'hi',
				scale: 'noscale',
				FlashVars: 'oas=' + y
			},
			container: 'boxbanner'
		});
	}
	/*if(!$defined(boxurl)){
		boxurl = x;
		injectBoxBanner(x,y,z);
	}
	else if(boxurl != x){
		boxurl = x;
		injectBoxBanner(x,y,z);
	}*/
}
function updateBin(x){
	binCat = 0;
	if($('imgnewcat' + x).src == 'http://static.hechos.tv/hechos/images2009/chkboxoff.jpg'){
		$('imgnewcat' + x).src = 'http://static.hechos.tv/hechos/images2009/chkboxon.jpg';
	}
	else{
		$('imgnewcat' + x).src = 'http://static.hechos.tv/hechos/images2009/chkboxoff.jpg';
	}
	getBin();
	Cookie.write('hcats',binCat);
	filterCats(binCat);
}
function getBin(){
	binCat = 0;
	for(i=1;i<9;i++){
		var pow = Math.pow(2,(i-1));
		if($('imgnewcat' + i).src == 'http://static.hechos.tv/hechos/images2009/chkboxon.jpg'){
			binCat = binCat + pow;
		}
	}
}
function refreshBodylist(){
	if(hTheme == 1)$('')
}
function filterCats(x){
	var tNews = arrNews.length;
	hideAllNews();
	for(i=0;i<tNews;i++){
		var cat = $('newHid' + i).value;
		if(1&x && cat == 1)$('newTitle' + i).setStyle('display','block');
		if(2&x && cat == 2)$('newTitle' + i).setStyle('display','block');
		if(4&x && cat == 3)$('newTitle' + i).setStyle('display','block');
		if(8&x && cat == 4)$('newTitle' + i).setStyle('display','block');
		if(16&x && cat == 5)$('newTitle' + i).setStyle('display','block');
		if(32&x && cat == 6)$('newTitle' + i).setStyle('display','block');
		if(64&x && cat == 7)$('newTitle' + i).setStyle('display','block');
		if(128&x && cat == 8)$('newTitle' + i).setStyle('display','block');
	}
}
function setLastNews(){
	htimer = $clear(htimer);
	showAllNews();
	binCat = 255;
	$('newCats').setStyle('display','none');
	$('hechos-inleftwrap').setStyle('height','150px');
	$('alastmin').set('class','hechos-atabon');
	$('amymin').set('class','hechos-ataboff');
	$('divtablastmin').set('class','hechos-tab hechos-tabon');
	$('divtabmymin').set('class','hechos-tab hechos-taboff');
}
function setMyNews(){
	htimer = $clear(htimer);
	getBin();
	//hideAllNews();
	filterCats(binCat);
	$('newCats').setStyle('display','block');
	$('hechos-inleftwrap').setStyle('height','125px');
	$('alastmin').set('class','hechos-ataboff');
	$('amymin').set('class','hechos-atabon');
	$('divtablastmin').set('class','hechos-tab hechos-taboff');
	$('divtabmymin').set('class','hechos-tab hechos-tabon');
}
function detectFlash(){
	var flashVersion = Browser.Plugins.Flash.version;
	if(flashVersion < 9)injectGetFlashPlayer();
	else injectPlayer();
}
function playerReady(){
	flashLoaded = true;
	var getHap = Cookie.read('hap');
	if (getHap == null) {
		Cookie.write('hap', '1');
		getHap = Cookie.read('hap');
	}
	if(getHap == '0'){
		$('aactivateplay').set('html','<img src="http://static.hechos.tv/hechos/images2009/play.gif" alt=""/>Activar autoreproducción inicial&nbsp;&nbsp;|&nbsp;&nbsp;');
		if(plistsize > 0)showPlist();
	}
	if(getHap == '1'){
		$('aactivateplay').set('html','<img src="http://static.hechos.tv/hechos/images2009/pause.gif" alt=""/>Desactivar autoreproducción inicial&nbsp;&nbsp;|&nbsp;&nbsp;');
		skipToNext();
	}
}
function autoplayCookie(){
	var getHap = Cookie.read('hap');
	if(getHap == '0'){
		Cookie.write('hap','1');
		$('aactivateplay').set('html','<img src="http://static.hechos.tv/hechos/images2009/pause.gif" alt=""/>Desactivar autoreproducción inicial&nbsp;&nbsp;|&nbsp;&nbsp;');
	}
	if(getHap == '1'){
		Cookie.write('hap','0');
		$('aactivateplay').set('html','<img src="http://static.hechos.tv/hechos/images2009/play.gif" alt=""/>Activar autoreproducción inicial&nbsp;&nbsp;|&nbsp;&nbsp;');
	}
}
function catsCookie(){
	var getHCats = Cookie.read('hcats');
	if (getHCats == null){
		Cookie.write('hcats','0');
		getHCats = Cookie.read('hcats');
		binCat = 0;
		for(i=1;i<9;i++){
			$('imgnewcat' + i).src = 'http://static.hechos.tv/hechos/images2009/chkboxon.jpg';
		}
	}
	else{
		getHCats = Cookie.read('hcats');
		if(1&getHCats)$('imgnewcat1').src = 'http://static.hechos.tv/hechos/images2009/chkboxon.jpg';
		if(2&getHCats)$('imgnewcat2').src = 'http://static.hechos.tv/hechos/images2009/chkboxon.jpg';
		if(4&getHCats)$('imgnewcat3').src = 'http://static.hechos.tv/hechos/images2009/chkboxon.jpg';
		if(8&getHCats)$('imgnewcat4').src = 'http://static.hechos.tv/hechos/images2009/chkboxon.jpg';
		if(16&getHCats)$('imgnewcat5').src = 'http://static.hechos.tv/hechos/images2009/chkboxon.jpg';
		if(32&getHCats)$('imgnewcat6').src = 'http://static.hechos.tv/hechos/images2009/chkboxon.jpg';
		if(64&getHCats)$('imgnewcat7').src = 'http://static.hechos.tv/hechos/images2009/chkboxon.jpg';
		if(128&getHCats)$('imgnewcat8').src = 'http://static.hechos.tv/hechos/images2009/chkboxon.jpg';
		binCat = eval(getHCats);
	}
}
function tellMonth(month){
	var theMonth = new Array(12);
	theMonth[0] = 'enero';
	theMonth[1] = 'febrero';
	theMonth[2] = 'marzo';
	theMonth[3] = 'abril';
	theMonth[4] = 'mayo';
	theMonth[5] = 'junio';
	theMonth[6] = 'julio';
	theMonth[7] = 'agosto';
	theMonth[8] = 'septiembre';
	theMonth[9] = 'octubre';
	theMonth[10] = 'noviembre';
	theMonth[11] = 'diciembre';
	return theMonth[month];
}
function tellDay(day){
	var theDay = new Array(7);
	theDay[0] = 'Domingo';
	theDay[1] = 'Lunes';
	theDay[2] = 'Martes';
	theDay[3] = 'Mi&eacute;rcoles';
	theDay[4] = 'Jueves';
	theDay[5] = 'Viernes';
	theDay[6] = 'S&aacute;bado';
	return theDay[day];
}
var hTheme;
var binCat;
var fetch;
var fetchv;
var lastVideoNew;
var firstVtk;
var lastVtk;
var arrNews = new Array();
var arrVideos = new Hash;
var arrBest = new Hash;
var arrPlist = new Hash;
var arrVtk = new Hash;
var arrLive = new Hash;
var arrTrig = new Hash;
var onLive = 0;
var timerTrig;
var arrFind = new Hash;
var place = 0;
var plistsize = 0;
var nviewed = new Array();
var hechosSwiff;
var autoPlay = true;
var actualCat;
var catTotal;
var getpage;
var vidsTotal;
var vtkOpen = false;
var autoHeight = '202px';
var prevHeight = '202px';
var vtktabs = 9;
//var vtkwrap = 870px;
var vtkwrap = 1000;
var vtkFxright;
var vtkFxleft;
var tabcurrent = 0;
var tab;
var tmr;
var jlen;
var htimer;
var isover = false;
var hstop = 0;
var set = 0;
var scrollable;
var vtkscrollable = true;
var htriggered = false;
var flashLoaded = false;
var firstLoad = false;
var boxurl;
function newsStop(){
	set = arrNews.length;
	hstop = 1;
	showAllNews();
	htimer = $clear(htimer);
	fetch = $clear(fetch);
	var dv = $('hechos-pp');
	dv.empty();
	var imgplay = new Element('img',{'src':'http://static.hechos.tv/hechos/images2009/play.gif','alt':''});
	var aplay = new Element('a', {'id': 'hechos-playmin','class':'hechos-aminuto','href':'javascript:void(0);','onFocus':'blur();','html':'Reanudar noticias al minuto'}); 
	imgplay.inject(dv);aplay.inject(dv);
	$('hechos-playmin').addEvent('click',function(e){
		e.stop();
		newsPlay();
	});
}
function showAllNews(){
	var toshow = $('hechos-inleftwrap').getElements('div[id^=newTitle]');
	toshow.each(function(item,index){
		item.setStyle('display','block');
	});
}
function hideAllNews(){
	var toshow = $('hechos-inleftwrap').getElements('div[id^=newTitle]');
	toshow.each(function(item,index){
		item.setStyle('display','none');
	});
}
function newsPlay(){
	hstop = 0;
	fetch = $clear(fetch);
	fetch = fetchNews.delay(180000);
	var dv = $('hechos-pp');
	dv.empty();
	var imgstop = new Element('img',{'src':'http://static.hechos.tv/hechos/images2009/pause.gif','alt':''});
	var astop = new Element('a', {'id': 'hechos-stopmin','class':'hechos-aminuto','href':'javascript:void(0);','onFocus':'blur();','html':'Detener noticias al minuto'}); 
	imgstop.inject(dv);astop.inject(dv);
	$('hechos-stopmin').addEvent('click',function(e){
		e.stop();
		newsStop();
	});
}
function fetchNews(){
	$('divuptabstitle').addClass('hechos-spin');
	var lastNew = arrNews[(arrNews.length)-1][3];
	lastNew = lastNew.toString();
	var lastDate = '20' + lastNew.substr(4,2) + '-' + lastNew.substr(2,2) + '-' + lastNew.substr(0,2) + ' ' + lastNew.substr(6,2) + ':' + lastNew.substr(8,2) + ':' + lastNew.substr(10,2);
	var request = new Request.JSON({
		url: '/minutoaminuto/view/format/json/last/' + lastDate + '/cats/' + binCat,
		//url: 'news.php',
		onComplete: function(jsonObj) {
			$('divuptabstitle').removeClass('hechos-spin');
			if(jsonObj){
				if (jsonObj.total>0) {
					pushNews(jsonObj.noticias);
				}
				fetch = fetchNews.delay(180000);
			}
		}
	}).send();
}
function pushNews(json){
	var pos = arrNews.length;
	json.each(function(value,index){
		var arrElems = new Array();
		arrElems[0] = json[index].id;
		arrElems[1] = json[index].idcat;
		arrElems[2] = json[index].cat;
		arrElems[3] = json[index].stamp;
		arrElems[4] = json[index].titulo;
		var cleaner = json[index].cont;
		cleaner = cleaner.clean();
		arrElems[5] = cleaner;
		arrElems[6] = json[index].rep;
		arrElems[7] = json[index].size;
		arrNews[pos] = arrElems;
		var divnews = $('hechos-inleftwrap');
		var hour = formatHour(arrElems[3]) + '&nbsp;-&nbsp;';
		var newHead = new Element('div',{'id':'newTitle' + pos,'class':'hechos-newTitle'});
		var newTime = new Element('p',{'class':'hechos-pDate noboth','html':hour});
		var newTitle = new Element('a',{'id':'hechos-pTitle' + pos,'class':'hechos-pTitle noboth','href':'javascript:void(0);','onfocus':'blur();','html':arrElems[4] + '.&nbsp;' + arrElems[6]});
		var newblt = new Element('img',{'id':'newblt' + pos,'src':'http://static.hechos.tv/hechos/images2009/play.gif','alt':''});
		var newDivCont = new Element('div',{'id':'newDivCont' + pos,'class':'hechos-newDivCont noboth'});
		var newCont = new Element('div',{'id':'pCont' + pos,'class':'hechos-newCont','html':arrElems[5]});
		var newHid = new Element('input',{'id':'newHid' + pos,'class':'noboth','type':'hidden','value':arrElems[1]});
		newblt.inject(newTitle);newTime.inject(newHead);newTitle.inject(newHead);newCont.inject(newDivCont);newDivCont.inject(newHead);newHid.inject(newHead);newHead.inject(divnews,'top');
		pos++;
		newTitle.addEvent('click',function(e){
			e.stop();
			var param = this.id.replace(/hechos-pTitle/,'');
			expandNew(param);
		});
	});
	tmr = (Math.floor(50 / (json.length - 1))) * 1000;
	if(set == 0)setVisible();
	else
	startTimer();
	if (!htriggered) {
		htriggered = true;
		fetch = fetchNews.delay(180000);
	}
}
function startTimer(){
	htimer = setVisible.delay(tmr);
}
function expandNew(x){
	if($('newDivCont' + x).getStyle('display') == 'block'){
		$('newblt' + x).src = 'http://static.hechos.tv/hechos/images2009/play.gif';
		var expCont = new Fx.Slide('pCont' + x, {duration: 600, wait: true, onComplete:function(){$('newDivCont' + x).setStyle('display','none');$('pCont' + x).setStyle('display','none');}});
		expCont.show();
		expCont.slideOut();
	}
	else{
		$('newblt' + x).src = 'http://static.hechos.tv/hechos/images2009/play2.gif';
		$('newDivCont' + x).setStyle('display','block');
		$('pCont' + x).setStyle('display','block');
		var expCont = new Fx.Slide('pCont' + x, {duration: 600, wait: true});
		expCont.hide();
		expCont.slideIn();
	}
}
function setVisible(){
	if (hstop == 0) {
		$('newTitle' + set).setStyle('display', 'block');
		$('newTitle' + set).fade('hide');
		$('newTitle' + set).fade(1);
		if(hTheme == 1)activateFade('hechos-uptabsmid','background-color',300,'rgb(141,0,12)','rgb(26,26,26)');
		else activateFade('hechos-uptabsmid','background-color',300,'rgb(141,0,12)','rgb(206,206,206)');
		if (set == (arrNews.length - 1)) {
			htimer = $clear(htimer);
		}
		else {
			htimer = $clear(htimer);
			htimer = setVisible.delay(tmr);
		}
		set++;
	}
}
function activateFade(div,property,delay,startValue,endValue){
	var myFx = new Fx.Tween($(div),{
		wait: true,
		property: property,
		duration: delay,
		onComplete: function(e){
			e.stop;
			myFx2.start(endValue);
			myFx = '';
		}
	});
	myFx.start(startValue);
	var myFx2 = new Fx.Tween($(div),{
		wait: true,
		property: property,
		duration: delay
	});
}
/* FASE 2 */
function injectPlayer(){
  /*
        if(navigator.userAgent.indexOf('iPad') == -1){
          //$('hechos-vidplayer').empty();
	//var playerName = 'FlvPlayerv71.swf';
	if(Browser.Engine.gecko){
		var place = $('hechos-vidplayer');
		var embed = new Element('embed',{'src':'http://static.hechos.tv/hechos/swf/' + playerName,'name':'videoplayer','type':'application/x-shockwave-flash','allowscriptaccess':'always','allowfullscreen':'true','width':'500','height':'309','bgColor':'#0E0E0E','scale':'noscale','wmode':'opaque'});
		embed.inject(place);
	}
	else{
          //hechosSwiff = new Swiff('http://static.hechos.tv/hechos/swf/' + playerName, {
		hechosSwiff = new Swiff('http://www.tvazteca.com/video_component/swf/video_component-v_1_0_f.swf', {
			id: 'videoplayer',
			width:  500,
			height: 309,
			params: {
				wmode: 'opaque',
				bgcolor: '#0E0E0E',
				allowFullScreen: true,
				quality: 'hi',
				scale: 'noscale'
			},
			container: 'hechos-vidplayer'
		});
  
	}
        }else{
		$('hechos-vidplayer').empty();
$('hechos-vidplayer').innerHTML = '<video src="" width="500" height="309" controls preload></video>';
        }
  */
}
function injectGetFlashPlayer(){    
        if(navigator.userAgent.indexOf('iPad') == -1){
	var agetflash = new Element('a',{'class':'noboth','href':'http://www.adobe.com/go/EN_US-H-GET-FLASH'})
	var imggetFlash = new Element('img',{'class':'hechos-imglink noboth','src':'http://static.hechos.tv/hechos/images2009/getflash.jpg'});
	imggetFlash.inject(agetflash);agetflash.inject($('hechos-vidplayer'));
	$('ptitle').set('html','Hemos detectado que tu navegador carece de la versión de flash player necesaria, haz click en la imágen para instalar la última versión.');
	}else{
	    injectPlayer();
	}
}
function fetchVideoNews(){
	$('alastnews').addClass('hechos-spin');
	var request2 = new Request.JSON({
		url: '/videonotas/view/format/json/last/' + lastVideoNew,
		//url: 'videos.php',
		onComplete: function(jsonObj2) {
			//fetchv = fetchVideoNews.delay(120000);
			fetchv = fetchVideoNews.delay(300000);
			$('alastnews').removeClass('hechos-spin');
			if(jsonObj2){
				if (jsonObj2.total>0) {
					pushVidNews(jsonObj2.videonews);
				}
			}
		}
	}).send();
	//}).get({'lastvn': lastVideoNew});
}
function pushVidNews(json){
	//vjlen = json.length;
	json.each(function(value,index){
		var vpos = json[index].id;
		var arrvElems = new Array();
		var ntime = formatHour(json[index].istamp);
		var nday = (json[index].istamp).substr(0,2);
		if (eval(nday) < 10) {
			nday = nday.substr(1, 1);
			nday = nday.toString();
		}
		var nmonth = tellMonth( eval((json[index].istamp).substr(2,2)) - 1 );
		var titulo = json[index].titulo;
		if(titulo.length > 80)titulo = titulo.substr(0,80) + '...';
		arrvElems[0] = json[index].idcat;
		arrvElems[1] = json[index].cat;
		arrvElems[2] = json[index].titulo;
		arrvElems[3] = json[index].istamp;
		arrvElems[4] = json[index].istamp;
		arrvElems[5] = json[index].vlink;
		//if(json[index].preview == null)arrvElems[6] = 'http://static.hechos.tv/hechos/images2009/preview.jpg';
		//else arrvElems[6] = json[index].preview;
		arrvElems[6] = "null";
		if(json[index].imgb == null)arrvElems[7] = 'http://static.hechos.tv/hechos/images2009/th_default_188x124.jpg';
		else arrvElems[7] = json[index].imgb;
		if(json[index].imgs == null)arrvElems[8] = 'http://static.hechos.tv/hechos/images2009/th_default_75x50.jpg';
		else arrvElems[8] = json[index].imgs;
		arrvElems[9] = json[index].dur;
		arrvElems[10] = json[index].camp;
		arrvElems[11] = json[index].rank;
		arrvElems[12] = json[index].resumen;
		arrVideos[vpos] = arrvElems;
		if(place == 0){
			injectVidRow(vpos,json[index].dur,arrvElems[8],json[index].cat,titulo,ntime,nday,nmonth);
		}
		lastVideoNew = eval(json[index].id) + 1;
	});
}
function pushBestNews(json){
	json.each(function(value,index){
		var bpos = json[index].id;
		var arrbElems = new Array();
		var ntime = formatHour(json[index].istamp);
		var nday = (json[index].istamp).substr(0,2);
		if (eval(nday) < 10) {
			nday = nday.substr(1, 1);
			nday = nday.toString();
		}
		var nmonth = tellMonth( eval((json[index].istamp).substr(2,2)) - 1 );
		//var titulo = json[index].titulo;
		//if(titulo.length > 80)titulo = titulo.substr(0,80) + '...';
		arrbElems[0] = json[index].idcat;
		arrbElems[1] = json[index].cat;
		arrbElems[2] = json[index].titulo;
		arrbElems[3] = json[index].istamp;
		arrbElems[4] = json[index].istamp;
		arrbElems[5] = json[index].vlink;
		arrbElems[6] = 'null';
		arrbElems[7] = 'null';
		if(json[index].imgs == null)arrbElems[8] = 'http://static.hechos.tv/hechos/images2009/th_default_75x50.jpg';
		else arrbElems[8] = json[index].imgs;
		arrbElems[9] = json[index].dur;
		arrbElems[10] = json[index].camp;
		arrbElems[11] = json[index].rank;
		arrbElems[12] = json[index].resumen;
		arrBest[bpos] = arrbElems;
	});
}
function fetchLive(){
	/*timerTrig = $clear(timerTrig);
	var request = new Request.JSON({
		url: 'http://www.hechos.tv/eventosvivo/view/format/json',
		//url: 'live.php',
		onComplete: function(jsonObj) {
			if(jsonObj){
				pushTriggerLive(jsonObj.trigger);
			}
			timerTrig = fetchLive.delay(300000);
		}
	}).send();*/
}
function pushLive(json){
	json.each(function(value,index){
		lpos = json[index].id;
		var arrlElems = new Array();
		arrlElems[0] = json[index].id;
		arrlElems[1] = json[index].cat;
		arrlElems[2] = json[index].titulo;
		arrlElems[3] = json[index].horario;
		arrlElems[4] = '';
		arrlElems[5] = json[index].vlink;
		arrlElems[6] = '';
		arrlElems[7] = '';
		arrlElems[8] = json[index].imgs;
		arrlElems[9] = '';
		arrlElems[10] = json[index].camp;
		arrlElems[11] = '';
		arrlElems[12] = '';
		arrLive[lpos] = arrlElems;
	});
}
function checkLiveOn(arrTrig){
	var hasOn = false;
	arrTrig.each(function(item,index){
		if(item==1)hasOn = true;
	});
	if(hasOn)$('divlive').tween('background-color','#8D000C');
	else {
		if(hTheme == 1)$('divlive').setStyle('background-color','#2C2C2C');
		else $('divlive').setStyle('background-color','#333333');
	}
}
function pushTriggerLive(json){
	var hasOn = false;
	json.each(function(item,index){
		if(json[index].active == '1')hasOn = true;
		arrTrig[json[index].id] = json[index].active;
		if(onLive == json[index].id && json[index].active == '0'){
			onLive = 0;
			getFlashMovie('videoplayer').notifyStop();
			$('globaltitle').set('html','Noticias en video');
		}
	});
	triggerLive(arrTrig);
	timerTrig = fetchLive.delay(300000); // <------ cancelado
	if(!hasOn && place != 2){
		if(hTheme == 1)$('divlive').tween('background-color', '#2C2C2C');
		else $('divlive').tween('background-color', '#333333');
	}
}
function triggerLive(arrTrig){
	var scrolled = false;
	arrTrig.each(function(item,index){
		if(place != 2){
			if(item == '1')$('divlive').tween('background-color', '#8d000c');
		}
		else{
			if(item == '0' && $('liverow' + index)){
				$('liverow' + index).fade(0.5);
				$('livelink' + index).removeEvents();
				$('divvidplay' + index).empty();
			}
			else if($('liverow' + index)){
				$('liverow' + index).fade(1);	
				if(!scrolled){
					scrolled = true;
					var bodyScroll = new Fx.Scroll('bodylist').toElement('liverow' + index);
				}
				$('divvidplay' + index).empty();
				var divvidplay = $('divvidplay' + index);
				var imglink = new Element('a',{'id':'aimglink' + index,'class':'hechos-imglink','href':'javascript:void(0);'});
				var imgplay = new Element('img',{'class':'noboth','src':'http://static.hechos.tv/hechos/images2009/vidplay.gif','alt':''});
				imgplay.inject(imglink);imglink.inject(divvidplay);
				$('aimglink' + index).addEvent('click',function(e){
					playLive(index);
					e.stop();
				});
				$('livelink' + index).addEvent('click',function(e){
					playLive(index);
					e.stop();
				})
			}
		}
	});
}
function injectVidRow(where,dur,imgs,cat,titulo,ntime,nday,nmonth){
	var bodylist = $('bodylist');
	var vidrow = new Element('div',{'id':'vidrow' + where,'class':'hechos-vidrow'});
	var vidrowleft = new Element('div',{'class':'hechos-vidrowleft','html':dur});
	var vidaclose = new Element('a',{'id':'vidaclose' + where,'class':'hechos-fright hechos-aimg noboth','href':'javascript:removeVideo("' + where + '");'});
	var imgvidaclose = new Element('img',{'class':'hechos-vidaclose','src':'http://static.hechos.tv/hechos/images2009/vidclose.gif','alt':''});
	var vidrowright = new Element('div',{'class':'hechos-vidrowright'});
	var divimgs = new Element('div',{'class':'hechos-divimgs'});
	var imgs = new Element('img',{'class':'hechos-imgs','src':imgs});
	var vidplay = new Element('div',{'class':'hechos-vidplay'});
	var imglink = new Element('a',{'class':'hechos-imglink','href':'javascript:playVideo("' + where + '");'});
	var imgplay = new Element('img',{'class':'noboth','src':'http://static.hechos.tv/hechos/images2009/vidplay.gif','alt':''});
	var vidplus = new Element('div',{'class':'hechos-vidplus'});
	var imglink2 = new Element('a',{'class':'hechos-imglink','href':'javascript:addtoList(' + where + ');'});
	var imgplus = new Element('img',{'class':'noboth','src':'http://static.hechos.tv/hechos/images2009/vidplus.gif','alt':''});
	var vidtext = new Element('div',{'class':'hechos-vidtext'});
	var pcatsmall = new Element('p',{'class':'hechos-ptitlecat noboth','html':ntime + '&nbsp;&nbsp;-&nbsp;' + nday + '&nbsp;de&nbsp;' + nmonth});
	var br = new Element('br');
	var ptitle = new Element('a',{'class':'hechos-ptitlesmall noboth','html':titulo,'href':'javascript:playVideo("' + where + '");'});
	imgvidaclose.inject(vidaclose);vidaclose.inject(vidrowleft,'top');imgs.inject(divimgs);imglink.inject(vidplay);imgplay.inject(imglink);vidplay.inject(divimgs);imgplus.inject(imglink2);imglink2.inject(vidplus);if(place == 0 || place == 3)vidplus.inject(divimgs);pcatsmall.inject(vidtext);br.inject(vidtext);ptitle.inject(vidtext);divimgs.inject(vidrowright);vidtext.inject(vidrowright);vidrowright.inject(vidrow);vidrowleft.inject(vidrow);if(place == 0 || place == 3)vidrow.inject(bodylist,'top'); else vidrow.inject(bodylist,'bottom');
}
function injectLiveRow(where,imgs,cat,titulo,horario){
	var bodylist = $('bodylist');
	var vidrow = new Element('div',{'id':'liverow' + where,'class':'hechos-vidrow'});
	var vidrowright = new Element('div',{'class':'hechos-vidrowright'});
	var divimgs = new Element('div',{'class':'hechos-divimgs'});
	var imgs = new Element('img',{'class':'hechos-imgs','src':imgs});
	var vidplay = new Element('div',{'id':'divvidplay' + where,'class':'hechos-vidplay'});
	//var imglink = new Element('a',{'class':'hechos-imglink','href':'javascript:playLive("' + where + '");'});
	//var imgplay = new Element('img',{'class':'noboth','src':'http://static.hechos.tv/hechos/images2009/vidplay.gif','alt':''});
	var vidtext = new Element('div',{'class':'hechos-vidtext'});
	var pcatsmall = new Element('p',{'class':'hechos-ptitlecat noboth','html':horario});
	var br = new Element('br');
	var ptitle = new Element('a',{'id':'livelink' + where,'class':'hechos-ptitlesmall noboth','html':titulo,'href':'javascript:void(0);'});
	imgs.inject(divimgs);
	//imglink.inject(vidplay);imgplay.inject(imglink);
	vidplay.inject(divimgs);
	ptitle.inject(vidtext);
	br.inject(vidtext);
	pcatsmall.inject(vidtext);
	divimgs.inject(vidrowright);
	vidtext.inject(vidrowright);vidrowright.inject(vidrow);
	vidrow.inject(bodylist,'bottom');
}
function getFlashMovie(movieName){
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    return (isIE) ? window[movieName] : document[movieName];
}
function playVideo(x){
        if(navigator.userAgent.indexOf('iPad') == -1){
          if(true){//flashLoaded
            
		onLive = 0;
		if(x.contains('vtk'))var certId = x.replace(/vtk/,'');
		else var certId = x;
		cert_registerHit( 24294, '/videos/' + certId, 'cert_Pivot');
		var isvtk = x.toString();
		if (isvtk.search(/vtk/) != -1) {
			var n = x.replace(/vtk/, '');
			var arr = arrVtk[n.toString()];
			var startCat = arrVtk[n.toString()][1];
			var startTit = arrVtk[n.toString()][2];
			var startDur = arrVtk[n.toString()][9];
		}
		else if(place == 0){var arr = arrVideos[x.toString()];var startCat = arrVideos[x.toString()][1];var startTit = arrVideos[x.toString()][2];var startDur = minToSec(arrVideos[x.toString()][9]);}
		else if(place == 1){var arr = arrPlist[x.toString()];var startCat = arrPlist[x.toString()][1];var startTit = arrPlist[x.toString()][2];var startDur = minToSec(arrPlist[x.toString()][9]);}
		else if(place ==3){var arr = arrBest[x.toString()];var startCat = arrBest[x.toString()][1];var startTit = arrBest[x.toString()][2];var startDur = minToSec(arrBest[x.toString()][9]);}
		startCat = formatStart(startCat);
		startTit = formatStart(startTit);
		//start(24281,startCat,startTit,startDur,false,true);
		var month = tellMonth(eval((arr[4]).substr(2,2)) - 1 );
		var day = arr[4].substr(0,2);
		//if(eval(day) < 10)day = day.substr(1,1);
		day = day.toInt();
		//$('ptitlecat').set('html',formatHour(arr[4]) + '&nbsp;-&nbsp;' + day + '&nbsp;de&nbsp;' + month);
		$('ptitle').set('html',arr[2]);
		$('psinopsis').set('html',arr[12]);
		$('globaltitle').set('html','Noticias en video');
		arr.push(x.toString());
		arr[12] = arr[12].replace(/vtk/,'');
		arr[13] = arr[13].replace(/vtk/,'');
                //getFlashMovie('videoplayer').notifyPlay(arr);
                //alert(arr.toString());
                window.VideoComponent.prototype.getSWFObjectById('videoComponent0').load(arr[5]);
		removeVideo(x);
	}
	}else{
	    document.getElementsByTagName('video')[0].src = 'http://98.129.43.169:1935/servicios/_definst_/neritmp/HD.mp4/playlist.m3u8';
	    document.getElementsByTagName('video')[0].load();
	}
}
function formatStart(x){
	x = x.trim();
	x = x.clean();
	x = x.toLowerCase();
	x = x.replace(/á/g,'a');
	x = x.replace(/é/g,'e');
	x = x.replace(/í/g,'i');
	x = x.replace(/ó/g,'o');
	x = x.replace(/ú/g,'u');
	x = x.replace(/ñ/g,'n');
	x = x.replace(/ /g,'_');
	x = x.replace(/[^a-z0-9\-]/g,'_');
	x = x.replace(/_+/g,'_');
	return x;
}
function playLive(x){
	$('globaltitle').set('html','Transmisión en vivo');
	onLive = x;
	onLive = onLive.toInt();
	$('psinopsis').set('html','');
	$('ptitle').set('html',arrLive[x.toString()][2]);
	var arrFlash = arrLive[x.toString()];
	arrFlash.push(arrLive[x.toString()][0]);
	getFlashMovie('videoplayer').notifyPlay(arrFlash);
}
function minToSec(x){
	var cMins = x.substr(0,2);
	//if(cMins[0] == 0)cMins = eval(x.substr(1,1));
	cMins = cMins.toInt();
	var cSecs = x.substr(3,2);
	cSecs = cSecs.toInt();
	var cTotal = (cMins * 60) + cSecs;
	return cTotal;
}
function playNext(){
	if (autoPlay) {
		onLive = 0;
		if (plistsize > 0) {
			showPlist();
			flashBodylist.delay(500);
		}
		if(plistsize <= 0 && place > 0){
			showLastNews();
			flashBodylist.delay(500);
		}
		var bodylist = $('bodylist');
		var arrFlash = new Hash;
		var nextVideo = bodylist.getFirst('div[id^=vidrow]');
		nextVideo = nextVideo.id;
		nextVideo = nextVideo.toString();
		var certId = nextVideo.replace(/vidrow/,'');
		cert_registerHit( 24294, '/videos/' + certId, 'cert_Pivot');
		var vlen = nextVideo.length - 6;
		nextVideo = nextVideo.substr(6, vlen);
		if (plistsize > 0) {
			arrFlash = arrPlist[nextVideo];
			var month = tellMonth((arrPlist[nextVideo][4]).substr(2,2) - 1);
			var day = (arrPlist[nextVideo][4]).substr(0,2);
			//if(eval(day) < 10)day = day.substr(1,1);
			day = day.toInt();
			var datetime = formatHour(arrPlist[nextVideo][4]) + '&nbsp;-&nbsp;' + day + '&nbsp;de&nbsp;' + month;
			//$('ptitlecat').set('html', datetime);
			$('ptitle').set('html', arrPlist[nextVideo][2]);
			$('psinopsis').set('html',arrPlist[nextVideo][12]);
			var startCat = arrPlist[nextVideo][1];
			var startTit = arrPlist[nextVideo][2];
			var startDur = minToSec(arrPlist[nextVideo][9]);
			startCat = formatStart(startCat);
			startTit = formatStart(startTit);
		}
		else {
			arrFlash = arrVideos[nextVideo];
			var month = tellMonth((arrVideos[nextVideo][4]).substr(2,2) - 1);
			var day = (arrVideos[nextVideo][4]).substr(0,2);
			if(eval(day) < 10)day = day.substr(1,1);
			var datetime = formatHour(arrVideos[nextVideo][4]) + '&nbsp;-&nbsp;' + day + '&nbsp;de&nbsp;' + month;
			//$('ptitlecat').set('html', datetime);
			$('ptitle').set('html', arrVideos[nextVideo][2]);
			$('psinopsis').set('html',arrVideos[nextVideo][12]);
			$('globaltitle').set('html','Noticias en video');
			var startCat = arrVideos[nextVideo][1];
			var startTit = arrVideos[nextVideo][2];
			var startDur = minToSec(arrVideos[nextVideo][9]);
			startCat = formatStart(startCat);
			startTit = formatStart(startTit);
		}
		//start(24281,startCat,startTit,startDur,false,true);
		arrFlash.push(nextVideo);
		removeVideo(nextVideo);
		//return arrFlash;
                window.VideoComponent.prototype.getSWFObjectById('videoComponent0').load(arrFlash[5]);
	}
}
function skipToNext(){
	if (plistsize > 0)showPlist();
	else if(arrVideos.getLength() > 0){
		if(place > 0)showLastNews();
	}
	if(plistsize > 0 || arrVideos.getLength() > 0){
		var bodylist = $('bodylist');
		var nextVideo = bodylist.getFirst('div[id^=vidrow]');
		nextVideo = nextVideo.id;
		nextVideo = nextVideo.replace(/vidrow/,'');
		playVideo(nextVideo);
	}
}
function addtoList(x){
	if (arrPlist.getLength() < 20) {
		if (place != 1) $('divplist').tween('background-color','#8d000c');
		
		if(place == 3)arrPlist[x.toString()] = arrBest[x.toString()];
		else arrPlist[x.toString()] = arrVideos[x.toString()];
		plistsize++;
		removeVideo(x);
	}
	else {
		scrollWindow('mainmid',0);
		$('hechos-alert').setStyle('top',(document.documentElement.scrollTop + 300).toString() + 'px');
		$('hechos-palert').set('html','Has excedido el número máximo de elementos en tu Playlist.');
		$('hechos-alert').setStyle('display','block');
		$('hechos-alert').fade('hide');
		$('hechos-alert').fade(1);
	}
}
function removeVideo(x){
	var isvtk = (x.toString()).contains('vtk');
	if($('vidaclose' + x)){
		$('vidaclose' + x).href = '';
		var row = 'vidrow' + x;	
		var delSlide = new Fx.Slide(row, {
			onComplete: function(){
				if($(row)) {$(row).destroy();}
				var trash = $('bodylist').getElements('div[style^=margin]');
				trash.destroy();
				if (place == 1 && plistsize == 0)showLastNews();
				if(place == 3)if(arrBest.getLength() < 1 && plistsize > 0)showPlist();
				if(place == 3)if(arrBest.getLength() < 1 && plistsize == 0)showLastNews();
			},
			duration: 400,
			wait: true
		});
		delSlide.slideOut();
	}
	if(place == 0)arrVideos.erase(x.toString());
	if(place == 1 && !isvtk) {
		arrPlist.erase(x.toString());
		plistsize--;
		if(plistsize < 1)$('divplist').tween('background-color', '#2C2C2C');
	}
	if(place == 3)arrBest.erase(x.toString());
	if(isvtk){
		if(arrPlist.has(x.toString())){
			arrPlist.erase(x.toString());
			plistsize--;
			if(plistsize < 1)$('divplist').tween('background-color', '#2C2C2C');
		}
	}
	var residue = $('bodylist').getFirst(':empty');
	if(residue)residue.destroy();
}
function stopAutoPlay(){
	$('hechos-autoplay').removeEvents();
	$('hechos-autoplay').set('html','<img src="http://static.hechos.tv/hechos/images2009/play.gif" alt=""/>Activar reproducción continua');
	$('hechos-autoplay').addEvent('click',function(e){
		e.stop();
		startAutoPlay();
	});
	autoPlay = false;
}
function startAutoPlay(){
	$('hechos-autoplay').removeEvents();
	$('hechos-autoplay').set('html','<img alt="" src="http://static.hechos.tv/hechos/images2009/pause.gif"/>Desactivar reproducción continua');
	$('hechos-autoplay').addEvent('click',function(e){
		e.stop();
		stopAutoPlay();
	});
	autoPlay = true;
}
function showLastNews(){
	if (place != 0) {
		place = 0;
		$('bodylist').empty();
		if (plistsize != 0)$('divplist').setStyle('background-color', '#8d000c');
		else if(hTheme == 2)$('divplist').setStyle('background-color','#333333');
		if(arrBest.getLength() > 0){
                  //$('divbest').setStyle('background-color', '#8d000c');
                  $('divbest').tween('background-color', '#333333');
                }else if(hTheme == 2){
                  //$('divbest').setStyle('background-color','#333333');
                }
		setTabStyle(0);
		arrVideos.each(function(item, index){
			var ntime = formatHour(item[4]); //(item[4]).substr(6, 2) + ':' + (item[4]).substr(8, 2);
			var nday = (item[4]).substr(0, 2);
			nday = nday.toInt();
			var nmonth = tellMonth(eval(item[4].substr(2, 2)) - 1);
			var titulo = item[2];
			if (titulo.length > 80) titulo = titulo.substr(0, 80) + '...';
			injectVidRow((arrVideos.indexOf(item)).toString(), item[9], item[8], item[1], titulo, ntime, nday, nmonth);
		});
		checkLiveOn(arrTrig);
	}
}
function showPlist(){
	if (place != 1) {
		place = 1;
		$('bodylist').empty();
		if(hTheme == 1)$('divplist').setStyle('background-color','#2C2C2C');
		else $('divplist').setStyle('background-color','#CECECE');
		setTabStyle(1);
		arrPlist.each(function(item, index){
			var ntime = formatHour(item[4]);
			var nday = (item[4]).substr(0, 2);
			nday = nday.toInt();
			var nmonth = tellMonth(eval(item[4].substr(2, 2)) - 1);
			var titulo = item[2];
			if (titulo.length > 80) titulo = titulo.substr(0, 80) + '...';
			injectVidRow((arrPlist.indexOf(item)).toString(), item[9], item[8], item[1], titulo, ntime, nday, nmonth);
		});
		checkLiveOn(arrTrig);
	}
	if(arrBest.getLength() > 0){
          //$('divbest').setStyle('background-color','#8d000c');
          $('divbest').tween('background-color', '#333333');
        }else if(hTheme == 2){
          //$('divbest').setStyle('background-color','#333333');
        }
}
function showBest(){
	if(place!=3){
		place = 3;
		$('bodylist').empty();
		if(hTheme == 1)$('divbest').setStyle('background-color', '#2C2C2C');
		else $('divbest').setStyle('background-color', '#CECECE');
		if(plistsize != 0)$('divplist').setStyle('background-color','#8d000c');
		else if(hTheme == 2)$('divplist').setStyle('background-color','#333333');
		setTabStyle(3);
		arrBest.each(function(item,index){
			var ntime = formatHour(arrBest[index][3]);
			var nday = (arrBest[index][3]).substr(0,2);
			if (eval(nday) < 10) {
				nday = nday.substr(1, 1);
				nday = nday.toString();
			}
			var nmonth = tellMonth( eval((arrBest[index][3]).substr(2,2)) - 1 );
			var titulo = arrBest[index][2];
			if(titulo.length > 80)titulo = titulo.substr(0,80) + '...';
			injectVidRow(index,arrBest[index][9],arrBest[index][8],arrBest[index][1],titulo,ntime,nday,nmonth);
		});
		checkLiveOn(arrTrig);
	}
}
function showLive(){
	if(place!=2){
		place = 2;
		$('bodylist').empty();
		if(plistsize != 0)$('divplist').setStyle('background-color','#8d000c');
		else if(hTheme == 2)$('divplist').setStyle('background-color','#333333');
		setTabStyle(2);
	}
	if(arrBest.getLength() > 0){
          //$('divbest').setStyle('background-color','#8d000c');
          $('divbest').tween('background-color', '#333333');
        }else if(hTheme == 2){
          //$('divbest').setStyle('background-color','#333333');
        }
	
	if(hTheme == 2)$('divlive').setStyle('background-color','#CECECE');
	
	arrLive.each(function(item,index){
		var titulo = arrLive[index][2];
		if(titulo.length > 80)titulo = titulo.substr(0,80) + '...';
		injectLiveRow(arrLive[index][0],arrLive[index][8],arrLive[index][1],titulo,arrLive[index][3]);
	});
	triggerLive(arrTrig);
}
function setTabStyle(x){
	if(x == 0){var divon = 'divlastnews', divoff1 = 'divlive', divoff2 = 'divplist', divoff3 = 'divbest', aon = 'alastnews', aoff1 = 'alive', aoff2 = 'aplist', aoff3 = 'abest';}
	if(x == 1){var divon = 'divplist', divoff1 = 'divlastnews', divoff2 = 'divlive', divoff3 = 'divbest', aon = 'aplist', aoff1 = 'alastnews', aoff2 = 'alive', aoff3 = 'abest';}
	if(x == 2){var divon = 'divlive', divoff1 = 'divlastnews', divoff2 = 'divplist', divoff3 = 'divbest', aon = 'alive', aoff1 = 'alastnews', aoff2 = 'aplist', aoff3 = 'abest';}
	if(x == 3){var divon = 'divbest', divoff1 = 'divlastnews', divoff2 = 'divplist', divoff3 = 'divlive', aon = 'abest', aoff1 = 'alastnews', aoff2 = 'aplist', aoff3 = 'alive';}
	$(divon).set('class','hechos-tab hechos-tabon');
	$(divoff1).set('class','hechos-tab hechos-taboff');
	$(divoff2).set('class','hechos-tab hechos-taboff');
	$(divoff3).set('class','hechos-tab hechos-taboff');
	$(aon).set('class','hechos-atabon');
	$(aoff1).set('class','hechos-ataboff');
	$(aoff2).set('class','hechos-ataboff');
	$(aoff3).set('class','hechos-ataboff');
}
function notifyViewed(idNota){
	if(idNota.contains('vtk'))idNota = idNota.replace(/vtk/, '')
    var notify = new Request.HTML({url:'/videonotas/updateVideoVisto/idNota/'+idNota,
		method: 'GET'
    }).send();
}
/*FASE 3*/
var pagina;
function setCat(x){
	if(x>9)actualCat = arrFind[x.toString()];
	else actualCat = x;
	$('divcat' + x).set('class','hechos-tab hechos-tabon');
	$('acat' + x).set('class','hechos-atabon');
	for(i=0;i<(vtktabs + 1);i++){
		if(i!= x && ($('divcat' + i))){
			$('divcat' + i).set('class','hechos-tab hechos-taboff');
			$('acat' + i).set('class','hechos-ataboff');
		}
	}
	fetchCat(actualCat,1,0);
}
function fetchCatPrev(){
	fetchCat(actualCat,0,pagina);
}
function fetchCatNext(){
	fetchCat(actualCat,1,pagina);
}
function fetchCat(cat,to,ref){
	if(firstLoad){
		switch (cat){
			case 1: cert_registerHit( 24283, '/politicaygobierno', 'cert_Pivot');break;
			case 2: cert_registerHit( 24285, '/segudidadyjusticia', 'cert_Pivot');break;
			case 3: cert_registerHit( 24286, '/dineroyempleo', 'cert_Pivot');break;
			case 4: cert_registerHit( 24287, '/bienestar', 'cert_Pivot');break;
			case 5: cert_registerHit( 24289, '/arteycultura', 'cert_Pivot');break;
			case 6: cert_registerHit( 24278, '/mundo', 'cert_Pivot');break;
			case 7: cert_registerHit( 24284, '/estados', 'cert_Pivot');break;
			case 8: cert_registerHit( 24288, '/cienciaytecnologia', 'cert_Pivot');break;
			case 9: cert_registerHit( 24279, '/hechosdepeluche', 'cert_Pivot');break;
			default: cert_registerHit( 24280, '/busquedas', 'cert_Pivot');
		}
	}
	$('hechos-vteca').empty();
	arrVtk.empty();
	$('titlevteca').addClass('hechos-spin');
	$('hechos-vteca').addClass('hechos-vtkspin');
	var request3 = new Request.JSON({
		url: '/videoteca/view/format/json/',
		//url: 'videoteca.php',
		onComplete: function(jsonObj3) {
			$('titlevteca').removeClass('hechos-spin');
			$('hechos-vteca').removeClass('hechos-vtkspin');
			if(jsonObj3){
				if(jsonObj3.total == 0){
					$('hechos-alert').setStyle('top',(document.documentElement.scrollTop + 300).toString() + 'px');
					$('hechos-palert').set('html','Lo sentimos, no hay resultados para la búsqueda.');
					$('hechos-alert').setStyle('display','block');
					$('hechos-alert').fade('hide');
					$('hechos-alert').fade(1);
					if(vtktabs > 8 && $('divcat' + vtktabs))$('divcat' + vtktabs).destroy();
					setCat($random(0, 9));
				}
				if (jsonObj3.total > 0) {
					pagina = jsonObj3.pag;
					if (jsonObj3.prev == 1) {
						$('pagerprev').addClass('hechos-apageron');
						$('pagerprev').setStyle('display', 'block');
					}
					else $('pagerprev').setStyle('display', 'none');
					if (jsonObj3.next == 1) {
						$('pagernext').addClass('hechos-apageron');
						$('pagernext').setStyle('display', 'block');
					}
					else $('pagernext').setStyle('display', 'none');
					pushVtk(jsonObj3.videonews);
					if(!$defined(catTotal)){
						catTotal = actualCat;
						vidsTotal = jsonObj3.total;
						getpage = (jsonObj3.total)/12;
						if(getpage < 1)getpage = 1;
						getpage = Math.ceil(getpage);
					}
					else if(catTotal!=actualCat){
						catTotal = actualCat;
						vidsTotal = jsonObj3.total;
						getpage = (jsonObj3.total)/12;
						if(getpage < 1)getpage = 1;
						getpage = Math.ceil(getpage);
					}
					$('pagestatus').set('html','Total de videos:&nbsp;' + vidsTotal + ',' + '&nbsp;Página&nbsp;' + jsonObj3.pag + '&nbsp;de&nbsp;' + getpage);
				}
			}
		}
	}).post({
		'cat': cat,
		'to': to,
		'ref': ref
	});
	//}).post({'lastvt': lastVideoNew, 'cat': cat});
	firstLoad = true;
}
function pushVtk(json){
	var hCont = 1;
	json.each(function(value,index){
		if(hCont < 13){
			var vpos = json[index].id;
			var arrvtElems = new Array();
			var ntime = formatHour(json[index].istamp);
			var nday = (json[index].istamp).substr(0,2);
			var nmonth = tellMonth( eval((json[index].istamp).substr(2,2)) - 1 );
			var titulo = json[index].titulo;
			if(titulo.length > 69)titulo = titulo.substr(0,69) + '...';
			arrvtElems[0] = json[index].idcat;
			arrvtElems[1] = json[index].cat;
			arrvtElems[2] = json[index].titulo;
			arrvtElems[3] = json[index].istamp;
			arrvtElems[4] = json[index].istamp;
			arrvtElems[5] = json[index].vlink;
			//if(json[index].preview == null)arrvtElems[6] = 'http://static.hechos.tv/hechos/images2009/preview.jpg';
			//else arrvtElems[6] = json[index].preview;
			arrvtElems[6] = "null";
			if(json[index].imgb == null)arrvtElems[7] = 'http://static.hechos.tv/hechos/images2009/th_default_188x124.jpg';
			else arrvtElems[7] = json[index].imgb;
			if(json[index].imgs == null)arrvtElems[8] = 'http://static.hechos.tv/hechos/images2009/th_default_75x50.jpg';
			else arrvtElems[8] = json[index].imgs;
			arrvtElems[9] = json[index].dur;
			arrvtElems[10] = json[index].camp;
			arrvtElems[11] = json[index].rank;
			arrvtElems[12] = json[index].resumen;
			arrVtk[vpos] = arrvtElems;
			injectPlaceHolder(vpos,json[index].dur,arrvtElems[7],json[index].cat,titulo,ntime,nday,nmonth);
			lastVtk = eval(json[index].id) + 1;
			hCont++;
		}
	});
	if(vtkOpen)expandVideos();
}
function injectPlaceHolder(where,dur,imgb,cat,titulo,ntime,nday,nmonth){
	if(eval(nday)<10)nday = nday.substr(1,1);
	var vtk = $('hechos-vteca')
	var placeholder = new Element('div',{'class':'hechos-placeholder'});
	var holder = new Element('div',{'class':'hechos-holder'});
	var divvtkimg = new Element('div',{'class':'hechos-divvtkimg'});
	var vtkimg = new Element('img',{'id':'vtkimg' + where,'class':'noboth','src':imgb});
	var alphapanel = new Element('div',{'class':'hechos-alphapanel'});
	var vtkcontrol = new Element('div',{'id':'vtkcontrol' + where,'class':'hechos-vtkcontrol'});
	var avtkcontrol = new Element('a',{'id':'vtkacontrol' + where,'class':'hechos-imglink','href':'javascript:addfromVtk(' + where + ')'});
	var vtkimgcontrol = new Element('img',{'id':'vtkimgcontrol' + where,'class':'noboth','src':'http://static.hechos.tv/hechos/images2009/vidplus.gif','alt':''});
	var vtkplay = new Element('div',{'class':'hechos-vtkplay'});
	var avtkplay = new Element('a',{'id':'avtkplay' + where,'class':'hechos-imglink','href':'javascript:playVideo("' + where + 'vtk");'});
	var vtkimgplay = new Element('img',{'class':'noboth','src':'http://static.hechos.tv/hechos/images2009/vidplay.gif','alt':''});
	var vidpanel = new Element('div',{'id':'vidpanel' + where,'class':'hechos-vidpanel','html':dur});
	var vtktxt = new Element('div',{'class':'hechos-vtktxt nopad'});
	var ptitle = new Element('a',{'id':'vtktitle' + where,'class':'hechos-ptitlesmall noboth','html':titulo,'href':'javascript:playVideo("' + where + 'vtk");'});
	var br = new Element('br');
	var pcat = new Element('p',{'class':'hechos-ptitlecat noboth','html':ntime + '&nbsp;-&nbsp;' + nday + '&nbsp;de&nbsp;' + nmonth});
	vtkimgplay.inject(avtkplay);avtkplay.inject(vtkplay);vtkplay.inject(alphapanel);vtkimgcontrol.inject(avtkcontrol);avtkcontrol.inject(vtkcontrol);vtkcontrol.inject(alphapanel);vidpanel.inject(alphapanel);vtkimg.inject(divvtkimg);alphapanel.inject(divvtkimg);ptitle.inject(vtktxt);br.inject(vtktxt);pcat.inject(vtktxt);divvtkimg.inject(holder);vtktxt.inject(holder);holder.inject(placeholder);placeholder.inject(vtk);
	if(arrPlist.has(where + 'vtk'))setVtkAdded(where);
	$('avtkplay' + where).addEvent('click',function(){
		playfromVtk();
	});
	$('vtktitle' + where).addEvent('click',function(){
		playfromVtk();
	});
}
function getVtkHeight(){
	var totalHolders = $$('#hechos-vteca div.hechos-placeholder');
	totalHolders = totalHolders.length;
	if(totalHolders <= 4)autoHeight = '202px';
	if(totalHolders > 4 && totalHolders <= 8)autoHeight = '404px';
	if(totalHolders > 8)autoHeight = '608px';
	return autoHeight;
}
function expandVideos(){
	vtkOpen = true;
	var vtecaFx = new Fx.Tween($('hechos-vteca'));
	vtecaFx.start('height', getVtkHeight());
	prevHeight = getVtkHeight();
	$('hechos-vtecaexp').set('html','Contraer Videoteca <img alt="" src="http://static.hechos.tv/hechos/images2009/scroll-up.gif" class="hechos-imgexp2"/>');
	$('hechos-vtecaexp').removeEvents();
	$('hechos-vtecaexp').addEvent('click',function(e){
		e.stop();
		collapseVideos();
	});	
}
function collapseVideos(){
	vtkOpen = false;
	var vtecaFx = new Fx.Tween($('hechos-vteca'));	
	vtecaFx.start('height', '202px');
	$('hechos-vtecaexp').set('html','Expandir Videoteca <img alt="" src="http://static.hechos.tv/hechos/images2009/hechos-exp.gif" class="hechos-imgexp"/>');
	$('hechos-vtecaexp').removeEvents();
	$('hechos-vtecaexp').addEvent('click',function(e){
		e.stop();
		expandVideos();
	});
}
function addfromVtk(x){
	if (arrPlist.getLength() < 20) {
		setVtkAdded(x);
		arrPlist[x + 'vtk'] = arrVtk[x.toString()];
		if(place == 1){
			var ntime = arrVtk[x][4].substr(6,2) + ':' + arrVtk[x][4].substr(8,2);
			var nday = arrVtk[x][4].substr(0,2);
			var nmonth = tellMonth( eval(arrVtk[x][4].substr(2,2)) - 1 );
			var titulo = arrVtk[x][2];
			if(titulo.length > 80)titulo = titulo.substr(0,80) + '...';
			injectVidRow(x + 'vtk',arrVtk[x][9],arrVtk[x][8],arrVtk[x][1],titulo,ntime,nday,nmonth);
		}
		else $('divplist').tween('background-color', '#8d000c');
		plistsize++;
	}
	else {
		scrollWindow('mainmid',0);
		$('hechos-alert').setStyle('top',(document.documentElement.scrollTop + 300).toString() + 'px');
		$('hechos-palert').set('html','Has excedido el número máximo de elementos en tu Playlist');
		$('hechos-alert').setStyle('display','block');
		$('hechos-alert').fade('hide');
		$('hechos-alert').fade(1);
	}
}
function setVtkAdded(x){
	$('vtkimg' + x).fade(0.3);
	$('vidpanel' + x).empty();
	$('vtkcontrol' + x).fade(0);
	var atolist = new Element('a',{'id':'gotolist' + x,'class':'hechos-avidpanel','href':'javascript:void(0);','html':'Ir a mi playlist'});
	atolist.inject($('vidpanel' + x));
	$('gotolist' + x).addEvent('click',function(e){
		e.stop();
		gotoList();
	});
}
function playfromVtk(){
	scrollWindow('mainmid',0);
}
function gotoList(){
	showPlist();
	scrollWindow('mainmid',0);
	flashBodylist.delay(700);
}
function flashBodylist(){
	if(hTheme == 1)activateFade('bodylist','background-color',300,'rgb(141,0,12)','rgb(26,26,26)');
	else activateFade('bodylist','background-color',300,'rgb(141,0,12)','rgb(206,206,206)');
}
function scrollWindow(place,y){
	var myFx = new Fx.Scroll(window, {
    	duration: 1000,
    	wait: false,
		offset: {
	        'x': 0,
	        'y': y
	    }
	}).toElement($(place));
}
function formatHour(stamp){
	stamp = stamp.toString();
	var mer = 'am';
	var hour = stamp.substr(6,2);
	if(hour == '00'){
		hour = '12';
	}
	else if(hour == '24'){
		hour = '12';
	}
	else if(hour >= '12'){
		mer = 'pm';
		if(hour == '12'){
			hour = '12';
		}
		else{
			hour = (eval(hour)) - 12;
			hour = hour.toString();
			if(eval(hour) < 10)hour = '0' + '' + hour;
		}
	}
	var intHour = hour;
	if(intHour[0] == 0)intHour = eval(hour.substr(1,1));
	if(intHour < 10)hour = hour.substr(1,1);
	var formated = hour + ':' + stamp.substr(8,2) + '' + '&nbsp;' + mer;
	return formated;
}
function vtkScroller(){
	var lastElement = $('vtkswrapper').getLast('div[id^=divcat]');
	var totalWidth = $('vtkswrapper').getStyle('width');
	totalWidth = totalWidth.replace(/px/,'');
	var intTotal = eval(totalWidth);
	var limitX = ($('vtklimit').getPosition($('vtkswrapper'))).x;
	var offset = intTotal - limitX;
	offset = offset - (offset * 2);
	offset = offset + 9;
	vtkFxright = new Fx.Scroll('hechos-vtks', {
		offset: {
			'x': offset,
			'y': 0
		},
		transition: Fx.Transitions.linear,
		duration: 2000,
		wait: true
	});
	vtkFxleft = new Fx.Scroll('hechos-vtks', {
		duration: 2000,
		wait: true
	});
	$('hechos-vsr').addEvent('mouseover',function(e){
		e.stop();
		vtkFxright.toRight();
	});
	$('hechos-vsr').addEvent('mouseout',function(e){
		e.stop();
		vtkFxright.cancel();
	});
	$('hechos-vsl').addEvent('mouseover',function(e){
		e.stop();
		vtkFxleft.toLeft();
	});
	$('hechos-vsl').addEvent('mouseout',function(e){
		e.stop();
		vtkFxleft.cancel();
	});
}
function mailcheck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    return false;
	}
	if (str.indexOf(at,(lat+1))!=-1){
	   return false;
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	   return false;
	}
	if (str.indexOf(dot,(lat+2))==-1){
	   return false;
	}
	if (str.indexOf(" ")!=-1){
	   return false;
	}
	return true;					
}

// -------------- adserver code

OAS_sitepage = "hechos_tv";
OAS_listpos= "Top";


var adServer = "http://ads.hechos.tv";
var staticServer ="http://static.hechos.tv";
OAS_url = adServer + '/RealMedia/ads/';OAS_query = '';
OAS_target = '_top';
OAS_version = 10;
OAS_rn = '001234567890'; OAS_rns = '1234567890';
OAS_rn = new String (Math.random()); OAS_rns = OAS_rn.substring (2, 11);
function OAS_NORMAL(pos) {
 document.write('<A HREF="' + OAS_url + 'click_nx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '!' + pos + '?' + OAS_query + '" TARGET=' + OAS_target + '>');
 document.write('<IMG SRC="' + OAS_url + 'adstream_nx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '!' + pos + '?' + OAS_query + '" BORDER=0></A>');
}
OAS_version = 11;
if ((navigator.userAgent.indexOf('Mozilla/3') != -1) || (navigator.userAgent.indexOf('Mozilla/4.0 WebTV') != -1))
 OAS_version = 10;
if (OAS_version >= 11)
 document.write('<SCR' + 'IPT LANGUAGE=JavaScript1.1 SRC="' + OAS_url + 'adstream_mjx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '?' + OAS_query + '"><\/SCRIPT>');
document.write('');
function OAS_AD(pos) {
    try{
        if (OAS_version >= 11)
        OAS_RICH(pos);
        else
        OAS_NORMAL(pos);
    }catch(e){
    }
}
//Seteo de variables
var OASposToShow = new Array();

function OASmostrarTOP(){
		if(document.getElementById("oasTOP") == null) return;
		OASposToShow[OASposToShow.length] = "oasTOP";
		OAS_AD("Top");
	}//Funciones de Inicio

//Funciones de Inicio
function OASstart(){
	if (document.all) window.attachEvent('onload', setPos);
	else window.addEventListener('load', setPos, false);
}
function setPos() {
  for(i=0; i < OASposToShow.length; i++){
   document.getElementById(OASposToShow[i]).appendChild(document.getElementById(OASposToShow[i]+"src"));
   document.getElementById(OASposToShow[i]+"src").style.display='inline';
  }
}
//Funciones de richmedia
// flash_ultimate
var Localbanner = '';
var remoteBanner= '';
var LocalimageAlternate='';
var RemoteImageAlternate='';
var a3rdPartyclick='';
var a3rdPartycount1x1='';
var width = '';
var height = '';
var PAGE = "";
var RAND = "";
var POS = "";
var CAMP = "";
var IMAGE = "";
var USER = "";
var clickTAG = "oas";
var Flash_OASALTTEXT="Haz Click";
var Flash_OASTARGET="_blank";
var Flash_OASPROTOCOL="http://";
var Flash_OASADID="ad_banner";
var Flash_VERSION=6;
var Flash_WMODE="transparent";
function show_flash(){
var Flash_OASDIM="WIDTH='" + width  + "' HEIGHT='" + height  + "'";
var Flash_OASCLICK= adServer+"/RealMedia/ads/click_lx.ads/"+PAGE+"/"+RAND+"/"+POS+"/"+CAMP+"/"+IMAGE+"/"+USER;
var Flash_SWFCLICKVARIABLE="?"+clickTAG+"="+Flash_OASCLICK+"?"+a3rdPartyclick;
var Flash_SWFFILE = adServer+'/RealMedia/ads/Creatives/'+CAMP+'/'+Localbanner;
if (staticServer){
 var Flash_SWFFILE = staticServer+'/RealMedia/ads/Creatives/'+CAMP+'/'+Localbanner;
}
if (remoteBanner){
 Flash_SWFFILE = remoteBanner;
}
if (LocalimageAlternate || RemoteImageAlternate){
	var MM_contentVersion = Flash_VERSION;
	var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
	if ( plugin ) {
		var words = navigator.plugins["Shockwave Flash"].description.split(" ");
		    for (var i = 0; i < words.length; ++i)
		    {
			if (isNaN(parseInt(words[i])))
			continue;
			var MM_PluginVersion = words[i]; 
		    }
		var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
	}
	else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.appVersion.indexOf("Win") != -1)) {
		document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
		document.write('on error resume next \n');
		document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
		document.write('</SCR' + 'IPT\> \n');
	}
}
if ( MM_FlashCanPlay || (! RemoteImageAlternate && ! LocalimageAlternate)  ){
document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="'+Flash_OASPROTOCOL+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+Flash_VERSION+',0,0,0" ID="'+Flash_OASADID+'" '+Flash_OASDIM+' ALIGN="">');
document.write('<PARAM NAME=movie VALUE="'+Flash_SWFFILE+'"><PARAM NAME=quality VALUE=high><PARAM NAME=wmode VALUE="'+Flash_WMODE+'">'); 
document.write('<PARAM name=FlashVars VALUE="' + clickTAG + '=' + Flash_OASCLICK +'">');
document.write('<EMBED src="'+Flash_SWFFILE+'" FlashVars="' + clickTAG + '=' + Flash_OASCLICK +'"  quality=high wmode='+Flash_WMODE+' swLiveConnect=FALSE '+Flash_OASDIM+' NAME="'+Flash_OASADID+'" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="'+Flash_OASPROTOCOL+'www.macromedia.com/go/getflashplayer">');
document.write('</EMBED></OBJECT>');
} else {
document.write('<a href="'+Flash_OASCLICK+'" target="'+Flash_OASTARGET+'"><IMG SRC="'+LocalimageAlternate + RemoteImageAlternate +'" '+Flash_OASDIM+' BORDER=0 alt="'+Flash_OASALTTEXT+'"></a>');
} 
if (a3rdPartycount1x1){
	document.write('<IMG SRC="'+a3rdPartycount1x1+'" width="1" height="1" BORDER=0 ></a>');}
}// end of show flash
// .... code para poner todo de acuerdo con el oas
window.addEvent('load',function(){
  window.setForOas = function(){
    $('nav1divbanner').setStyle('display','block');
    $('bnpanelabsolute').setStyle('top',(parseInt($('bn_maintop').offsetTop) + parseInt($('bn_maintop').offsetHeight)).toString()+'px');
  };
  window.document.body.onafterupdate = function(){
    setForOas();
  };
  setForOas();
  });
// .............................................................................
/*
window.addEvent('load',function(){
				vtkwrap = vtkwrap + 200;
				var vtkwidth = vtkwrap + 'px';
				$('vtkswrapper').setStyle('width',vtkwrap);
				if(vtkwrap>870 && !vtkscrollable){
					vtkscrollable = true;
					$('hechos-vsl').setStyle('display','block');
					$('hechos-vsl').fade('hide');
					$('hechos-vsl').fade(1);
					$('hechos-vsr').setStyle('display','block');
					$('hechos-vsr').fade('hide');
					$('hechos-vsr').fade(1);
				}
				vtktabs++;
				var nextTab = vtktabs;
				var newtab = new Element('div',{'id':'divcat' + nextTab,'class':'hechos-tab hechos-taboff'});
				var newa = new Element('a',{'id':'acat' + nextTab,'class':'hechos-atabon','href':'javascript:void(0);','onfocus':'blur();','html':'Huracanes&nbsp;&nbsp;'});
				var aclose = new Element('a',{'id':'avtkclose' + nextTab,'class':'hechos-aimg noboth','href':'javascript:void(0);'});
				var imgclose = new Element('img',{'class':'hechos-aimg','src':'http://static.hechos.tv/hechos/images2009/closetab.gif'});
				imgclose.inject(aclose);newa.inject(newtab);aclose.inject(newtab);newtab.inject($('vtklimit'),'before');
                                document.getElementById('vtkswrapper').insertBefore(document.getElementById('divcat10'),document.getElementById('divcat1'));
				escaped = escape('TEMA58');
				arrFind[nextTab.toString()] = escaped;
				vtkScroller();
//				if (vtkscrollable) {
//					var lastTab = $('vtkswrapper').getLast('div[id^=divcat]');
//					var elX = ($('vtklimit').getPosition($('vtkswrapper'))).x;
//					var elXTotal = eval(elX) - 870;
//					vtkFxright.set(elXTotal, 0);
//				}
				//this.blur();this.value = 'Buscar Videos...';
				setCat(nextTab);
				$('acat' + nextTab).addEvent('click',function(e){
					e.stop();
					setCat(nextTab);
				});
				$('avtkclose' + nextTab).addEvent('click',function(e){
					e.stop();
					var tmpid = this.id
					var intId = tmpid.replace(/avtkclose/,'');
					intId = eval(intId);
					var isOn = $('divcat' + intId).hasClass('hechos-tab hechos-tabon');
					if(isOn){
						vtkFxleft.set(0, 0);
						setCat($random(0, 9));
					}					
					$('divcat' + nextTab).destroy();
					arrFind.erase(nextTab.toString());
					vtkwrap = vtkwrap - 200;
					var vtkwidth = vtkwrap + 'px';
					$('vtkswrapper').setStyle('width',vtkwidth);
					var elX = ($('vtklimit').getPosition($('vtkswrapper'))).x;
					var elXTotal = eval(elX) - 870;
					vtkFxright.set(elXTotal, 0);
					vtkScroller();
				});
setTimeout('setCat(0)','2000');
});
*/
// .............................................................................
function busquedaTema58(){
				vtkwrap = vtkwrap + 200;
				var vtkwidth = vtkwrap + 'px';
				$('vtkswrapper').setStyle('width',vtkwrap);
				if(vtkwrap>870 && !vtkscrollable){
					vtkscrollable = true;
					$('hechos-vsl').setStyle('display','block');
					$('hechos-vsl').fade('hide');
					$('hechos-vsl').fade(1);
					$('hechos-vsr').setStyle('display','block');
					$('hechos-vsr').fade('hide');
					$('hechos-vsr').fade(1);
				}
				vtktabs++;
				var nextTab = vtktabs;
				var newtab = new Element('div',{'id':'divcat' + nextTab,'class':'hechos-tab hechos-taboff'});
				var newa = new Element('a',{'id':'acat' + nextTab,'class':'hechos-atabon','href':'javascript:void(0);','onfocus':'blur();','html':'Detr&aacute;s del bal&oacute;n&nbsp;'});
				var aclose = new Element('a',{'id':'avtkclose' + nextTab,'class':'hechos-aimg noboth','href':'javascript:void(0);'});
				var imgclose = new Element('img',{'class':'hechos-aimg','src':'http://static.hechos.tv/hechos/images2009/closetab.gif'});
				imgclose.inject(aclose);newa.inject(newtab);aclose.inject(newtab);newtab.inject($('vtklimit'),'before');
                                document.getElementById('vtkswrapper').insertBefore(document.getElementById('divcat10'),document.getElementById('divcat1'));
				escaped = escape('TEMA229');
				arrFind[nextTab.toString()] = escaped;
				vtkScroller();
                                /*
				if (vtkscrollable) {
					var lastTab = $('vtkswrapper').getLast('div[id^=divcat]');
					var elX = ($('vtklimit').getPosition($('vtkswrapper'))).x;
					var elXTotal = eval(elX) - 870;
					vtkFxright.set(elXTotal, 0);
				}
                                */
				//this.blur();this.value = 'Buscar Videos...';
				setCat(nextTab);
				$('acat' + nextTab).addEvent('click',function(e){
					e.stop();
					setCat(nextTab);
				});
				$('avtkclose' + nextTab).addEvent('click',function(e){
					e.stop();
					var tmpid = this.id
					var intId = tmpid.replace(/avtkclose/,'');
					intId = eval(intId);
					var isOn = $('divcat' + intId).hasClass('hechos-tab hechos-tabon');
					if(isOn){
						vtkFxleft.set(0, 0);
						setCat($random(0, 9));
					}					
					$('divcat' + nextTab).destroy();
					arrFind.erase(nextTab.toString());
					vtkwrap = vtkwrap - 200;
					var vtkwidth = vtkwrap + 'px';
					$('vtkswrapper').setStyle('width',vtkwidth);
					var elX = ($('vtklimit').getPosition($('vtkswrapper'))).x;
					var elXTotal = eval(elX) - 870;
					vtkFxright.set(elXTotal, 0);
					vtkScroller();
				});
                                //setTimeout('setCat(0)','2000');
                                setTimeout('busquedaTema132()','2000');
}
// .............................................................................
function busquedaTema132(){
				vtkwrap = vtkwrap + 200;
				var vtkwidth = vtkwrap + 'px';
				$('vtkswrapper').setStyle('width',vtkwrap);
				if(vtkwrap>870 && !vtkscrollable){
					vtkscrollable = true;
					$('hechos-vsl').setStyle('display','block');
					$('hechos-vsl').fade('hide');
					$('hechos-vsl').fade(1);
					$('hechos-vsr').setStyle('display','block');
					$('hechos-vsr').fade('hide');
					$('hechos-vsr').fade(1);
				}
				vtktabs++;
				var nextTab = vtktabs;
				var newtab = new Element('div',{'id':'divcat' + nextTab,'class':'hechos-tab hechos-taboff'});
				var newa = new Element('a',{'id':'acat' + nextTab,'class':'hechos-atabon','href':'javascript:void(0);','onfocus':'blur();','html':'Iniciativa M&eacute;xico&nbsp;'});
				var aclose = new Element('a',{'id':'avtkclose' + nextTab,'class':'hechos-aimg noboth','href':'javascript:void(0);'});
				var imgclose = new Element('img',{'class':'hechos-aimg','src':'http://static.hechos.tv/hechos/images2009/closetab.gif'});
				imgclose.inject(aclose);newa.inject(newtab);aclose.inject(newtab);newtab.inject($('vtklimit'),'before');
                                document.getElementById('vtkswrapper').insertBefore(document.getElementById('divcat11'),document.getElementById('divcat1'));
				escaped = escape('TEMA232');
				arrFind[nextTab.toString()] = escaped;
				vtkScroller();
                                /*
				if (vtkscrollable) {
					var lastTab = $('vtkswrapper').getLast('div[id^=divcat]');
					var elX = ($('vtklimit').getPosition($('vtkswrapper'))).x;
					var elXTotal = eval(elX) - 870;
					vtkFxright.set(elXTotal, 0);
				}
                                */
				//this.blur();this.value = 'Buscar Videos...';
				setCat(nextTab);
				$('acat' + nextTab).addEvent('click',function(e){
					e.stop();
					setCat(nextTab);
				});
				$('avtkclose' + nextTab).addEvent('click',function(e){
					e.stop();
					var tmpid = this.id
					var intId = tmpid.replace(/avtkclose/,'');
					intId = eval(intId);
					var isOn = $('divcat' + intId).hasClass('hechos-tab hechos-tabon');
					if(isOn){
						vtkFxleft.set(0, 0);
						setCat($random(0, 9));
					}					
					$('divcat' + nextTab).destroy();
					arrFind.erase(nextTab.toString());
					vtkwrap = vtkwrap - 200;
					var vtkwidth = vtkwrap + 'px';
					$('vtkswrapper').setStyle('width',vtkwidth);
					var elX = ($('vtklimit').getPosition($('vtkswrapper'))).x;
					var elXTotal = eval(elX) - 870;
					vtkFxright.set(elXTotal, 0);
					vtkScroller();
				});
                                setTimeout('setCat(0)','2000');
}

function busquedaTema58Timeout(){
  setTimeout(busquedaTema58,'2000');
}

function addPestaniaBusqueda(){
  vtkwrap = vtkwrap + 200;
  var vtkwidth = vtkwrap + 'px';
  $('vtkswrapper').setStyle('width',vtkwrap);
  if(vtkwrap>870 && !vtkscrollable){
    vtkscrollable = true;
    $('hechos-vsl').setStyle('display','block');
    $('hechos-vsl').fade('hide');
    $('hechos-vsl').fade(1);
    $('hechos-vsr').setStyle('display','block');
    $('hechos-vsr').fade('hide');
    $('hechos-vsr').fade(1);
  }
  vtktabs++;
  var nextTab = vtktabs;
  var newtab = new Element('div',{'id':'divcat' + nextTab,'class':'hechos-tab hechos-taboff'});
  var newa = new Element('a',{'id':'acat' + nextTab,'class':'hechos-atabon','href':'javascript:void(0);','onfocus':'blur();','html':window.arrayPestaniasBusqueda[window.parCount][1]});
  var aclose = new Element('a',{'id':'avtkclose' + nextTab,'class':'hechos-aimg noboth','href':'javascript:void(0);'});
  var imgclose = new Element('img',{'class':'hechos-aimg','src':'http://static.hechos.tv/hechos/images2009/closetab.gif'});
  imgclose.inject(aclose);newa.inject(newtab);aclose.inject(newtab);newtab.inject($('vtklimit'),'before');
  document.getElementById('vtkswrapper').insertBefore(document.getElementById('divcat'+window.arrayPestaniasBusqueda[window.parCount][2]),document.getElementById('divcat1'));
  escaped = escape('TEMA'+window.arrayPestaniasBusqueda[window.parCount][0]);
  arrFind[nextTab.toString()] = escaped;
  vtkScroller();
  setCat(nextTab);
  $('acat' + nextTab).addEvent('click',function(e){
      e.stop();
      setCat(nextTab);
    });
  $('avtkclose' + nextTab).addEvent('click',function(e){
      e.stop();
      var tmpid = this.id
        var intId = tmpid.replace(/avtkclose/,'');
      intId = eval(intId);
      var isOn = $('divcat' + intId).hasClass('hechos-tab hechos-tabon');
      if(isOn){
        vtkFxleft.set(0, 0);
        setCat($random(0, 9));
      }
      $('divcat' + nextTab).destroy();
      arrFind.erase(nextTab.toString());
      vtkwrap = vtkwrap - 200;
      var vtkwidth = vtkwrap + 'px';
      $('vtkswrapper').setStyle('width',vtkwidth);
      var elX = ($('vtklimit').getPosition($('vtkswrapper'))).x;
      var elXTotal = eval(elX) - 870;
      vtkFxright.set(elXTotal, 0);
      vtkScroller();
    });
  if(window.parCount < (window.arrayPestaniasBusqueda.length - 1)){
    window.parCount ++;
    setTimeout(addPestaniaBusqueda,1000);
  }else{
    setTimeout('setCat(0)','2000');
  }
}


  window.parCount = 0;
  window.arrayPestaniasBusqueda = new Array(
                                            new Array('232','Iniciativa M&eacute;xico','10'),
                                            new Array('236','Lluvias en M&eacute;xico 2010','11'),
                                            new Array('237','Ley Arizona','12')
                                            );
window.addEvent('load',function(){setTimeout(addPestaniaBusqueda,1000);});
//setTimeout(addPestaniaBusqueda,1000);
