jQuery(function( $ ){

var del = 1000;
var step=parseInt($("#inner_div").css("height")); // #inner_div height is set in polls_general.css
var one_less=total_polls-1; // total_polls value is set in sidebar.php
var rnd_poll=Math.floor(total_polls*Math.random())+1; 
var counter=rnd_poll;
var distance=(counter-1)*step;

		$.easing.bounceout = function(x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
		};

        $.easing.inoutquad = function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	};

$(document).ready(function() {

        if(counter==1){$('#left_nav').show();}
        else {if(counter==total_polls){$('#right_nav').show();}
              else{$('#left_nav,#right_nav').show();}
              };
		$('#inner_div').stop().scrollTo( distance, 0 );
        $('#inner_div').css({'z-index' : 1});
});

	$('#right_nav').click(function(){
        $(this,'#left_nav').hide();
		$('#inner_div').stop().scrollTo( '-='+step, del, { easing:'bounceout' } );
        counter=counter-1;
        if(counter==one_less){setTimeout("$('#right_nav,#left_nav').show();",del)
        } 
        else {if(counter==1) {$('#left_nav,#right_nav').hide(); 
                                setTimeout("$('#left_nav').show();",del)
                              }
               else {setTimeout("$('#left_nav,#right_nav').show();",del)}
             };
        
	});
	$('#left_nav').click(function(){
        $(this,'#right_nav').hide();
		$('#inner_div').stop().scrollTo( '+='+step, del, { easing:'inoutquad' } );
        counter=counter+1;
        if(counter==total_polls){$('#right_nav').hide(); 
                                 setTimeout("$('#right_nav').show();",del)
                                 } 
        else {setTimeout("$('#left_nav,#right_nav').show();",del)
              };
	});

});