// JavaScript Document
//Set thumbs
//function set_thumbs(obj, W, H) {
//    jQuery(obj + ' img').hide();
//    jQuery(window).bind("load", function(){
//        jQuery(obj + ' img').each(function() {
//            var w, h, t, l;
//            jQuery(this).show();
//            var cw = jQuery(this).width();
//            var ch = jQuery(this).height();
//            w = W;
//            h = ch*W/cw;
//            if (h>H) {
//                l = 0;
//                t = (ch*W/cw-H)/2;
//            } else {
//                h = H;
//                w = H*cw/ch;
//                l = (H*cw/ch-W)/2;
//                t = 0;
//            }
//            jQuery(this).attr('style', 'width: ' + w + 'px; height: ' + h + 'px; left: -' + l + "px; top: -" + t + "px;" );
//        });
//    });
//}
//
////Set thumbs
////v1.1 (文档完全载入后显示缩略图)
//function set_thumbs(obj, W, H) {
//    jQuery(obj + ' img').hide();
//    jQuery(window).bind("load", function(){
//        jQuery(obj + ' img').each(function() {
//            var w, h, t, l;
//            var cw = jQuery(this).width();
//            var ch = jQuery(this).height();
//            w = W;
//            h = ch*W/cw;
//            if (h>H) {
//                l = 0;
//                t = (ch*W/cw-H)/2;
//            } else {
//                h = H;
//                w = H*cw/ch;
//                l = (H*cw/ch-W)/2;
//                t = 0;
//            }
//            jQuery(this).attr('style', 'width: ' + w + 'px; height: ' + h + 'px; left: -' + l + "px; top: -" + t + "px;" ).hide().fadeIn('slow');
//        });
//    });
//}
//v2.0(判断图片载入后显示缩略图)
function set_thumbs(obj, W, H) {
    jQuery(obj + ' img').hide().each(function() {
        var w, h, t, l, cw, ch;
        function doResize(o) {
            cw = o.width();
            ch = o.height();
            w = W;
            h = ch*W/cw;
            if (h>H) {
                l = 0;
                t = (ch*W/cw-H)/2;
            } else {
                h = H;
                w = H*cw/ch;
                l = (H*cw/ch-W)/2;
                t = 0;
            }
            o.attr('style', 'width: ' + w + 'px; height: ' + h + 'px; left: -' + l + "px; top: -" + t + "px;").hide().fadeIn('slow');
        }
        if (jQuery(this).get(0).complete) doResize(jQuery(this));
        else jQuery(this).bind("load", function() { doResize(jQuery(this)); });
    });
}
