/**
 * Created by IntelliJ IDEA.
 * User: Bugi
 * Date: 13 вер 2010
 * Time: 13:16:06
 * To change this template use File | Settings | File Templates.
 */
jQuery.fn.MainBlogSlider = function()
{
	return this.each(function()
	{
    var conteiner = this;
    var li_width = $('li:first', conteiner).innerWidth() + 20;
    if($.browser.webkit)
    {
      // В хроме не может вытянуть ширину дива :(
      li_width = 120;
    }
    var ul_width = $('li', conteiner).length * li_width;
    var max_left = ul_width - 4 * li_width; //4 слайда уже показываем
    $('ul', conteiner).css('width', ul_width);
    var isAnimate = false;
    var ul_left = parseInt($('ul',conteiner).css('left'));

    $('.slide-prev', conteiner).click(function()
    {
      ul_left = parseInt($('ul',conteiner).css('left'));
      if( !(ul_left >= 0) )
      {

        if(!isAnimate)
			  {
				  isAnimate = true;
				  $('ul', conteiner).animate({ left : ul_left + li_width   +'px' } , 500, '', function()
          {
				  	isAnimate = false;
				  });
        }
      }
    });

    $('.slide-next', conteiner).click(function()
    {
      ul_left = parseInt($('ul',conteiner).css('left'));
      if(!isAnimate)
      {

        if( -ul_left != max_left )
        {
          isAnimate = true;
				  $('ul', conteiner).animate({ left : ul_left - li_width   +'px' } , 500, '', function()
          {
				  	isAnimate = false;
				  });
        }
      }
    });


	});
}

