/* author: [EGOiST].[TeaM | TSRh].[ego1st.cjb.net] */
/* Creation date: 10.08.2008 */
var leftIndex = 0;
var rightIndex = 0;
var maxLength = 0;
var arr_img = new Array();
var arr_big = new Array();

$(document).ready(function(){
  maxLength = $("#lenta_images > #images > a > img").length;
  update_info();
  $("#leftbutton > a > img").animate({opacity: 0.7}, 1);
  $("#leftbutton").mouseover(left_over());
  $("#leftbutton").mouseout(left_out());
});

function left_over()
{
  $("#leftbutton > a > img").animate({opacity: 1}, 1);
}

function left_out()
{
  $("#leftbutton > a > img").animate({opacity: 0.6}, 1);
}

function right_over()
{
  $("#rightbutton > a > img").animate({opacity: 1}, 1);
}

function right_out()
{
  $("#rightbutton > a > img").animate({opacity: 0.6}, 1);
}

function right()
{
  if (leftIndex+maxLength-1==maxIndexArray) return;
  leftIndex++;
  var ind = leftIndex+maxLength-1;

  // Убрать первый элемент
  $("#lenta_images > #images > a:first").remove();
  // После последнего добавить новый и скрытый
  $("#lenta_images > #images > a:last").after("<a href=# onclick=\"show_image('"+arr_big[ind]+"'); return false\"><img src="+arr_img[ind]+" border=0></a>");
  $("#lenta_images > #images > a:last").animate({opacity: 0.1}, 1);
  $("#lenta_images > #images > a:last").show();
  $("#lenta_images > #images > a:last").animate({opacity: 1}, 1500);
  if (leftIndex==1) unblock_left();
  if (leftIndex+maxLength-1==maxIndexArray)
  {
    $("#rightbutton > a").mouseover();
    $("#rightbutton > a").css("cursor","default");
    $("#rightbutton > a > img").animate({opacity: 0.4}, 1);  
  }
  update_info();
}

function left()
{
  if (leftIndex==0) return;
  leftIndex--;
  $("#lenta_images > #images > a:last").remove();
  $("#lenta_images > #images > a:first").before("<a href=# onclick=\"show_image('"+arr_big[leftIndex]+"'); return false\"><img src="+arr_img[leftIndex]+" border=0></a>");
  $("#lenta_images > #images > a:first").animate({opacity: 0.1}, 1);
  $("#lenta_images > #images > a:first").show();
  $("#lenta_images > #images > a:first").animate({opacity: 1}, 1500);
  if (leftIndex==0) block_left();
  if (leftIndex+maxLength==maxIndexArray)
  {
    $("#rightbutton > a").css("cursor","pointer");
    $("#rightbutton > a > img").animate({opacity: 0.7}, 1);
    $("#rightbutton > a").mouseover(right_over());  
  }	
  update_info();
}

function update_info()
{
  var start = leftIndex+1;
  var end = leftIndex+maxLength;
  var all = maxIndexArray+1;
  $("#lenta_images > #info").html("Фото № "+start+"-"+end+"<br>(всего "+all+")");
}

function block_left()
{
  $("#leftbutton > a").mouseover();
  $("#leftbutton > a").css("cursor","default");
  $("#leftbutton > a > img").animate({opacity: 0.4}, 1);
}

function unblock_left()
{
  $("#leftbutton > a").css("cursor","pointer");
  $("#leftbutton > a > img").animate({opacity: 0.7}, 1);
  $("#leftbutton > a").mouseover(left_over());
}
