
//tab选项卡
/*第一种形式 第二种形式 更换显示样式*/
function setTab(m, n) {
    var tli = document.getElementById("menu" + m).getElementsByTagName("li");
    var mli = document.getElementById("main" + m).getElementsByTagName("ul");
    for (i = 0; i < tli.length; i++) {
        tli[i].className = i == n ? "hover" : "";
        mli[i].style.display = i == n ? "block" : "none";
    }
}

function menuFix() {
    var sfEls = document.getElementById("nav").getElementsByTagName("li");
    for (var i = 0; i < sfEls.length; i++) {
        sfEls[i].onmouseover = function() {
            this.className += (this.className.length > 0 ? " " : "") + "sfhover";
        }
        sfEls[i].onMouseDown = function() {
            this.className += (this.className.length > 0 ? " " : "") + "sfhover";
        }
        sfEls[i].onMouseUp = function() {
            this.className += (this.className.length > 0 ? " " : "") + "sfhover";
        }
        sfEls[i].onmouseout = function() {
            this.className = this.className.replace(new RegExp("( ?|^)sfhover\\b"),

"");
        }
    }
}
window.onload = menuFix;


//典藏幻灯片
//滚动图片
var dir = 1; //每步移动像素，大＝快
var speed = 10; //循环周期（毫秒）大＝慢
var MyMar = null;
function Marquee() {//正常移动
    var demo = document.getElementById("demo");
    var demo2 = document.getElementById("demo2");
    if (dir > 0 && (demo2.offsetWidth - demo.scrollLeft) <= 0) {
        demo.scrollLeft = 0;
    }
    if (dir < 0 && (demo.scrollLeft <= 0)) {
        demo.scrollLeft = demo2.offsetWidth;
    }
    demo.scrollLeft += dir;
}
function onmouseoverMy() {
    window.clearInterval(MyMar);
} //暂停移动
function onmouseoutMy() {
    MyMar = setInterval(Marquee, speed);
} //继续移动
function r_left() {
    if (dir == -1)
        dir = 1;
} //换向左移
function r_right() {
    if (dir == 1)
        dir = -1;
} //换向右移

function IsIE() {
    var browser = navigator.appName
    if ((browser == "Netscape")) {
        return false;
    }
    else if (browser == "Microsoft Internet Explorer") {
        return true;
    }
    else {
        return null;
    }
}

var _IsIE = IsIE();
var _MousePX = 0;
var _MousePY = 0;
var _DivLeft = 0;
var _DivRight = 0;
var _AllDivWidth = 0;
var _AllDivHeight = 0;
function MoveDiv(e) {
    var obj = document.getElementById("demo");
    _MousePX = _IsIE ? (document.body.scrollLeft + event.clientX) : e.pageX;
    _MousePY = _IsIE ? (document.body.scrollTop + event.clientY) : e.pageY;
    //Opera Browser Can Support ''window.event'' and ''e.pageX''
    var obj1 = null;
    if (obj.getBoundingClientRect) {
        //IE
        obj1 = document.getElementById("demo").getBoundingClientRect();
        _DivLeft = obj1.left;
        _DivRight = obj1.right;
        _AllDivWidth = _DivRight - _DivLeft;
    }
    else if (document.getBoxObjectFor) {
        //FireFox
        obj1 = document.getBoxObjectFor(obj);
        var borderwidth = (obj.style.borderLeftWidth != null && obj.style.borderLeftWidth != "") ? parseInt(obj.style.borderLeftWidth) : 0;
        _DivLeft = parseInt(obj1.x) - parseInt(borderwidth);
        _AllDivWidth = Cut_Px(obj.style.width);
        _DivRight = _DivLeft + _AllDivWidth;
    }
    else {
        //Other Browser(Opera)
        _DivLeft = obj.offsetLeft;
        _AllDivWidth = Cut_Px(obj.style.width);
        var parent = obj.offsetParent;
        if (parent != obj) {
            while (parent) {
                _DivLeft += parent.offsetLeft;
                parent = parent.offsetParent;
            }
        }
        _DivRight = _DivLeft + _AllDivWidth;
    }

    var pos1, pos2;
    pos1 = parseInt(_AllDivWidth * 0.4) + _DivLeft;
    pos2 = parseInt(_AllDivWidth * 0.6) + _DivLeft;

    if (_MousePX > _DivLeft && _MousePX < _DivRight) {
        if (_MousePX > _DivLeft && _MousePX < pos1)//Move left
        {
            r_left();
        }
        else if (_MousePX < _DivRight && _MousePX > pos2)//Move right
        {
            r_right();
        }

        if (_MousePX > pos1 && _MousePX < pos2)//Stop
        {
            onmouseoverMy();
            MyMar = null;
        } else if (_MousePX < pos1 || _MousePX > pos2) {
            if (MyMar == null) {
                MyMar = setInterval(Marquee, speed);
            }
        }
    }
}

function Cut_Px(cswidth) {
    cswidth = cswidth.toLowerCase();
    if (cswidth.indexOf("px") != -1) {
        cswidth.replace("px", "");
        cswidth = parseInt(cswidth);
    }
    return cswidth;
}

function MoveOutDiv() {
    if (MyMar == null) {
        MyMar = setInterval(Marquee, speed);
    }
}




//图片等比例缩放
function DrawImage(ImgD, FitWidth, FitHeight) {
    var image = new Image();
    image.src = ImgD.src;
    if (image.width > 0 && image.height > 0) {
        if (image.width / image.height >= FitWidth / FitHeight) {
            if (image.width > FitWidth) {
                ImgD.width = FitWidth;
                ImgD.height = (image.height * FitWidth) / image.width;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        } else {
            if (image.height > FitHeight) {
                ImgD.height = FitHeight;
                ImgD.width = (image.width * FitHeight) / image.height;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
    }
}


//图片展示
function div(id) { return document.getElementById(id); }
var ie = ! -[1, ];
var Obj = {
    Create: function(id, id2, ele) {
        var obj = document.createElement(ele);
        obj.setAttribute("id", id2);
        div(id).appendChild(obj);
    },
    del: function(id) {
        var obj = div(id);
        obj.parentNode.removeChild(obj);
    },
    inner: function(id, text) {
        div(id).innerHTML = text;
    },
    css: function() {
        this.cssinfo();
        var obj = div(this.css.id);
        with (obj.style) {
            ie ? (this.css.float != undefined ? styleFloat = this.css.float : "") : (this.css.float != undefined ? cssFloat = this.css.float : "");
            this.css.background != undefined ? background = this.css.background : "";
            this.css.width != undefined ? width = this.css.width : "";
            this.css.height != undefined ? height = this.css.height : "";
            this.css.position != undefined ? position = this.css.position : "";
            this.css.left != undefined ? left = this.css.left : "";
            this.css.top != undefined ? top = this.css.top : "";
            this.css.bottom != undefined ? bottom = this.css.bottom : "";
            this.css.padding != undefined ? padding = this.css.padding : "";
            this.css.margin != undefined ? margin = this.css.margin : "";
            this.css.filter != undefined ? filter = this.css.filter : "";
            this.css.opacity != undefined ? opacity = this.css.opacity : "";
            this.css.zIndex != undefined ? zIndex = this.css.zIndex : "";
            this.css.border != undefined ? border = this.css.border : "";
            this.css.overflow != undefined ? overflow = this.css.overflow : "";
            this.css.display != undefined ? display = this.css.display : "";
            this.css.textAlign != undefined ? textAlign = this.css.textAlign : "";
            this.css.fontSize != undefined ? fontSize = this.css.fontSize : "";
            this.css.color != undefined ? color = this.css.color : "";
            this.css.verticalAlign != undefined ? verticalAlign = this.css.verticalAlign : "";
            this.css.cursor != undefined ? cursor = this.css.cursor : "";
            this.css.lineHeight != undefined ? lineHeight = this.css.lineHeight : "";
        }
    },
    oEventX: function(e) {
        var e = window.event ? window.event : e;
        return e.clientX;
    },
    oEventY: function(e) {
        var e = window.event ? window.event : e;
        return e.clientY;
    }
}
var Create = Obj.Create, inner = Obj.inner, del = Obj.del, oX = Obj.oEventX, oY = Obj.oEventY;
Obj.css.prototype.cssinfo = function() {
    this.css = css;
    return this;
}

////////////////////////////////////////////////////////////
function iShow(objid) {
    this.iControl = "1"        /*1为图片大小自适应*/
    this.iControlSize = 0.6    /*最大图片大小占可视区域比例(此项需要this.iControl=1)*/
    this.ibody = "ibody";      /*bodyid*/
    this.bgid = "container"    /*背景id*/
    this.borderid = "wrap";    /*边框id*/
    this.boxid = "imgwrap";    /*图像容器id*/
    this.listid = objid;       /*图像列表id*/
    this.borderSize = 15;      /*边框大小*/
    this.titleSize = 15;       /*标题区域大小*/
    this.alpha = 7;            /*透明度---1~10*/
    this.bgc = "000"           /*背景色*/
    /*默认弹出框样式*/
    this.w = 420;
    this.h = 226;
    this.c = "#fff";
    this.w1 = this.w + this.borderSize * 2;
    this.h1 = this.h + this.borderSize * 2 + this.titleSize;
    this.c1 = "#eee";
}
iShow.prototype.iMouse = function() {
    /*鼠标事件*/
    var iDel = this.iDel;
    var iLoad = this.iLoad, iStyle = this.iStyle;
    var ele = { box: this.boxid, bd: this.borderid, bdSize: this.borderSize * 2, tSize: this.titleSize, iCount: this.iCount, iControl: this.iControl, iControlSize: this.iControlSize }
    var eles = div(this.listid).getElementsByTagName("a");
    for (var i = 0; i < eles.length; i++) {
        eles[i].onclick = function() {
            iStyle(iDel);
            iLoad(this, ele);
            return false;
        }
    }
}
iShow.prototype.iStyle = function(iDel) {
    /*对象初始化*/
    this.iShow.call(this)
    Create(this.ibody, this.bgid, "div");
    Create(this.ibody, this.borderid, "div");
    Create(this.ibody, this.boxid, "div");
    css = { id: this.bgid, width: "1500", height: "1325", opacity: 0.1 * this.alpha, background: "#" + this.bgc, filter: "alpha(opacity=" + 10 * this.alpha + ")", position: "absolute", top: 0, left: 0 }
    new Obj.css;
    css = { id: this.borderid, background: this.c1, width: this.w1 + "px", height: this.h1 + "px", position: "absolute", margin: -this.h1 / 2 + "px " + "0 0 " + -this.w1 / 2 + "px", left: "50%", top: "50%", opacity: 0.2, overflow: "hidden", filter: "alpha(opacity=20)" }
    new Obj.css;
    css = { id: this.boxid, textAlign: "center", background: this.c, width: this.w + "px", height: this.h + "px", position: "absolute", margin: -(this.h + this.titleSize) / 2 + "px " + "0 0 " + -this.w / 2 + "px", left: "50%", top: "50%" }
    new Obj.css;
    inner(this.boxid, "<span style='display:block;margin-top:50px;color:#f30'>图片读取可能比较慢，请稍后......</span><br/><span style='display:block;margin-top:50px;color:#f30;font-size:12px'>(若长时间未加载，请刷新页面)</span>")
    document.onkeydown = function(e) {
        var e = e ? e : window.event;
        if (e.keyCode == "27") {
            iDel();
        }
    }
    /*移动*/
    var obj1 = div(this.borderid);
    var obj2 = div(this.boxid);
    var Site = imgshow.Site;
    var Move = imgshow.Move;
    obj1.onmousedown = function() { Site(arguments[0], obj1, obj2); this.style.cursor = "move"; document.onmousemove = function() { Move(arguments[0], obj1, obj2) }; }
    document.onmouseup = function() { this.onmousemove = ""; obj1.style.cursor = "" }
}
iShow.prototype.iLoad = function(e, ele) {
    var image = new Image();
    image.src = e.href;
    if (image.complete) { Reset(); } else {
        image.onload = function() { Reset(); }
    }
    function Reset() {
        var iw0 = image.width, ih0 = image.height;
        var W0 = iw0 + ele.bdSize, H0 = ih0 + ele.bdSize + ele.tSize;
        function curSize() {
            css = { id: borderid, width: W0 + "px", height: H0 + "px", left: "50%", top: "30px", margin: "0 0 0 " + -W0 / 2 + "px" };
            new Obj.css;
            css = { id: boxid, width: iw0 + "px", height: ih0 + "px", left: "50%", top: "30px", margin: ele.tSize / 2 + "px 0 0 " + -(W0 - ele.bdSize) / 2 + "px" };
            new Obj.css;
        }
        var Size = (image.width > document.body.clientWidth * ele.iControlSize || image.height > document.body.clientHeight * ele.iControlSize) ? true : false
        if (ele.iControl == "1" && Size == true) {
            var iInfo = ele.iCount(image, ele.iControlSize);
            image.width = iInfo.iW, image.height = iInfo.iH;
        }
        var bt1 = "<a href='#' style='color:#fff;left:20px;text-decoration:none;font-size:13px' onclick='imgshow.iDel()'>关闭</a>";
        var bt2 = "<a href='#' style='color:#fff;margin-left:20px;text-decoration:none;font-size:13px' id='iZoom_cur'>原图大小</a>"
        var bt = "<span style='float:right;width:100px;text-align:left;'>" + bt1 + bt2 + "</span>";
        var text1 = "<img src='" + image.src + "' style='width:100%' alt='" + e.title + "' />";
        var text2 = "<span id='imgshow_title' style='font-size:13px'>" + bt + e.title + "</span>"
        var text = text1 + text2;
        var W = image.width + ele.bdSize, H = image.height + ele.bdSize + ele.tSize;
        css = { id: borderid, width: W + "px", height: H + "px", left: "50%", top: "50%", margin: -H / 2 + "px" + " 0 0 " + -W / 2 + "px" };
        new Obj.css;
        css = { id: boxid, width: image.width + "px", height: image.height + "px", left: "50%", top: "50%", margin: -(image.height + ele.tSize) / 2 + "px" + " 0 0 " + -image.width / 2 + "px" };
        new Obj.css;
        inner(ele.box, text);
        css = { id: "imgshow_title", width: "100%", height: "22px", position: "absolute", bottom: "-26px", left: 0, lineHeight: "22px", overflow: "hidden", color: "#fff"}
        new Obj.css;
        div("iZoom_cur").onclick = curSize;
    }
}
iShow.prototype.iCount = function(e, f) {
    var doc = document.body, W = doc.clientWidth * f, H = doc.clientHeight * f;
    var obj = e.width / W > e.height / H ? { iW: W, iH: e.height * W / e.width, iType: 1} : { iW: e.width * H / e.height, iH: H, iTyle: 2 };
    return obj;
}
iShow.prototype.Site = function(e, obj1, obj2) {
    this.X = oX(arguments[0]);
    this.Y = oY(arguments[0]);
    this.oLeft1 = obj1.offsetLeft;
    this.oTop1 = obj1.offsetTop;
    this.oLeft2 = obj2.offsetLeft;
    this.oTop2 = obj2.offsetTop;
}
iShow.prototype.Move = function(e, obj1, obj2) {
    var X = oX(arguments[0]) - this.X, Y = oY(arguments[0]) - this.Y;
    var Left1 = this.oLeft1 + X, Top1 = this.oTop1 + Y, Left2 = this.oLeft2 + X, Top2 = this.oTop2 + Y;
    css = { id: obj1.id, left: Left1 + "px", top: Top1 + "px", margin: 0 }
    new Obj.css;
    css = { id: obj2.id, left: Left2 + "px", top: Top2 + "px", margin: 0 }
    new Obj.css;
}
iShow.prototype.iDel = function() {
    del(boxid); del(borderid); del(bgid);
    document.onkeydown = '';
}
