	$(document).ready(function(){
	// HOME
	if( $(".home").length ){
		//CARRUSEL
		noticias_carrusel=$(".horse").length;
		noticia_actual=1;
		$("#carrusel").fadeIn(1000, function() {
			pausa3();
		});

		// VIDEOS del home
		videosdelhome();

		//SLIDE al final del sitio
		slideshow('slide_home');
	}


	//NOTA COMPLETA, POST
	if( $(".post").length ){
		//SLIDE de una nota
		slideshow('slide_nota');
	}

});






//SLIDE genérico
function slideshow(id){
	if( $("#"+id).length ){
		slide_actual = 1;
		slide_cantidad = $("#"+id+ " .slide").length;
		slide_ancho = $("#"+id+ " #slide1 img").width();

		tiempo_lectura = 6000;
		tiempo_transicion = 1000;

		//acomoda las imagenes en horizontal
		for (var i = 1; i <= slide_cantidad; i++) {
			$("#slide"+i).css("left",slide_ancho*(i-1))
		};

		slide_timer(id,tiempo_lectura,tiempo_transicion)
	}
}

function slide_timer(id,tiempo_lectura,tiempo_transicion){
	if( slide_timer[id] != ''){
		clearInterval(slide_timer[id]);
	}
	slide_timer[id] = setInterval("corre_slide("+tiempo_transicion+")",tiempo_lectura);
}

function corre_slide(tiempo_transicion){
	if(slide_actual < slide_cantidad){
		slide_actual++;
		slide_left = '-='+slide_ancho;
	} else {
		slide_actual=1;
		slide_left = '0';
	}
	$(".slideshow").animate({
		left: slide_left
	}, tiempo_transicion);
}

function slide_boton(boton,id){
	if(boton=="anterior"){
		if(slide_actual > 1){
			slide_actual--;
			slide_left = '+='+slide_ancho;
		} else {
			slide_actual = slide_cantidad;
			slide_left = '-='+(slide_ancho * (slide_cantidad-1));
		}
		
		slide_timer(id,tiempo_lectura+3000,tiempo_transicion)
		
		$(".slideshow").animate({
			left: slide_left
		}, tiempo_transicion);
	}

	if(boton=="siguiente"){
		corre_slide(tiempo_transicion);
		slide_timer(id,tiempo_lectura+3000,tiempo_transicion)
	}
}






//CARRUSEL
intervalo10 = '';
function pausa3(){
	if( intervalo10 != ''){
		clearInterval(intervalo10);
	}
	intervalo3 = setInterval("correnoticia()",10000);
}

function correnoticia(){
	if(noticia_actual < noticias_carrusel){
		noticia_actual++;		
		posicion = '-=620';
		posicion_flecha = '+=105';
	} else {
		noticia_actual=1;		
		posicion = '0';
		posicion_flecha = '35';
	}

	$("#carrusel").animate({
		left: posicion
	}, 1000);

	$("#carrusel_th > .current").removeClass("current");
	$("#horse"+noticia_actual+"_th").addClass("current");

	$("#flecha_carrusel").animate({
		left: posicion_flecha
	}, 1000);
}

function buscarnota(nota){
	noticia_actual=nota;
	clearInterval(intervalo3);
	if( intervalo10 != ''){
		clearInterval(intervalo10);
	}
	intervalo10 = setInterval("pausa3()",12000);

	$("#carrusel_th > .current").removeClass("current");
	$("#horse"+nota+"_th").addClass("current");

	posicion = -((nota-1) * 620);
	posicion_flecha = (nota-1) * 105 + 35;

	$("#carrusel").animate({
		left: posicion
	}, 1000);

	$("#flecha_carrusel").animate({
		left: posicion_flecha
	}, 1000);
}






//VIDEOS
function muestra_video(id,titulo){
	swfobject.removeSWF("myytplayer")
	$("#video_big").prepend("<div id='ytapiplayer'>You need Flash player 8+ and JavaScript enabled to view this video.</div>")

	var params = { allowScriptAccess: "always", allowFullScreen: "true" };
	var atts = { id: "myytplayer" };
	swfobject.embedSWF("http://www.youtube.com/v/"+id+"?enablejsapi=1&playerapiid=ytplayer&fs=1", 
	"ytapiplayer", "300", "224", "8", null, null, params, atts);

	$("#video_big p").html(titulo)
}

function feedLoaded(result) {
	if (!result.error) {
		// Grab the container we will put the results into
		// var container = document.getElementById("content");
		// container.innerHTML = '';

		// Loop through the feeds, putting the titles onto the page.
		// Check out the result object for a list of properties returned in each entry.
		// http://code.google.com/apis/ajaxfeeds/documentation/reference.html#JSON
		for (var i = 0; i < result.feed.entries.length; i++) {
			var entry = result.feed.entries[i];
			//var div = document.createElement("div");
			url_videos[i] = entry.link;
			title_videos[i] = entry.title;

			id_videos[i] = url_videos[i].substring(url_videos[i].lastIndexOf("?v=")+3,url_videos[i].lastIndexOf("&feature")); 

			if(i==0){
				muestra_video(id_videos[i],title_videos[i]);
			}
			if(i>=1){
				// alert(id_videos[i]);

				$("#video_th_"+i+" .video_th_img").attr("src","http://img.youtube.com/vi/"+id_videos[i]+"/default.jpg");
				$("#video_th_"+i+" p a").html(title_videos[i])
				
				patron="'";
				title_videos[i] = title_videos[i].replace(patron,"");
				$("#video_th_"+i+" a").attr("href","javascript:muestra_video('"+id_videos[i]+"','"+escape(title_videos[i])+"');")

			}
		}
	}
}

function OnLoad() {
	// Create a feed instance that will grab Digg's feed.
	var feed = new google.feeds.Feed("http://gdata.youtube.com/feeds/base/videos?max-results=19&alt=rss&orderby=published&author=MUPargentina1");
	feed.setNumEntries(19);

	// Calling load sends the request off.  It requires a callback function.
	feed.load(feedLoaded);
}







//PAGINADOR DE VIDEOS del home
function videosdelhome(){
	// $("#video_page_1 img").attr("src","images/video_current.png");
	// $("#video_page_1").addClass("current");
	current_page=1;

	$("#video_atras a").click(function() {
		actualizar_pagina_video(current_page-1)
		return false;
	});
	$("#video_siguiente a").click(function() {
		actualizar_pagina_video(current_page+1)
		return false;
	});
}

function actualizar_pagina_video(page){

	if(page==7) page=1;
	if(page==0) page=6;

	// $("#video_pagination .current img").attr("src","images/video_page.png");
	// $("#video_page_"+page).addClass("current");
	// $("#video_pagination #video_page_"+page+" img").attr("src","images/video_current.png");
	current_page = page;

	var altura_th = $("#video_th_1").outerHeight(true);
	
	var mover = (page-1) * -(79*3)

	$("#video_list").animate({
 		top: mover
 	}, 500);
}





//VIDEO en nota
function muestra_video_ennota(id){
	// alert('entro');
	swfobject.removeSWF("myytplayer");
	$("#video_nota").prepend("<div id='ytapiplayer'>You need Flash player 8+ and JavaScript enabled to view this video.</div>")

	var params = {
		allowScriptAccess: "always",
		wmode:'transparent',
		allowFullScreen: "true"
	};
	var atts = { id: "myytplayer" };
	swfobject.embedSWF("http://www.youtube.com/v/"+id+"?enablejsapi=1&playerapiid=ytplayer&fs=1", 
	"ytapiplayer", "620", "383", "8", null, null, params, atts);
}

//IMAGENES O VIDEO en noticia completa
function imagenesovideos(iov){
	if( iov == "imagenes"){
		$("#video_nota").hide()
		$("#slide_nota").fadeIn(500)
	}
	if( iov == "videos"){
		$("#slide_nota").fadeOut(500)
		$("#video_nota").show()
	}
}

