pic_timer = false;
scroll_speed = 5;
gal_list = [];

function gal_init() {
  $('.gal_main .gal_up').hover(
    scroll_up, scroll_stop
    
  );
  
  
  $('.gal_main .gal_down').hover(
    scroll_down, scroll_stop
    
  );
  
  $('.gal_main div.gal_thumb_div img').each(function(i, d) {
    gal_list.push({
      id: i,
      src: d.src.replace(/_thumb\.jpg$/, '_full.jpg'),
      alt: d.alt
    });
    $(d).bind('click', function(e) {
      gal_load(i);
    });
  });

  gal_load(0);
  
}

function gal_load(i) {
  $('.gal_main img.gal_full').attr('src', gal_list[i].src).attr('alt', gal_list[i].alt);
  $('.gal_main div.gal_title').html(gal_list[i].alt);
  
}

function scroll_up(e) {
  if (!pic_timer) pic_timer=setInterval("scroll_y(2)", scroll_speed);
  
}

function scroll_down(e) {
  if (!pic_timer) pic_timer=setInterval("scroll_y(-2)", scroll_speed);
  
}

function scroll_y(d) {
  var e = $('.gal_main div.gal_thumb_div');
  ujtop = (parseInt(e.css('top')) + d);
  
  var min_top = -e.height() + e.parent().height();
  
  if (d < 0 && ujtop < min_top) {
    ujtop = min_top;
    scroll_stop();
  }
  
  if (ujtop > 0) {
    ujtop = 0;
    scroll_stop();
  }
  
  e.css('top', ujtop +'px');
}


function scroll_stop(e) {
  clearInterval(pic_timer);
  pic_timer = false;
}
