
/*
* Image preload and auto zoom
* scaling     是否等比例自动缩放
* width       图片最大高
* height      图片最大宽
* loadpic     加载中的图片路径
* example $("*").LoadImage(true,w,h);
*/
jQuery.fn.LoadImage = function (scaling, width, height, loadpic) {
    if (loadpic == null) loadpic = "/images/gray.gif";
    return this.each(function () {
        var t = $(this);
        var src = $(this).attr("src");
        var img = new Image();
        //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);
                            t.css("margin-top", (height - t.height()) / 2);
                        } else {
                            t.width(img.width);
                            t.height(img.height);
                            t.css("margin-top", (height - t.height()) / 2);
                        }
                    }
                    else {
                        if (img.height > height) {
                            t.height(height);
                            t.width((img.width * height) / img.height);
                            t.css("margin-top", (height - t.height()) / 2);
                        } else {
                            t.width(img.width);
                            t.height(img.height);
                            t.css("margin-top", (height - t.height()) / 2);
                        }
                    }
                }

            }
        };
        //处理ff下会自动读取缓存图片
        if (img.complete) {
            //alert("getToCache!");
            autoScaling();
            return;
        }
        $(this).attr("src", "");
        var loading = $("<img alt=\"加载中...\" title=\"图片加载中...\" src=\"" + loadpic + "\" />");

        t.hide();
        t.after(loading);
        $(img).load(function () {
            autoScaling();
            loading.remove();
            t.attr("src", this.src);
            t.show();
            //alert("finally!")
        });

    });
};

/*======================= 首頁-輪換廣告680 x 200 =======================*/
$.fn.flashAlbum=function(){
	var wrap=$(this);
	var slider=$(".is-main ul",wrap);
	//var btnPanel=$(".ui-btn li",wrap);
	//alert(btnPanel.html());
	var btns=$('.is-btn li',wrap);//所愿的按钮li标签
	var picList=$('img',slider);//所有的图象标签
	var len=picList.length;//li的个数
	var i=0;//记录当前播放的是第几张图片
	var timer;
	//默认给第一个按钮添加样式
	btns.eq(i).addClass('current');
	//开启定时器
	startScroll();
	//给容器pic-show添加鼠标移上去就停止滚动，移开就开始滚动的功能
    wrap.hover(stopScroll,startScroll);
	//给按钮添加鼠标移上去就转换图片的效果
	btns.mouseover(function(){
		var index=btns.index(this);
		scroll(index);
	});
	//开始定时器
	function startScroll(){
		timer=setInterval(
				function(){i++;i=i%len;scroll(i)}//开始滚动后，就显示下一张图片，要是i超级范围就变加0
				,3000
			);
	}
	//关闭定时器
	function stopScroll(){
		clearInterval(timer);
	}
	//定时器处理函数，决定滚动哪一个
	function scroll(to){
		slider.stop().animate({"top":-240*to},300);
		btns.eq(to).addClass('current').siblings().removeClass('current');//对应的按钮添加变色，其它的默认为白色
		i=to;
	}
}
$(function(){
	$(".index-scroll").flashAlbum();//调用函数
});

function autoZoomLoadImage(ImgD, iwidth, iheight) {

    //参数(图片,允许的宽度,允许的高度) 
    var image = new Image();
    image.src = ImgD.src;
    if (image.width > 0 && image.height > 0) {
        flag = true;
        if (image.width / image.height >= iwidth / iheight) {
            if (image.width > iwidth) {
                ImgD.width = iwidth;
                ImgD.height = (image.height * iwidth) / image.width;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
            //ImgD.alt=image.width+"×"+image.height; 
        }
        else {
            if (image.height > iheight) {
                ImgD.height = iheight;
                ImgD.width = (image.width * iheight) / image.height;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
            //ImgD.alt=image.width+"×"+image.height;
        }
    }
}
/**LazImg*/



