﻿	$(document).ready(function(){
		arr_objs(100,100);
	});

	function arr_objs(fixW,fixH){
		objs=$(".picture");
		for(lop=0;lop<objs.length;lop++){
			fix_mb_pic($(objs[lop]),fixW,fixH);
		}
	}
	
	function fix_mb_pic(obj,fixW,fixH){
		var image = new Image();
		obj_img = $(obj).children("a").children("img");
		image.src = $(obj_img).attr("src");
		width = image.width;
		height = image.height;
		if(width > fixW && height > fixH){
			fixRatioW = width / fixW;
			fixRatioH = height / fixH;
			fixRatio=fixRatioW > fixRatioH?fixRatioH:fixRatioW;
			width = Math.round(width / fixRatio);
			height = Math.round(height / fixRatio);
			
			$(obj_img).css("width",width);
			$(obj_img).css("height",height);
		}
		
		pic_W=parseInt($(obj).css("width"));
		pic_H=parseInt($(obj).css("height"));
		pic_SW=parseInt($(obj).attr("scrollWidth"));
		pic_SH=parseInt($(obj).attr("scrollHeight"));
		pic_SL=parseInt((pic_SW-pic_W)/2);
		pic_ST=parseInt((pic_SH-pic_H)/2);
		$(obj).attr("scrollLeft",pic_SL);
		$(obj).attr("scrollTop",pic_ST);
	}