jQuery(function( $ ){
	
	/**
	 * No need to have only one element in view, you can use it for slideshows or similar.
	 * In this case, clicking the images, scrolls to them.
	 * No target in this case, so the selectors are absolute.
	 */
	
	$('#slideshow_more').serialScroll({
		items:'li',
		prev:'.thumbnail_prev',
		next:'.thumbnail_next',
		offset:0, //when scrolling to photo, stop 230 before reaching it (from the left)
		start:0, //as we are centering it, start at the 2nd
		duration:850,
		force:true,
		stop:true,
		lock:false,
		cycle:false, //don't pull back once you reach the end
		easing:'easeOutQuart', //use this easing equation for a funny effect
		step:1,
		jump: false,
		
		onBefore:function( e, elem, $pane, $items, pos ){
			/*
			var total = $items.length;
			var current = pos+1;
			
			// disable/enable next button
			if(current >= total){
				$(".thumbnail_next").css({ opacity: 0 });
			} else {
				$(".thumbnail_next").css({ opacity: 1 });
			}
			// disable/enable prev button
			if(current <= 1){
				$(".thumbnail_prev").css({ opacity: 0 });
			} else {
				$(".thumbnail_prev").css({ opacity: 1 });
			}
			*/
		}
		
	});
	
	$('#slideshow').serialScroll({
		items:'li',
		prev:'.prev_btn',
		next:'.next_btn',
		offset:0, //when scrolling to photo, stop 230 before reaching it (from the left)
		start:0, //as we are centering it, start at the 2nd
		duration:400,
		interval:6000,
		force:true,
		stop:true,
		lock:false,
		cycle:true, //don't pull back once you reach the end
		step:1,
		//easing:'easeOutQuart', //use this easing equation for a funny effect
		jump: true,
		
		onBefore:function( e, elem, $pane, $items, pos ){
			//$("#currentphoto").html(pos+1);
			var thisID = $(elem).attr('rev');
			updateFact(thisID);
		}
	});
	
	
	function updateFact(thisID){
		$.ajax({
		  type: "GET",
		  dataType : 'json',
		  url: "widgets/ajax_bannerInfo.php",
		  data: ({photoid:thisID}),
		  success: function(data){
			if(!data.error) {
				$('#slider_title').html(data.title);
				$('#slider_text').html(data.subtitle);
				$('#slider_text').attr('href', data.jumpto);
			} else {
			   alert('Sorry, something went wrong!');
			}
		
		  }
		});  // ajax block
	};
	
});
