/* mnaauuu */

var $$ = $.fn;

$$.extend({
  SplitID : function()
  {
    return this.attr('id').split('-').pop();
  },

  Slideshow : {
    Ready : function(size)
    {
		pos = 0;
		for(var i=0;i<size;i++) {
			pos = i * 121;
			$('div#q' + i).css('background-position','0 -'+pos+'px');
			if ( i > 0 )
				$('div#q' + i).css('display','none');
		}
		$('#quotes #q-arrow-l').click(function() { $$.Slideshow.Button('left'); });
		$('#quotes #q-arrow-r').click(function() { $$.Slideshow.Button('right'); });
		$('#quotes #q-arrow-l, #quotes #q-arrow-r').hover(function(){$$.Slideshow.Interrupted=true;},function(){$$.Slideshow.Interrupted=false;});
		
		
		this.Counter = -1;
		this.Last = 0;
		this.Interrupted = false;
		this.InterruptedButton = false;

		this.MaxTimeout = 50;
		this.Timeout = this.MaxTimeout;
		this.Transition();
		this.Size = size;
		this.AnimationTime = 1100;
    },
	
	Button : function(dir) {
		if ( this.InterruptedButton )
			return;
			
		this.Interrupted = true;
		this.InterruptedButton = true;
		
		if ( dir == 'left' ) {
			this.Counter = parseInt(this.Last) + 1;
			if ( this.Counter >= this.Size ) this.Counter = 0;
		} else {
			this.Counter = parseInt(this.Last) - 1;
			if ( this.Counter < 0 ) this.Counter = this.Size-1;
		}
		this.from = this.Last;
		this.Last = this.to = this.Counter;
			
		
		var pozTo = pozFrom = "910px";
		if ( dir == 'right' )
			pozFrom = '-'+pozFrom;
		else
			pozTo = '-'+pozTo;
			
		$('div#q' + this.to).css("left", pozTo);
		$('div#q' + this.to).css("display", "block");
		$('div#q' + this.from).animate({left: pozFrom}, $$.Slideshow.AnimationTime, 'easeInOutExpo', function() { $(this).css("display", "none");} );
		$('div#q' + this.to).animate({left: "0"}, $$.Slideshow.AnimationTime, 'easeInOutExpo', function() {
						$$.Slideshow.Timeout = $$.Slideshow.MaxTimeout;
						$$.Slideshow.Interrupted = false;
						$$.Slideshow.InterruptedButton = false;
		});
	},
	
    Transition : function()
    {
		if (this.Interrupted || this.InterruptedButton) {
			setTimeout('$$.Slideshow.Transition();', 100);
			return;
		} else {
			this.Timeout--;
			if ( this.Timeout > 0 ) {
				setTimeout('$$.Slideshow.Transition();', 100);
				return;
			}
			this.Counter = parseInt(this.Last) + 1;
			if ( this.Counter >= this.Size ) this.Counter = 0;
		}

		this.Interrupted = this.InterruptedButton = true;
		
		this.from = this.Last;
		this.Last = this.to = this.Counter;

		var pozFrom = "-910px";
		var pozTo = "910px";
		
		
		$('div#q' + this.to).css("left", pozTo);
		$('div#q' + this.to).css("display", "block");
		$('div#q' + this.from).animate({left: pozFrom}, $$.Slideshow.AnimationTime,'easeInOutExpo', function() { $(this).css("display", "none");} );
		$('div#q' + this.to).animate({left: "0"}, $$.Slideshow.AnimationTime,'easeInOutExpo', function() {
						$$.Slideshow.Timeout = $$.Slideshow.MaxTimeout;
						$$.Slideshow.Interrupted = $$.Slideshow.InterruptedButton = false;
						setTimeout('$$.Slideshow.Transition();', 100);
		});
    }
	
  }
});

$(document).ready(
  function() {
    $$.Slideshow.Ready(12);
  }
);
