﻿//首页鼠标经过事件。labelID：导航ID，switchID：显示层ID，maxNum：总数量
function EventFlash(labelID, switchID, maxNum) {
    for (i = 1; i <= maxNum; i++)
        document.getElementById(labelID + i).onmouseover = JSSet(labelID, switchID, i, maxNum);
    JSShow(labelID, switchID, 1, maxNum);
}
var JSSet = function (labelID, switchID, num, maxNum) {
    return function () { JSShow(labelID, switchID, num, maxNum); }
}
//num：当前激活标签数字顺序
function JSShow(labelID, switchID, num, maxNum) {
    for (i = 1; i <= maxNum; i++) {
        document.getElementById(labelID + i).style.background = "url(../images/f"+i+".gif)";  //未激活导航样式
        document.getElementById(labelID + i).style.height = "27px"; //调整高度
        document.getElementById(switchID + i).style.display = "none";    //隐藏未激活层
    }
    document.getElementById(labelID + num).style.background = "url(../images/f_a"+num+".gif)";  //激活导航样式
    document.getElementById(labelID + num).style.height = "32px"; //调整高度
    document.getElementById(switchID + num).style.display = ""; //显示激活层
}

//首页鼠标经过事件1。labelID：导航ID，switchID：显示层ID，maxNum：总数量
function EventFlash1(labelID, switchID, maxNum) {
    for (i = 1; i <= maxNum; i++)
        document.getElementById(labelID + i).onmouseover = JSSet1(labelID, switchID, i, maxNum);
    JSShow1(labelID, switchID, 1, maxNum);
}
var JSSet1 = function (labelID, switchID, num, maxNum) {
    return function () { JSShow1(labelID, switchID, num, maxNum); }
}
function JSShow1(labelID, switchID, num, maxNum) {
    for (i = 1; i <= maxNum; i++) {
        document.getElementById(labelID + i).style.background = "url(../images/dh6.gif)";  //未激活导航样式
        document.getElementById(labelID + i).style.color = "#014b94";
        document.getElementById(switchID + i).style.display = "none";    //隐藏未激活层
    }
    document.getElementById(labelID + num).style.background = "url(../images/dh5.gif) repeat-x";  //激活导航样式
    document.getElementById(labelID + num).style.color = "White";
    document.getElementById(switchID + num).style.display = ""; //显示激活层
}

//首页鼠标经过事件2。labelID：导航ID，switchID：显示层ID，maxNum：总数量
function EventFlash2(labelID, switchID, maxNum) {
    for (i = 1; i <= maxNum; i++)
        document.getElementById(labelID + i).onmouseover = JSSet2(labelID, switchID, i, maxNum);
    JSShow2(labelID, switchID, 1, maxNum);
}
var JSSet2 = function (labelID, switchID, num, maxNum) {
    return function () { JSShow2(labelID, switchID, num, maxNum); }
}
function JSShow2(labelID, switchID, num, maxNum) {
    for (i = 1; i <= maxNum; i++) {
        document.getElementById(labelID + i).style.background = "none";  //未激活导航样式
        document.getElementById(labelID + i).style.borderBottom = "solid 1px #cfcfcf";  //未激活导航样式
        document.getElementById(switchID + i).style.display = "none";    //隐藏未激活层
    }
    document.getElementById(labelID + num).style.background = "url(../images/dh12.gif)";  //激活导航样式
    document.getElementById(labelID + num).style.borderBottom = "none";  //未激活导航样式
    document.getElementById(switchID + num).style.display = ""; //显示激活层
}

//首页鼠标经过事件1。labelID：导航ID，switchID：显示层ID，maxNum：总数量,moreid:更多ID
function EventFlash3(labelID, switchID, maxNum,moreid) {
    for (i = 1; i <= maxNum; i++)
        document.getElementById(labelID + i).onmouseover = JSSet3(labelID, switchID, i, maxNum,moreid);
    JSShow3(labelID, switchID, 1, maxNum,moreid);
}
var JSSet3 = function (labelID, switchID, num, maxNum,moreid) {
    return function () { JSShow3(labelID, switchID, num, maxNum,moreid); }
}
function JSShow3(labelID, switchID, num, maxNum,moreid) {
    for (i = 1; i <= maxNum; i++) {
        document.getElementById(labelID + i).style.background = "url(../images/dh6.gif)";  //未激活导航样式
        document.getElementById(labelID + i).style.color = "#014b94";
        document.getElementById(switchID + i).style.display = "none";    //隐藏未激活层
        document.getElementById(moreid + i).style.display = "none";    //隐藏未激活层
    }
    document.getElementById(labelID + num).style.background = "url(../images/dh5.gif) repeat-x";  //激活导航样式
    document.getElementById(labelID + num).style.color = "White";
    document.getElementById(switchID + num).style.display = ""; //显示激活层
    document.getElementById(moreid + num).style.display = ""; //显示激活层
}

//字数限制，无提示  例： onKeyDown="subcontent(this,255)" onKeyUp="subcontent(this,255)" onFocus="subcontent(this,255)"
function subcontent(nid, num) {
    var l = nid.value.length;
    if (l > num) {
        nid.value = nid.value.substring(0, num);
        alert("字数超出250字，多出字符将被截断");
    }
}
//字数限制，有提示  例： onKeyDown="subcontent(this,255,'div')" onKeyUp="subcontent(this,255,'div')" onFocus="subcontent(this,255,'div')"
function subConTip(nid, num, divp) {
    var l = nid.value.length;
    if (l > num) {
        nid.value = nid.value.substring(0, num);
        document.getElementById(divp).innerHTML = "<font color=red>*</font>您已输入" + nid.value.length + "个字。";
    }
    else {
        document.getElementById(divp).innerHTML = "<font color=red>*</font>您已输入" + l + "个字。";
    }
}

//flash幻灯
function e(p, ele) { return p.getElementsByTagName(ele) };
function el(id) { return document.getElementById(id) };
function t(o, e, f) { o.addEventListener ? o.addEventListener(e, f, false) : o.attachEvent('on' + e, f) };
var ss = {};
ss.slider = function () {
    var arg, move = function () { };
    move.prototype.init = function (opt) {
        arg = this.set(opt);
        var wrap = el(opt.gallery),
ctl = el(opt.control),
obj = this.obj = e(wrap, 'ul')[0],
$this = this;
        this.u = e(obj, 'li');
        this.cu = e(ctl, 'li');
        this.uW = this.u[0].offsetWidth;
        this.uH = this.u[0].offsetHeight;
        this.len = this.u.length;
        this.old = this.cur = arg.index;
        wrap.style.cssText = 'width:' + this.uW + 'px;' + 'height:' + this.uH + 'px;' + 'overflow: hidden;';
        obj.style.cssText = 'height:' + this.uH + 'px;' + 'width:' + (arg.dir ? this.uW + 'px;' : this.len * this.uW + 'px;') + (arg.dir ? 'top:' + -1 * this.cur * this.uH + 'px;' : 'left:' + -1 * this.cur * this.uW + 'px;');
        this.cu[this.cur].className = 'current';
        this.event(arg.type);
        setTimeout(function () { $this.auto() }, arg.interval);
    };
    move.prototype.set = function (opt) {
        org = {
            gallery: 'gal-wrap',
            control: "gal-panel",
            dir: false,
            index: 0,
            speed: 16,
            interval: 3000,
            type: 'click'
        };
        for (var p in opt) {
            org[p] = opt[p]
        }
        return org;
    };
    move.prototype.timeMgr = function () {
        var $this = this;
        this.m = setTimeout(function () { $this.auto(); $this.indexMgr() }, arg.interval);
    };
    move.prototype.auto = function () {
        var $this = this;
        if (this.a != undefined) clearInterval(this.a);
        this.a = setInterval(function () { $this.pos() }, arg.speed);
    };
    // Downloads By http://down.liehuo.net
    move.prototype.pos = function () {
        var dir = arg.dir ? parseInt(this.obj.style.top) : parseInt(this.obj.style.left),
area = arg.dir ? this.uH : this.uW,
dis = (area * this.cur + dir) * .1,
step = dis >= 0 ? Math.ceil(dis) : Math.floor(dis);
        arg.dir ? this.obj.style.top = dir - step + 'px' : this.obj.style.left = dir - step + 'px';
        this.stop(dir, area);
    };
    move.prototype.stop = function (dir, area) {
        if (Math.abs(dir) == area * this.cur) {
            clearInterval(this.a);
            this.cur == this.len - 1 ? this.cur = 0 : this.cur++;
            this.timeMgr();
        }
    };
    move.prototype.indexMgr = function () {
        this.cu[this.cur].className = 'current';
        if (this.old != this.cur) {
            this.cu[this.old].className = '';
            this.old = this.cur;
        }
    };
    move.prototype.event = function (e) {
        for (var i = 0; i < this.cu.length; i++) {
            var $this = this;
            t(this.cu[i], e, num(i, $this));
        }
        function num(n, $this) {
            return function () {
                clearInterval($this.a);
                clearTimeout($this.m);
                $this.cu[n].className = 'current';
                if ($this.old != n) {
                    $this.cu[$this.old].className = '';
                    $this.old = $this.cur = n;
                }
                $this.c = 0;
                $this.auto();
            }
        }
    };
    return move;
} ();
