// JavaScript Document
// JavaScript Document
function getvideos(treeStructure,pageNum,pageSize,sortClause,filterClause,vidFilterClause){

	matchdomain =window.location.href.match('(.*)\.com');
	domainURL=matchdomain[0];


var req = new Request.HTML({
url:'http://www.tvolucion.com/indextimeajax.php?treeStructure='+treeStructure+'&sortClause='+sortClause+'&pageSize='+pageSize+'&pageNum='+pageNum+'&filterClause='+filterClause+'&vidFilterClause='+vidFilterClause,onSuccess: function(html) {
					//Clear the text currently inside the results div.
					$('mainContainerFull').set('text', '');
//Inject the new DOM elements into the results div.
					$('mainContainerFull').adopt(html);
					
					setTips();
				},
				//Our request will most likely succeed, but just in case, we'll add an
				//onFailure method which will let the user know what happened.
onFailure: function(xhr) {
					$('mainContainerFull').set('text', 'ERROR');
				}
				
			}
			
			).send();

}




function getvideosCom(treeStructure,pageNum,pageSize,sortClause,filterClause,vidFilterClause,type,treeStructureCode){

	matchdomain =window.location.href.match('(.*)\.com');
	domainURL=matchdomain[0];
	
	var req = new Request.HTML({
			url:'http://www.tvolucion.com/indexcomentariosajax.php?type='+type+'&treeStructure='+treeStructure+'&pageSize='+pageSize+'&pageNum='+pageNum+'&filterClause='+filterClause+'&treeStructureCode='+treeStructureCode,  
				onSuccess: function(html) {
					//Clear the text currently inside the results div.
					$('mainContainerFull').set('text', '');
					//Inject the new DOM elements into the results div.
					$('mainContainerFull').adopt(html);					
					
					setTips();
				},
				//Our request will most likely succeed, but just in case, we'll add an
				//onFailure method which will let the user know what happened.
				
				onFailure: function(xhr) {
					$('mainContainerFull').set('text', 'ERROR');
				}
				
			}
			
			).send();

}

var cache;

function getvideosCarrusel(tags,pageNum,pageSize,videoId){

	matchdomain =window.location.href.match('(.*)\.com');
	domainURL=matchdomain[0];

new Ajax.Request('http://www.tvolucion.com/pagcarruselajax.php?tags='+tags+'&videoId='+videoId, {
  method:'get',
  onSuccess: function(transport){
     var videos = transport.responseText.evalJSON();
	 	
		cache = videos.Videos;
		var backHTML = "";
		var itemsHTML = "";
		var nextHTML = "";
		
		backHTML+="<img src=\"http://i2.esmas.com/tvolucion/img/arrow_carrusel_back.gif\" onclick=\"Javascript:backnextVids(8);\" />";
		
		for (i=0; i<cache.length && i<4; i++){
		var tmp = cache[i];
		
			if (tmp.Program.length>40)
				titulo=tmp.Program.substring(0,37)+'...';
			else 
				titulo=tmp.Program;
			if (tmp.EditorialTitle.length>26)
				capitulo=tmp.EditorialTitle.substring(0,23)+'...';
			else 
				capitulo=tmp.EditorialTitle;
		
		
		itemsHTML+="<li>";
		itemsHTML+="<a href=\""+tmp.UrlPublic+"\"><img src=\""+tmp.ThumbnailFilename+"\"/></a>";
		itemsHTML+="<h4 class=\"itemsubTitle\">"+titulo+"</h4>";
		itemsHTML+="<span class=\"itemOptions\">Duraci&oacute;n:"+tmp.Duration+"</span>";
		itemsHTML+="<span class=\"itemOptions\">"+capitulo+"</span>";
		itemsHTML+="</li>";
		}
		
		nextHTML+="<img src=\"http://i2.esmas.com/tvolucion/img/arrow_carrusel_foward.gif\" onclick=\"Javascript:backnextVids(4);\" />";
		
	$("btnCarruselBack").update(backHTML);	
    $("VidcarruselItems").update(itemsHTML);
	$("btnCarruselNext").update(nextHTML);    
   }
});

}

function backnextVids(indice){

		var backHTML = "";
		var itemsHTML = "";
		var nextHTML = "";
		
		var pagBack = indice-4;
		var pagNext = indice+4;
		
		if ((indice+4)>=12)
			pagNext=0;
			
		if ((indice-4)<0)
			pagBack=8; 
		
		backHTML+="<img src=\"http://i2.esmas.com/tvolucion/img/arrow_carrusel_back.gif\" onclick=\"Javascript:backnextVids("+pagBack+");\" />";		
		for (i=indice; i<=(indice+3); i++){
		var tmp = cache[i];
		
			if (tmp.Program.length>40)
				titulo=tmp.Program.substring(0,37)+'...';
			else 
				titulo=tmp.Program;
			if (tmp.EditorialTitle.length>26)
				capitulo=tmp.EditorialTitle.substring(0,23)+'...';
			else 
				capitulo=tmp.EditorialTitle;
		
		itemsHTML+="<li>";
		itemsHTML+="<a href=\""+tmp.UrlPublic+"\"><img src=\""+tmp.ThumbnailFilename+"\"/></a>";
		itemsHTML+="<h4 class=\"itemsubTitle\">"+titulo+"</h4>";
		itemsHTML+="<span class=\"itemOptions\">Duraci&oacute;n:"+tmp.Duration+"</span>";
		itemsHTML+="<span class=\"itemOptions\">"+capitulo+"</span>";
		itemsHTML+="</li>";
		}
		
		nextHTML+="<img src=\"http://i2.esmas.com/tvolucion/img/arrow_carrusel_foward.gif\" onclick=\"Javascript:backnextVids("+pagNext+");\" />";
		
	$("btnCarruselBack").update(backHTML);	
    $("VidcarruselItems").update(itemsHTML);
	$("btnCarruselNext").update(nextHTML);    


}


function getListRelated(treeStructure,pageNum,pageSize){

	matchdomain =window.location.href.match('(.*)\.com');
	domainURL=matchdomain[0];
	
	var req = new Request.HTML({
			url:'http://www.tvolucion.com/list_relatedajax.php?treeStructure='+treeStructure+'&pageSize='+pageSize+'&pageNum='+pageNum,  
				onSuccess: function(html) {
					//Clear the text currently inside the results div.
					$('list_related').set('text', '');
					//Inject the new DOM elements into the results div.
					$('list_related').adopt(html);					
					
					//setTips();
				},
				//Our request will most likely succeed, but just in case, we'll add an
				//onFailure method which will let the user know what happened.
				
				onFailure: function(xhr) {
					$('list_related').set('text', 'ERROR');
				}
				
			}
			
			).send();

}



function getListChapter(treeStructure,pageNum,pageSize){

	matchdomain =window.location.href.match('(.*)\.com');
	domainURL=matchdomain[0];
	
	var req = new Request.HTML({
			url:'http://www.tvolucion.com/list_chapterajax.php?treeStructure='+treeStructure+'&pageSize='+pageSize+'&pageNum='+pageNum,  
				onSuccess: function(html) {
					//Clear the text currently inside the results div.
					$('vid_chapter').set('text', '');
					//Inject the new DOM elements into the results div.
					$('vid_chapter').adopt(html);
					
					//setTips();
				},
				//Our request will most likely succeed, but just in case, we'll add an
				//onFailure method which will let the user know what happened.
				
				onFailure: function(xhr) {
					$('vid_chapter').set('text', 'ERROR');
				}
				
			}
			
			).send();
}


function getVideoSel (filterTreeStructure){

 var filter=filterTreeStructure.split('|')
if (filter[0] == 'all')
	getvideos(filter[1],1,18,'date','','');
if (filter[0] == 'fullepisode')
	getvideos(filter[1],1,18,'date','','fullepisode');
if (filter[0] == 'clips')
	getvideos(filter[1],1,18,'date','','clips');
if (filter[0] == 'votes')
	getvideosCom(filter[1],1,18,'date','','','votes',filter[2]);
if (filter[0] == 'views')
	getvideosCom(filter[1],1,18,'date','today','','views',filter[2]);

}

function showSelect(treeStructure){

	if (isNaN(treeStructure)){
		window.location=treeStructure;
	}
	else{
		var children = $('subCategory').getChildren();
		children.setStyle('display', 'none');
		//if ( treeStructure != '13' )
		$(treeStructure).setStyle('display', 'block');
	}

}