var timerID;
jQuery(function( $ ){			

	$.preload( '.rollover', {

	    find:'_off.png',

	    replace:'_on.png'

	});
	$('.rollover').hover(function(){
		this.src = this.src.replace('_off.png','_on.png');
	},function(){
		this.src = this.src.replace('_on.png','_off.png');
	});

});
$(document).ready(function(){
	panel_reproductor();
	timerID = setTimeout("fplay()",$("#velocidad").attr("value")*1000 );
});
function panel_reproductor()
{
	$("#pantalla_reproductor").click(function()
	{
		vvplay = $("#play").val();
		if(parseInt(vvplay)==0)
		{
			$("#play").attr("value","1");
			$("#play_pause").attr("src",$("#play_pause").attr("src").replace('_play_','_pause_'));
			timerID = setTimeout("fplay()",$("#velocidad").attr("value")*1000);
		}
		else
		{
			$("#play").attr("value","0");
			$("#play_pause").attr("src",$("#play_pause").attr("src").replace('_pause_','_play_'));
			clearTimeout(timerID);

		}
	});
	$("#play_pause").click(function()
	{
		vplay = $("#play").val();
		if(parseInt(vplay)==0)
		{
			$("#play").attr("value","1");
			this.src = this.src.replace('_play_','_pause_');
			timerID = setTimeout("fplay()",5000 );
		}
		else
		{
			$("#play").attr("value","0");
			this.src = this.src.replace('_pause_','_play_');
			clearTimeout(timerID);

		}
	});
	$("#siquiente").click(function(){
		pos=$("#pos_foto").val();
		maxfoto = $("#max_fotos").val();
		$("#imagen_"+pos).animate({opacity: 0},1);
		$("#imagen_"+pos).hide("fast");
		pos++;
		if(parseInt(pos)<=parseInt(maxfoto))
		{
			$("#imagen_"+pos).animate({opacity: 0},1);
			$("#imagen_"+pos).show("fast");
			$("#imagen_"+pos).animate({opacity: 1},1);
			$("#pos_foto").attr("value",pos);
		}
		else
		{
			$("#imagen_0").animate({opacity: 0},1);
			$("#imagen_0").show("fast");
			$("#imagen_0").animate({opacity: 1},1);
			$("#pos_foto").attr("value","0");
		}
	});
	$("#anterior").click(function(){
		pos=$("#pos_foto").val();
		$("#imagen_"+pos).animate({opacity: 0},1);
		$("#imagen_"+pos).hide("fast");
		pos--;
		if(parseInt(pos)>=0)
		{
			$("#imagen_"+pos).animate({opacity: 0},1);
			$("#imagen_"+pos).show("fast");
			$("#imagen_"+pos).animate({opacity: 1},1);
			$("#pos_foto").attr("value",pos);
		}
		else
		{
			
			$("#imagen_"+$("#max_fotos").val()).animate({opacity: 0},1);
			$("#imagen_"+$("#max_fotos").val()).show("fast");
			$("#imagen_"+$("#max_fotos").val()).animate({opacity: 1},1);
			$("#pos_foto").attr("value",$("#max_fotos").val());
		}
	});
	$("#menos_velo").click(function(){
		velo = $("#velocidad").attr("value");
		velo++;
		if(velo<11)
		{
		 	$("#velocidad").attr("value",velo);
		}
		else
		{
			alert("Velocidad minima alcamzada")
		}
		
	});
	
	$("#mas_velo").click(function(){
		velo = $("#velocidad").attr("value");
		velo--;
		if(velo>0)
		{
		 	$("#velocidad").attr("value",velo);
		}
		else
		{
			alert("Velocidad máxima alcanzada")
		}
	});
}

function fplay()
{
	pos=$("#pos_foto").val();
		maxfoto = $("#max_fotos").val();
		$("#imagen_"+pos).animate({opacity: 0},1);
		$("#imagen_"+pos).hide("fast");
		pos++;
		if(parseInt(pos)<=parseInt(maxfoto))
		{
			$("#imagen_"+pos).animate({opacity: 0},1);
			$("#imagen_"+pos).show("fast");
			$("#imagen_"+pos).animate({opacity: 1},1);
			$("#pos_foto").attr("value",pos);
		}
		else
		{
			$("#imagen_0").animate({opacity: 0},1);
			$("#imagen_0").show("fast");
			$("#imagen_0").animate({opacity: 1},1);
			$("#pos_foto").attr("value","0");
		}
	timerID = setTimeout("fplay()",$("#velocidad").attr("value")*1000 );//parseFloat(tiempo)*1000
}
