// Activo los scroll segun pantalla

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// Rutinas AJAX
function reproducevideo(video,tiporeproductor)
{
	$('#reproductor').load('index.php?jump=reproductor',{ idvideo : video, reproductor: tiporeproductor});
	$('#infofotograma2').load('index.php?jump=datosvideo',{ idvideo : video, reproductor: tiporeproductor});
}

function removeThickBoxEvents() {
        $('.thickbox').each(function(i) {
		$(this).unbind('click');
	});
}

function bindThickBoxEvents() {
	removeThickBoxEvents();
	tb_init('a.thickbox');
}


function call_ajax(url,tag)
{
	var_criterio = document.getElementById('criterio').value;

	if (var_criterio!=""){
		url += '&criterio='+var_criterio;
	}
/*
	$.ajax({
	    type:       "POST",
            url:        url,
	    cache:      false,
//	    data:       "f=foo&b=bar",
	    success:    function() {
//		$('#'+tag).html(html);
		//re-attach thickbox
		tb_init($('.thickbox a'));
		$('#'+tag).load(url,'');
	    }
	});
*/
//	$.post(url,
//	{ },
//	$('#'+tag).load(url,function (){tb_init($('.thickbox a'));});
	$('#'+tag).html('<p style="margin-top: 30px;margin-left:300px;"><img src="images/loading.gif" alt=""></p>');
	$('#'+tag).load(url,function (){bindThickBoxEvents();});
	//,tb_init(.a.thickbox));
//	);

	// Limpio la variable del buscador
	document.getElementById('criterio').value="";
}

function cambio_buscador(tipo)
{
	alert(tipo);
	alert(document.getElementById('boton_canal').style.display);
	
	if (tipo == 1) {
		document.getElementById('boton_canal').style.display = 'block';
		document.getElementById('boton_video').style.display= 'none';
	} else {
		document.getElementById('boton_video').style.display = 'block';
		document.getElementById('boton_canal').style.display = 'none';
	}

}

function stop_video(tipolistado,idcanal)
{	
	var player = document.getElementById('videoplayer');
	player.sendEvent("STOP","true");
	
	//url = "index.php?jump=stopvideo";
	//argumentos = { tipo : tipolistado, canal : idcanal };

	//$('#detallevideo').load(url, argumentos);
}

function abrir(direccion,ancho,alto){
     var opciones = "fullscreen=0"+
	 			 ",dependent=1"+
                 ",toolbar=0"+
                 ",location=0"+
                 ",status=0"+
                 ",menubar=0"+
                 ",scrollbars=0"+
                 ",resizable=0"+
                 ",width="+ancho+
                 ",height="+alto+
                 ",left=300"+
                 ",top=300";
     var ventana = window.open(direccion,"paleta",opciones,1);

}      

/* Funciones que generan los scroll en forma de carousel */
function limpiar(capa,url1,url2,arg)
{
	if (arg!=""){
		url2+='&'+arg+'='+document.getElementById(arg).value;
		// Reserteo el valor del campo
		document.getElementById(arg).value=''; 
	}
	
	$('#'+capa).html();
	
	$.ajax({
		type: "GET",
		dataType: "html",
		contentType: "application/x-www-form-urlencoded",
		url: url2,
			success: function(datos){
				$('#'+capa).html(datos);
			}
	});
	
	//$("#"+capa).load(url1, 
	//function(){
	//	inicia_scroll(url2,7,false);
	//});
}

function inicia_scroll(url,numscroll,tiposcroll)
{
	function itemLoadCallbackFunction(carousel, state) 
	{ 
		if (carousel.has(carousel.first, carousel.last)) {
			return;
		}
		jQuery.post(
			url,
			{
				first: carousel.first,
				last: carousel.last
			},
			function(videos) {
				mycarousel_itemAddCallback(carousel, carousel.first, carousel.last, videos);
			},
			'html'
		);
	};
	
	function mycarousel_itemAddCallback(carousel, first, last, videos)
	{
		num_item = 0;
		jQuery('li', videos).each(function(i) {		    
			carousel.add(first + i, this);			
			num_item ++;
		});
		carousel.size (parseInt(num_item));
		// Para que funcione el thickbox en los carrousel generados y tb fuera
		tb_init($('#mycarousel a'));		
	};
	
	jQuery(document).ready(function() {
		jQuery('#mycarousel').jcarousel({
			itemLoadCallback: itemLoadCallbackFunction,
			vertical : tiposcroll,
			scroll : numscroll
		});
	});
}

