function gallery_abspos_small(obj,size_w,size_h) { $(document).ready(function() { gallery_a2bspos_small(obj,size_w,size_h);}); return true; }

function gallery_get_big(obj, url, id, w, h, size) { 	$('#gallery_big_photo_'+id+' img').animate({opacity: 0}, 100, function() { 	$('#gallery_big_photo_'+id).html("<img style='opacity:0;'  onClick='gallery_get_z_big(\""+id+"\", "+size+")';  onload='gallery_abspos_small(this,"+w+","+h+");'  src='/files/images/preview/200x200_"+url+"'/>");   /*$('#gallery_big_img_'+id+' div').css({'left':50,'top':50});*/	$('#gallery_big_img_'+id+' div img').attr('src',"/files/images/upload/"+url); 	$('#gallery_big_img_img_'+id).attr('src',"/files/images/preview/400x400_"+url); 	$('#gallery_big_photo_'+id+' img').animate({opacity: 1}, 100);}); 
	}

function gallery_get_z_big(id,size) {  $('#gallery_big_img_'+id+' div.over').css('display','block').find('div.loop').css('display:block');  var a_width=$('#gallery_big_img_img_'+id).width(); var css_w=$('#gallery_big_img_img_'+id).css("width");   $('#gallery_big_img_img_'+id).removeAttr("width").css({ width: ""});    var b_width  = $('#gallery_big_img_img_'+id).width(); $('#gallery_big_img_img_'+id).attr({width: a_width}); $('#gallery_big_img_img_'+id).css({width: css_w}); if($('#gallery_big_img_'+id+' div.over img').width()/b_width<1.1) { $('#gallery_big_img_'+id+' div.over').css('display','none'); } $('#gallery_big_img_'+id+' div.over').css({'left':'5px','top':'5px'}).find('img').css('margin','0');    $('#gallery_big_img_'+id).animate({    width: size,  opacity:1  }, 400, function() {    });  }    
function gallery_get_z_hide(id) {  $('#gallery_big_img_'+id+' div.over').css('display','none'); 	$('#gallery_big_img_'+id).animate({     width: 0, 	opacity:0 }, 400, function() {   }); }
	
$(document).ready(function() { $('div.over').hover(function() { $(this).find('div.loop').toggle(); }); $('.gallery_big_photo img').animate({opacity: 0}, 0);  $('.gallery_preview img').animate({opacity: 0}, 0); });

function gallery_a2bspos_small(obj,size_w,size_h) { 
var w=obj.offsetWidth;  
var h=obj.offsetHeight; 

 var h_n=h; 
 var w_n=w;  
 if (w > size_w)  {  h_n = h*(size_w/w);  w_n = size_w; } 
 if(h_n==null) { h_n=h;  } 
 if (h_n > size_h)   { w_n = w*(size_h/h);  h_n = size_h;  }  
 
 obj.style.height = h_n+'px'; 
 obj.style.width = w_n+'px'; 
 obj.style.top = (size_h-h_n)/2+'px'; 
 obj.style.visibility='visible';  
 $(obj).animate({opacity: 1}, 200); 
 }

function mv(ui) {
var left=107*(ui.position.left)/($('.ui-draggable-dragging img').parent().parent().children('img').width()-107)-7;
var k =(($('.ui-draggable-dragging img').width())/($('.ui-draggable-dragging img').parent().parent().children('img').width()));
var w=((ui.position.left)*k);

var top=107*(ui.position.top)/($('.ui-draggable-dragging img').parent().parent().children('img').height()-107)-3;
var k2 =(($('.ui-draggable-dragging img').height())/($('.ui-draggable-dragging img').parent().parent().children('img').height()));
var h=((ui.position.top)*k2);


//$('#debug2').html($('.ui-draggable-dragging img').parent().parent().children('img').width()+'::'+$('.ui-draggable-dragging img').width()+'::'+(ui.position.left)+'::'+(left)); 
   $('.ui-draggable-dragging img').css({"margin-top":0-(h-top+top*k2),"margin-left":0-(w-left+left*k) });
}

$(document).ready(function() {
 var a = $('.over').length;
 if(a>0) { $('.over').draggable({containment:'parent', drag:function(event, ui) { mv(ui); }}); }
 });

 
 $(document).ready(function(){ $('.gallery_big_img').animate({     opacity: 0   }, 0, function() {  	$('.gallery_big_img').css({display: "block", width:1});   }); });	