function searching(){
	var search1=document.getElementById('search').value.replace(/^\s+|\s+$/g,"");
	if(search1.length<3){
		if(language==2){
			alert('Necesita especificar el texto a buscar, minimo 3 caracteres');
		}else{
			alert('You must specify a string to search, minimum 3 characters');
		}
	}else{
		document.getElementById('search').value=search1;
		document.formsearch.submit();
	}
}
function overchange(type, xlang, button){
	var lang="";
	switch(language){
		case 1:
			lang="en";
			break;
		case 2:
			lang="es";
			break;
		default:
			lang="en";
			break;
	}
	if(type==3 && document.getElementById(lang+button)){
		language=xlang;
		source=1;
		if(button!=selected){
			document.getElementById('content').style.display='none';
			document.getElementById('divcontent').innerHTML='';
			document.getElementById('channelslist').style.height='0px';
			for(f=1;f<=9;f++){
				if(f==button){
					document.getElementById(lang+f).src='../images/button-'+lang+f+'n.gif';
				}else{
					document.getElementById(lang+f).src='../images/button-'+lang+f+'.gif';
				}
			}
			selected=button;
			openw();
		}else{
			document.getElementById(lang+button).src='../images/button-'+lang+button+'n.gif';
			selected=0;
			closew();
		}
	}else if(type==1 && document.getElementById(lang+button) && button!=selected){
		document.getElementById(lang+button).src='../images/button-'+lang+button+'n.gif';
	}else if(button!=selected){
		document.getElementById(lang+button).src='../images/button-'+lang+button+'.gif';
	}
}
function ajax(type){
	if(!isNaN(type) && type>0 && type<4){
		var pager=false;
		switch(type){
			case 1:
				url='http://www.caboom.tv/ajax/loadjustin.php?cat='+selected+'&language='+language;
				break;
			case 2:
				url='http://www.caboom.tv/ajax/loadlivestream.php?cat='+selected+'&language='+language;
				break;
			case 3:
				url='http://www.caboom.tv/ajax/loadustream.php?cat='+selected+'&language='+language;
				break;
		}
		if(window.XMLHttpRequest){
			pager=new XMLHttpRequest ();
			if(pager.overrideMimeType){
				pager.overrideMimeType('text/html');
			}
		}else if(window.ActiveXObject){
			try{
				pager=new ActiveXObject ("Msxml2.XMLHTTP");
			}
			catch(e){
				try{
					pager=new ActiveXObject ("Microsoft.XMLHTTP");
				}
				catch(e){
				}
			}
		}else{
			alert('ERROR: you need to update your browser');
			return false;
		}
		pager.onreadystatechange=function(){
			loadpage(pager, type);
		};
		pager.open('GET', url, true);
		pager.send(null);
	}
}
function loadpage (pager, type){
	if(pager.readyState==4){
		if(type==source){
			var result=pager.responseText;
			document.getElementById('divcontent').innerHTML=result;
			if(result!=""){
				document.getElementById('aright').innerHTML='<img src="../images/buttonarrow4.gif" width="13" height="179" onmouseover="this.src=\'../images/buttonarrow4n.gif\'" onmouseout="this.src=\'../images/buttonarrow4.gif\'" onclick="next();" style="cursor: pointer" border="0">';
			}else{
				var text='<div style="width: 930px; height: 50px; padding: 70px 0px 30px 0px; text-align: center;">';
				if(language==2){
					text+='<font class="bold" style="color: #999999; font-size: 18px;">No pudimos encontrar canales en esta categor&iacute;a</font>';
				}else{
					text+='<font class="bold" style="color: #999999; font-size: 18px;">We couldn\'t find channels in this category</font>';
				}
				text+='</div>';
				document.getElementById('divcontent').innerHTML=text;
			}
		}
	}
}
function closew(){
	if(parseInt(document.getElementById('channelslist').style.height)>0){
		var step=10;
		if(!window.moveclose){
			document.getElementById('content').style.display='none';
			document.getElementById('divcontent').innerHTML='';
			oldheight=201;
		}
		oldheight=oldheight-step;
		if(oldheight>0){
			document.getElementById('channelslist').style.height=oldheight+'px';
			moveclose=setTimeout("closew()",15);
		}else{
			document.getElementById('channelslist').style.height='0px';
			clearTimeout(moveclose);
			moveclose=undefined;
		}
	}
}
function openw(){
	var step=10;
	if(!window.moveopen){
		newheight=0;
		time=50;
		count=1;
	}
	newheight=newheight+step;
	document.getElementById('channelslist').style.height=newheight+'px';

	if(newheight<201){
		if(count<50){
			time=time-5;
		}else if(count>55){
			time=time+5;
		}
		if(time<1) time=1;
		if(time>50) time=50;
		count++;
		moveopen=setTimeout("openw()",time);
	}else{
		clearTimeout(moveopen);
		moveopen=undefined;
		page=1;
		document.getElementById('channelslist').style.height='201px';
		document.getElementById('content').style.display='';
		source=0;
		changesource(1);
	}
}
function changesource(type){
	if(type!=source){
		switch(type){
			case 1:
				page=1;
				source=1;
				document.getElementById('divcontent').innerHTML='';
				document.getElementById('aleft').innerHTML='<img src="images/buttonarrow3n.gif" width="13" height="179">';
				document.getElementById('aright').innerHTML='<img src="images/buttonarrow4n.gif" width="13" height="179">';
				ajax(1);	
				break;
			case 2:
				page=1;
				document.getElementById('divcontent').innerHTML='';
				document.getElementById('aleft').innerHTML='<img src="images/buttonarrow3n.gif" width="13" height="179">';
				document.getElementById('aright').innerHTML='<img src="images/buttonarrow4n.gif" width="13" height="179">';
				source=2;
				ajax(2);	
				break;
			case 3:
				page=1;
				source=3;
				document.getElementById('divcontent').innerHTML='';
				document.getElementById('aleft').innerHTML='<img src="images/buttonarrow3n.gif" width="13" height="179">';
				document.getElementById('aright').innerHTML='<img src="images/buttonarrow4n.gif" width="13" height="179">';
				ajax(3);	
				break;
		}
	}
}
function next(){
	document.getElementById('aleft').innerHTML='<img src="../images/buttonarrow3.gif" width="13" height="179" onmouseover="this.src=\'../images/buttonarrow3n.gif\'" onmouseout="this.src=\'../images/buttonarrow3.gif\'" onclick="previous();" style="cursor: pointer" border="0">';
	var width=parseInt(document.getElementById('contentx').style.width);
	var totalp=parseInt(width/930);
	if(page<=totalp){
		page++;
		moveleft();
		if(page>=totalp){
			document.getElementById('aright').innerHTML='<img src="images/buttonarrow4n.gif" width="13" height="179">';
		}
	}
}
function previous(){
	if(page>1){
		document.getElementById('aright').innerHTML='<img src="../images/buttonarrow4.gif" width="13" height="179" onmouseover="this.src=\'../images/buttonarrow4n.gif\'" onmouseout="this.src=\'../images/buttonarrow4.gif\'" onclick="next();" style="cursor: pointer" border="0">';
		page--;
		moveright();
		if(page<=1){
			document.getElementById('aleft').innerHTML='<img src="images/buttonarrow3n.gif" width="13" height="179">';
		}
	}
}
function moveleft(){
	if (window.moverightvar){
		clearTimeout(moverightvar);
		moverightvar=undefined;
	}
	if (parseInt(document.getElementById('contentx').style.left)>(-930*(page-1))){
		document.getElementById('contentx').style.left=parseInt(document.getElementById('contentx').style.left)-30+"px";
		moveleftvar=setTimeout("moveleft()",10);
	}else{
		clearTimeout(moveleftvar);
		moveleftvar=undefined;
	}
}
function moveright(){
	if (window.moveleftvar){
		clearTimeout(moveleftvar);
		moveleftvar=undefined;
	}
	if (parseInt(document.getElementById('contentx').style.left)<-(930*(page-1))){
		document.getElementById('contentx').style.left=parseInt(document.getElementById('contentx').style.left)+30+"px";
		moverightvar=setTimeout("moveright()",10);
	}else{
		clearTimeout(moverightvar);
		moverightvar=undefined;
	}
}

