var i=0, x=0, y=0, t;

$(document).ready(function() {
  MM_preloadImages(
    'images/menu_lewe_up_09.gif',
    'images/menu_lewe_up_12.gif',
    'images/menu_lewe_up_13.gif',
    'images/menu_lewe_up_14.gif',
    'images/menu_lewe_up_15.gif',
    'images/menu_lewe_up_16.gif',
    'images/nowe_menu_up_21.gif',
    'images/nowe_menu_up_22.gif',
    'images/menu_g_up_03.gif',
    'images/menu_g_up_04.gif',
    'images/menu_g_up_05.gif',
    'images/menu_g_up_06.gif',
    'images/stopka_up_28.gif',
    'images/stopka_up_29.jpg',
    'images/stopka_up_30.jpg',
    'images/stopka_up_31.jpg',
    'images/stopka_up_32.jpg',
    'images/stopka_up_33.jpg',
    'images/stopka_up_34.gif',
    'images/stopka_up_35.gif',
    'images/stopka_up_36.jpg',
    'images/stopka_up_37.jpg',
    'images/stopka_up_38.jpg',
    'images/stopka_up_39.jpg',
    'images/stopka_up_40.jpg',
    'images/stopka_up_28.jpg',
    'images/stopka_up_29.jpg',
    'images/stopka_up_30.jpg',
    'images/stopka_up_31.jpg',
    'images/stopka_up_32.jpg',
    'images/stopka_up_33.jpg',
    'images/stopka_up_34.jpg',
    'images/stopka_up_35.jpg'
  );
});

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function start_gallery() {
  x=$('#scroll_box').width();
  $('.lightbox').lightBox();
/*  $('.lightbox').live('mousedown', function(event) {
    if(event.which==3) alert('Prawa autorkie zastrzeżone!');
  });
  $('#lightbox-container-image').live('mousedown', function(event) {
    if(event.which==3) alert('Prawa autorkie zastrzeżone!');
  }); */
  t=setTimeout('scrolling();', 10000);
  document.oncontextmenu=new Function("alert('Prawa autorskie zastrzeżone!');return false;");
}

function go_right() {
  clearTimeout(t);
  i=0
  y=$('#scroll_box').position().left;
  if(x+y>657) y=y-660;
  if(x+y<657) y=657-x;
  $('#scroll_box').animate({left: y}, 1000, 'swing');
  t=setTimeout('scrolling();', 5000);
}

function go_left() {
  clearTimeout(t);
  i=1;
  y=$('#scroll_box').position().left;
  if(y<0) y=y+660;
  if(y>0) y=0;
  $('#scroll_box').animate({left: y}, 1000, 'swing');
  t=setTimeout('scrolling();', 5000);
}

function scrolling() {
  y=$('#scroll_box').position().left;
  if(i==0) y=y-220; else y=y+220;
  if(x+y<657) {y=657-x+220; i=1}
  if(y>0) {y=-220; i=0}
  $('#scroll_box').animate({left: y}, 500, 'swing');
  t=setTimeout('scrolling();', 5000);
}
