﻿/* 
**************图片预加载插件****************** 
///作者：没剑(2008-06-23) 
///http://regedit.cnblogs.com 

///说明：在图片加载前显示一个加载标志，当图片下载完毕后显示图片出来 
可对图片进行是否自动缩放功能 
此插件使用时可让页面先加载，而图片后加载的方式， 
解决了平时使用时要在图片显示出来后才能进行缩放时撑大布局的问题 
///参数设置： 
scaling 是否等比例自动缩放 
width 图片最大高 
height 图片最大宽 
loadpic 加载中的图片路径 
*/
jQuery.fn.loadimg = function (scaling, width, height, loadpic) {
    if (loadpic == null) loadpic = "";
    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);
                        } else {
                            t.width(img.width);
                            t.height(img.height);
                        }
                    }
                    else {
                        if (img.height > height) {
                            t.height(height);
                            t.width((img.width * height) / img.height);
                        } else {
                            t.width(img.width);
                            t.height(img.height);
                        }
                    }
                }
            }
        }
        //处理ff下会自动读取缓存图片 

        if (img.complete) {

            autoScaling();
            t.show();
            return;
        }
        $(this).attr("src", "");

        t.hide();
        if (loadpic != "") {
            var loading = $("<img alt=\"加载中\" title=\"图片加载中\" src=\"" + loadpic + "\" />");
            t.after(loading);
        }
        $(img).load(function () {
            autoScaling();
            if (loadpic != "") loading.remove();
            t.attr("src", this.src);
            t.show();
            //alert("finally!") 
        });

    });
}

$(function () {
    if ($(".page_newslist_pager").find("div[id$='plChangePage']").length > 0) {
        $(".page_newslist_pager").show();
    }

    $("#NewsContet img").each(function () {
        if (this.width > 650) {
            this.width = 650;
        }
    });
    $("#menunav").find("li").hover(function () {
        $(this).addClass("on");
    }, function () {
        $(this).removeClass("on");
    });

    if ($(".splitline").length > 0) {
        var l = $("#main_left").height();
        var m = $("#main_middle").height();
        var r = $("#main_right").height();
        var max = l > m ? l > r ? l : r : m;

        $(".splitline").height(max - 30);
        $(".splitline").css("margin-top", "35px");
    }

    if ($("#leftnav").length > 0) {
        $("#leftnav").height($("#main_content").height());
    }

    if ($(".newslist_picture_img").length > 0) {
        $(".newslist_picture_img").loadimg(true, $(".newslist_picture_img").attr("w"), $(".newslist_picture_img").attr("h"));
    }
});

function doZoom(size) {
    $("#NewsContet").css("font-size", size + "px");
}


//－－－－－－－－－－－翻页类－－－－－－－－－－－－－－//
//属性  1.currentPage - 当前页码
//      2.pageCount - 页面总数
//      3.pageSize - 每一页显示个数
//      4.recordCount - 记录总数
//－－－－－－－－－－－－－－－－－－－－－－－－－－－//
function ChangePage_Property(Id) {
    this.currentPage = 1;
    this.pageCount = 1;
    this.pageSize = 20;
    this.recordCount = 0;
    this.Id = Id;
    this.CheckPage = function (topage) {
        if (topage < 1 || topage > this.pageCount) {
            alert("指定页码不存在，页码范围是(1 - " + this.pageCount + ")");
            return false;
        }
        return true;
    }

    this.Start = function (o, index, go) {

        if (go.toLowerCase() == "false") {
            return false;
        }
        var tempPage = this.currentPage;
        switch (index) {
            case 0:
                tempPage = 1;
                break;
            case 1:
                tempPage = tempPage - 1;
                break;
            case 2:
                tempPage = tempPage + 1;
                break;
            case 3:
                tempPage = this.pageCount;
                break;
            case 4:
                try {
                    tempPage = $("#txtCurrentPage").val();
                }
                catch (e) {
                    tempPage = $("#" + this.Id + "_txtCurrentPage").val();
                }
        }

        if (this.CheckPage(tempPage)) {
            $("#" + this.Id + "_PageIndex").val(tempPage);
            if ($("input [id$='" + this.Id + "_changepage_btnGoto']").length>0) {
                $("input [id$='" + this.Id + "_changepage_btnGoto']").click();    //执行对应的linkbutton的点击事件
            }
            else {
                var url = $("#" + this.Id + "_PageUrl").val();
                var pagePos = url.indexOf("&page=")

                if (pagePos > 0) {
                    var pageC = url.indexOf("&", pagePos + 1)
                    if (pageC > 0) {
                        url = url.substring(0, pagePos) + "&page=" + tempPage + url.substr(pageC);
                    }
                    else {
                        url = url.substring(0, pagePos) + "&page=" + tempPage;
                    }
                }
                else {
                    pagePos = url.indexOf("?page=")
                    if (pagePos > 0) {
                        pageC = url.indexOf("&", pagePos + 1)
                        if (pageC > 0) {
                            url = url.substring(0, pagePos) + "?page=" + tempPage + url.substr(pageC);
                        }
                        else {
                            url = url.substring(0, pagePos) + "?page=" + tempPage;
                        }
                    }
                    else {
                        if (url.indexOf("?") > 0) {
                            url = url + "&page=" + tempPage;
                        }
                        else {
                            url = url + "?page=" + tempPage;
                        }
                    }
                }
                window.location = url;
            }
            return true;
        }
        else {
            $("#" + this.Id + "_txtCurrentPage").val(this.currentPage);
            return false;
        }
    }
}

