jQuery(function( $ ){

$('#scrolliar').serialScroll({
		target:'#tira',
		items:'li', // Selector to the items ( relative to the matched elements, '#sections' in this case )
		prev:'#prev',// Selector to the 'prev' button (absolute!, meaning it's relative to the document)
		next:'#next',// Selector to the 'next' button (absolute too)
		axis:'xy',// The default is 'y' scroll on both ways
		//navigation:'#navigation li a',
		duration:700,// Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
		force:true, // Force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)
		step: 3,
		//start: 0, // On which element (index) to begin ( 0 is the default, redundant in this case )		
		//step:1, // How many items to scroll each time ( 1 is the default, no need to specify )
		lazy:false,// (default) if true, the plugin looks for the items on each event(allows AJAX or JS content, or reordering)
		//interval:1000, // It's the number of milliseconds to automatically go to the next
		//constant:true, // constant speed
		
		onBefore:function( e, elem, $pane, $items, pos ){
			/**
			 * 'this' is the triggered element 
			 * e is the event object
			 * elem is the element we'll be scrolling to
			 * $pane is the element being scrolled
			 * $items is the items collection at this moment
			 * pos is the position of elem in the collection
			 * if it returns false, the event will be ignored
			 */
			 //those arguments with a $ are jqueryfied, elem isn't.
			e.preventDefault();
			if( this.blur )
				this.blur();
		},
		onAfter:function( elem ){
			
		}
	});

						   });

function cargarImagen(imagen) {
	if (imagen.complete)
		if ($('#foto_grande img:first').is(':visible')) {//si el primer img esta visible aparece el segundo img
			if ($('#ajax_load').is(':visible')) {
				$('#ajax_load').css('display','none');				
			}
			$('#foto_grande img:last').attr('src',imagen.src);//inserta la img en el esta escondido
			$('#foto_grande img:first').fadeOut('fast',function(){$('#foto_grande img:first').attr('src','')});//desaparece
			$('#foto_grande a:last').attr('href','upload/'+imagen.src.split("=")[3]);
			$('#foto_grande a:last').attr('title',imagen.alt);
			$('#foto_grande img:last').fadeIn('fast',function(){$('#foto_grande a:last').lightBox();});//aparece el q estaba escondido
			$('#cont_der .pie h3:first').text(imagen.alt);
			$('#cont_der .pie div:first').text(imagen.title);
		}
		else {//si el primer img esta escondido aparece
			if ($('#ajax_load').is(':visible')) {
				$('#ajax_load').css('display','none');				
			}
			$('#foto_grande img:first').attr('src',imagen.src);
			$('#foto_grande img:last').fadeOut('fast',function(){$('#foto_grande img:last').attr('src','')});
			$('#foto_grande a:first').attr('href','upload/'+imagen.src.split("=")[3]);
			$('#foto_grande a:first').attr('title',imagen.alt);
			$('#foto_grande img:first').fadeIn('fast',function(){$('#foto_grande a:first').lightBox()});
			$('#cont_der .pie h3:first').text(imagen.alt);
			$('#cont_der .pie div:first').text(imagen.title);
		}
	else {
		if (!$('#ajax_load').is(':visible')) {
			$('#ajax_load').css('display','block')	;
		}
		setTimeout(function(){cargarImagen(imagen)},200);
	}
		
}

$(document).ready(function(){
	$("#foto_grande .foto a:last").lightBox();
	$('#tira li img').bind('click',function(){
		var imagen = new Image();
		imagen.src='upload/redimensionar.php?w=300&h=200&imagen='+$(this).attr('src').split('=')[2];
		imagen.alt=$(this).attr('alt');
		imagen.title=$(this).attr('title');
		cargarImagen(imagen);
	});
});


