window.onload = set_position_photo;
//event.observe(window, 'onload', set_position_photo);

var image_num = 0;
function show_big_photo(num, url) {
   image_num = num; // для передачи в setImage
   
   var photo = $('photo'+num);
   var big_photo = $('big_photo_img');
   var relative = $('container');
   var small_photo_height = photo.offsetHeight;
   var small_photo_top = getPosY( photo, relative );
   
   big_photo.src = '/i/preloader.gif';//photo.src;
   big_photo.title = '';
   $('big_photo_title_text').innerHTML = '';
   var big_photo_height = 220;
      
   $('big_photo').style.top = (small_photo_top - (big_photo_height-small_photo_height)/2) + 'px';
   $('photo_light_top').style.height = ((big_photo_height - small_photo_height)/2) + 'px';
   $('photo_light_bottom').style.height = ((big_photo_height - small_photo_height)/2) + 'px';
   $('photo_light_middle').style.height = small_photo_height + 'px';
   
   $('big_photo').show();

   var oImg = new Image();
   oImg.onload = onLoadImage;
   oImg.src = url;
}
function onLoadImage(){
	//if(this.complete)
		setImage(this);
}
function setImage(image){
   var photo = $('photo'+image_num);
   var big_photo = $('big_photo_img');
   var relative = $('container');
   var small_photo_height = photo.offsetHeight;
   var small_photo_top = getPosY( photo, relative );
   
   big_photo.src = image.src;//photo.src;
   big_photo.title = photo.title;
   $('big_photo_title_text').innerHTML = photo.title;
   var big_photo_height = image.height;
      
   $('big_photo').style.top = (small_photo_top - (big_photo_height-small_photo_height)/2) + 'px';
   $('photo_light_top').style.height = ((big_photo_height - small_photo_height)/2) + 'px';
   $('photo_light_bottom').style.height = ((big_photo_height - small_photo_height)/2) + 'px';
   $('photo_light_middle').style.height = small_photo_height + 'px';
   
   $('big_photo').show();
}

function hide_big_photo(num) {
   $('big_photo').hide();
}

function set_position_photo() {
   var relative = $('container');
   var photo_cnt = $('photo_cnt').value;
   var prev_y = 300;
   for(var i=1; i<=photo_cnt; i++) {
      if(i>1){
         prev_y = getPosY($('photo'+(i-1)),relative) + $('photo'+(i-1)).offsetHeight;
      }
      if(i==1){
         $('rightimages').style.margin = getPosY($('pos'+i),relative)-prev_y+'px 0 0 0';
         prev_y = getPosY($('pos'+i),relative);
      }
      $('photo'+i).style.margin = getPosY($('pos'+i),relative)-prev_y+'px 0 0 0';
   }
}



