// JavaScript Document
jQuery.fn.LoadImage=function(scaling,width,height,loadpic){
if(loadpic==null)loadpic="/App_Images/loading.gif";
return this.each(function(){
var t=$(this);
var src=$(this).attr("src")
var img=new Image();
var load_img=(height-32)/2;
//alert("Loading")
img.src=src;
//自动缩放图片
var autoScaling=function(){
   if(scaling){
           if(img.width>0 && img.height>0){
              if(img.width/img.height>=width/height){
                      if(img.width>width){
                            t.width(width);
                            t.height((img.height*width)/img.width);
                            var m_top=(height-(img.height*width)/img.width)/2;
                            t.css({"margin-top":m_top})
                         }else{
                            t.width(img.width);
                            t.height(img.height);
                            var m_top=(height-img.height)/2;
                            t.css({"margin-top":m_top})
                         }
                }else{
                    if(img.height>height){
                           t.height(height);
                           t.width((img.width*height)/img.height);
                           var m_top=(height-height)/2;
                            t.css({"margin-top":m_top})
                     }else{
                           t.width(img.width);
                           t.height(img.height);
                           var m_top=(height-img.height)/2;
                           t.css({"margin-top": m_top})
              }
         }
      }
   }
}
//处理ff下会自动读取缓存图片
if(img.complete){
//alert("getToCache!");
autoScaling();
return;
}
$(this).attr("src","");
var loading=$("<img alt=\"loading...\" title=\"loading...\" style=\"margin-top:"+load_img+"px;\" src=\""+loadpic+"\" />");

t.hide();
t.after(loading);
$(img).load(function(){
autoScaling();
loading.remove();
t.attr("src",this.src);
t.show();
});

});
}

$(document).ready(function() {
   $("#bags-part1 div.img img").LoadImage(true,75,75);
   $("#bags-part2 div.img img").LoadImage(true,90,90);
   $("ul.pro-view li.img img").LoadImage(true,170,170);
   $("ul#bdbb li.img img").LoadImage(true,100,100);
   $("ul.pro li.img img").LoadImage(true,100,100);
   $("#history div.img img").LoadImage(true,120,120);
   $("#home-part2 div.img img").LoadImage(true,75,75);
   $("#home-part3 #brand li img").LoadImage(true,100,50);
   $("#material-part1 div.img img").LoadImage(true,75,75);
   $("dl.img-news dt img").LoadImage(true,60,60);
   $("#show-time dl.show-info dt img").LoadImage(true,98,98);
   $(".business-box div#info dt img").LoadImage(true,100,100);
   $("#brand-recommend div.img img").LoadImage(true,120,120);
   $("#home-part1 #products-category dl.more").hover(
            function(){
              $("#home-part1 #products-category dl").removeClass("current").children("dd.more-category").hide();
              $(this).addClass("current").children("dd.more-category").show();
            },  
            function(){
             $("#home-part1 #products-category dl").removeClass("current").children("dd.more-category").hide();
            }
   );
   $("#filter dd.btn img").toggle(
        function(){
          $(this).attr({src:"../../images/start-2.gif"}).parent().prev().css({ "height": "auto"}); 
        },
        function(){
          $(this).attr({src:"../../images/away-2.gif"}).parent().prev().css({ "height": "30px"});
        }
    )
});

