var NewsPics = {
    pics: new Array,
    titles: new Array,
    links: new Array,
    count: 0,
    timer: new Number,
    container: new String,
    getImg: new Array,
    getNum: new Array,
    getTitle: new Array,
    init: function () {
        var oImg = new String, oTitle = new String, oNum = new String;
        var getContainer = document.getElementById(this.container);
        for (var j = 0; j < this.pics.length; j++) {
            oImg += "<a href='" + this.links[j] + "' title='" + this.titles[j] + "' target='_blank'><img src='" + this.pics[j] + "' alt='" + this.titles[j] + "' /></a>";
            oTitle += "<h6><a href='" + this.links[j] + "' title='" + this.titles[j] + "' target='_blank'>" + this.titles[j] + "</a></h6>";
            oNum += "<li>" + (j + 1) + "</li>";
        }
        getContainer.innerHTML = oImg + oTitle + "<ul>" + oNum + "</ul>";
        this.getImg = getContainer.getElementsByTagName("img");
        this.getNum = getContainer.getElementsByTagName("ul")[0].getElementsByTagName("li");
        this.getTitle = getContainer.getElementsByTagName("h6");
        this.count = 0;
        this.autoSwitch();
        this.setControl();
    },
    autoSwitch: function () {
        if (NewsPics.count == 0) $(NewsPics.getImg[NewsPics.pics.length - 1]).fadeOut("fast", NewsPics.setSwitch);
        else $(NewsPics.getImg[NewsPics.count - 1]).fadeOut("fast", NewsPics.setSwitch);
        setAuto = setTimeout(arguments.callee, NewsPics.timer);
    },
    setControl: function () {
        for (var i = 0; i < this.pics.length; i++) {
            this.getNum[i].onmouseover = function () {
                clearTimeout(setAuto);
                NewsPics.count = this.innerHTML - 1;
                NewsPics.setSwitch();
            }
            this.getImg[i].onmouseover = function () { clearTimeout(setAuto); }
            this.getNum[i].onmouseout = function () {
                setAuto = setTimeout(NewsPics.autoSwitch, NewsPics.timer);
            }
            this.getImg[i].onmouseout = function () { setAuto = setTimeout(NewsPics.autoSwitch, NewsPics.timer) }
        }
    },
    setSwitch: function () {
        if (NewsPics.count < NewsPics.pics.length) {
            for (var i = 0; i <= NewsPics.getImg.length; i++) {
                if (i == NewsPics.count) {
                    NewsPics.getImg[i].style.zIndex = NewsPics.getImg.length - 1;
                    NewsPics.getImg[i].style.display = "";
                    NewsPics.getTitle[i].style.display = "block";
                    NewsPics.getNum[i].className = "active";
                    var t = i;
                    for (var j = 0; j < i; j++) {
                        t -= 1;
                        NewsPics.getImg[j].style.zIndex = t;
                        NewsPics.getImg[j].style.display = "";
                        NewsPics.getTitle[j].style.display = "none";
                        NewsPics.getNum[j].className = "";
                    }
                    var b = NewsPics.getImg.length - 1;
                    for (var h = i + 1; h < NewsPics.getImg.length; h++) {
                        b -= 1;
                        NewsPics.getImg[h].style.zIndex = b;
                        NewsPics.getImg[h].style.display = "";
                        NewsPics.getTitle[h].style.display = "none";
                        NewsPics.getNum[h].className = "";
                    }
                }
            }
            NewsPics.count += 1;
        }
        else {
            for (var i = 0; i < NewsPics.getImg.length; i++) {
                if (i == 0) {
                    NewsPics.getImg[i].style.zIndex = NewsPics.getImg.length - 1;
                    NewsPics.getImg[i].style.display = "";
                    NewsPics.getTitle[i].style.display = "block";
                    NewsPics.getNum[i].className = "active";
                    var t = i;
                    for (var j = 0; j < i; j++) {
                        t -= 1;
                        NewsPics.getImg[j].style.zIndex = t;
                        NewsPics.getImg[j].style.display = "";
                        NewsPics.getTitle[j].style.display = "none";
                        NewsPics.getNum[j].className = ""
                    }
                    var b = NewsPics.getImg.length - 1;
                    for (var h = i + 1; h < NewsPics.getImg.length; h++) {
                        b -= 1;
                        NewsPics.getImg[h].style.zIndex = b;
                        NewsPics.getImg[h].style.display = "";
                        NewsPics.getTitle[h].style.display = "none";
                        NewsPics.getNum[h].className = "";
                    }
                }
            }
            NewsPics.count = 1;
        }
    }
}
