﻿// JavaScript Document

$(document).ready(function(){
    $(".nav > ul > li > a").mouseover(function(){ 
	    var c = $(".sub",$(this).parent());
		$(".sub").hide();
		c.show();
	    c.hover(function(){c.show();}, function(){c.hide();});
		$(this).hover(function(){c.show();}, function(){c.hide();});
	})
	
	$(".hlink .btnshow").mouseover(function(){ 
	    var c = $(this).next();
		c.show();
	    c.hover(function(){c.show();}, function(){c.hide();});
		$(this).hover(function(){c.show();}, function(){c.hide();});
	})
});

(function($){ 
    
$.fn.LoadImage=function(options){
	return this.each(function(){
  
		var defaults = { 
			width: 150,
			height: 50,
			loading:"loading.gif"
		};
		var opts = $.extend(defaults, options);
		
		var t=$(this);
		var src=$(this).attr("src")
		var img=new Image();
		img.src=src;

		var autoScaling=function(){
			if(img.width>0 && img.height>0){ 
				if(img.width/img.height>=opts.width/opts.height){ 
					if(img.width>opts.width){ 
						t.width(opts.width); 
						t.height((img.height*opts.width)/img.width); 
					}else{ 
						t.width(img.width); 
						t.height(img.height); 
					} 
				} 
				else{ 
					if(img.height>opts.height){ 
						t.height(opts.height); 
						t.width((img.width*opts.height)/img.height); 
					}else{ 
						t.width(img.width); 
						t.height(img.height); 
					} 
				} 
			}
		}
		
		t.hide();
		
		if(img.complete){
			autoScaling();
			t.show();
		    return;
		}
		
		$(this).attr("src","");
		var loading=$("<img alt=\"加载中...\" title=\"图片加载中...\" src=\"images/"+opts.loading+"\" class=\"loadpic\" />");
		t.after(loading);
		loading.show();
		
		$(img).load(function(){
			autoScaling();
			loading.remove();
			t.attr("src",this.src);
			t.fadeIn();
		});
		
	});
}

})(jQuery);

