$(document).ready(function () {
 // Script to scroll the textfield
 // http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 // http://flesler.blogspot.com/2008/02/jqueryserialscroll.html
 var $panels = $('.persona_scroller .text_container > *');
 var $container = $('.persona_scroller .text_container');
 // if false, we'll float all the panels left and fix the width
 // of the container
 var horizontal = false;

 // float the panels left if we're going horizontal
 if (horizontal) {
 $panels.css({ 'float' : 'left','position' : 'relative' // IE fix to ensure overflow is hidden
 });
 }

 // calculate a new width for the container (so it holds all panels)
 //if (typeof ($panels[0]) != 'undefined')
 //$container.css('height', $panels[0].offsetHeight * $panels.length);
 //$container.css('height', "3000px");

 // collect the scroll object, at the same time apply the hidden overflow
 // to remove the default scrollbars that will appear
 var $scrollEl = $('.persona_scroller').css('overflow', 'hidden');

 // apply our left + right buttons
 $scrollEl
  .before('<img class="prev_txt" src="../img/up.png" />')
  .after('<img class="next_txt" src="../img/down.png" />');
  
   	$('img.prev_txt').mousedown(function()
	{
		$(this).attr('src', '../img/up_md.png');
		interval: 300;
	})
	.mouseup(function()
	{
		$(this).attr('src', '../img/up.png');
	});
	
	$('img.next_txt').mousedown(function()
	{
		$(this).attr('src', '../img/down_md.png');
		interval: 300;
	})
	.mouseup(function()
	{
		$(this).attr('src', '../img/down.png');
	});
 
 // offset is used to move to *exactly* the right place, since I'm using
 // padding on my example, I need to subtract the amount of padding to
 // the offset. Try removing this to get a good idea of the effect
 var offset = parseInt((horizontal ? $container.css('paddingTop') : $container.css('paddingLeft')) || 0) * -1;
 
 
 // go find the navigation link that has this target and select the nav
 function trigger(data) {
	//var el = $('#persona_scroller a').find('span[title$="' + data.id + '"]').parent().get(0); // li.selected 
 //fadeThemIn();
 }
 
 var scrollOptions = {
 target: $scrollEl, // the element that has the overflow
 items: $panels, // can be a selector which will be relative to the target
 //navigation: '#persona_text a',
 start: 0,
 step: 5,
 prev: 'img.prev_txt', // selectors are NOT relative to document, i.e. make sure they're unique
 next: 'img.next_txt',
 axis: 'xy', // allow the scroll effect to run both directions
 //onAfter: trigger, // our final callback
 //onBefore: fadeThemOut,
 offset: offset,
 duration: 900, // duration of the sliding effect
 easing: 'swing', // easing - can be used with the easing plugin: http://gsgd.co.uk/sandbox/jquery/easing/
 interval: 9999,
 //event: click,
 cycle: false,
  onBefore:function( e, elem, $scrollEl, $panels, pos )
  {
	$('.prev_txt').add('.next_txt').show();
	if( pos == 0 )
		$('.prev_txt').hide();
	else if( pos == $panels.length-1 )
		$next.hide();
  }
 };

 // apply serialScroll to the slider - we chose this plugin because it
 // supports// the indexed next and previous scroll along with hooking
 // in to our navigation.
 //$('#persona_scroller').serialScroll(scrollOptions);
 
 $('img.next_txt').click(function()
 {
 	$(this).parent().find('.persona_scroller').stop().scrollTo( '+=200', 0, { axis:'y', duration: 700 } );
 });

 
 $('img.prev_txt').click(function()
 {
 	$(this).parent().find('.persona_scroller').stop().scrollTo( '-=200', 0, { axis:'y', duration: 700 } );
 });

 // mousewheel for text scroller
$('.persona_scroller').mousewheel(function(event, delta) {
    //console.log(delta);
    if (delta > 0)
    {
    	//$.scrollTo(0,0);
    	$(this).stop().scrollTo( '-=120', 0, { axis:'y', duration: 300 } );
    }
    else
    {
    	//$.scrollTo(0,0);
    	$(this).stop().scrollTo( '+=120', 0, { axis:'y', duration: 300 } );
    }
    // need 'return false' not to scroll the whole window!
    return false;
});

});
