
var FocusPic = function(BigPicID, SmallPicsID, TitleID, MemoID, width, height) {

    this.Data = [];

    this.ImgLoad = [];

    this.TimeOut = 5000;

    var isIE = navigator.appVersion.indexOf("MSIE") != -1 ? true: false;

    this.width = width;

    this.height = height;

    this.adNum = 0;

    var TimeOutObj;

    if (!FocusPic.childs) {

        FocusPic.childs = []

    };

    this.showTime = null;

    this.showSum = 10;

    this.ID = FocusPic.childs.push(this) - 1;

    this.Add = function(BigPic, SmallPic, Title, Url, Memo) {

        var ls;

        this.Data.push([BigPic, SmallPic, Title, Url, Memo]);

        ls = this.ImgLoad.length;

        this.ImgLoad.push(new Image);

        this.ImgLoad[ls].src = BigPic

    };

    this.TimeOutBegin = function() {

        clearInterval(TimeOutObj);

        TimeOutObj = setInterval("FocusPic.childs[" + this.ID + "].next()", this.TimeOut)

    };

    this.TimeOutEnd = function() {

        clearInterval(TimeOutObj)

    };

    this.select = function(num) {

        if (num > this.Data.length - 1) {

            return

        };

        if (num == this.adNum) {

            return

        };

        this.TimeOutBegin();

        if (BigPicID) {

            if (this.$(BigPicID)) {

                var aObj = this.$(BigPicID).getElementsByTagName("a")[0];

                aObj.href = this.Data[num][2];

                if (this.aImgY) {

                    this.aImgY.style.display = 'none';

                    this.aImg.style.zIndex = 0

                };

                this.aImgY = this.$('F' + this.ID + 'BF' + this.adNum);

                this.aImg = this.$('F' + this.ID + 'BF' + num);

                clearTimeout(this.showTime);

                this.showSum = 10;

                this.showTime = setTimeout("FocusPic.childs[" + this.ID + "].show()", 5);

            }

        };

        if (TitleID) {

            if (this.$(TitleID)) {

                this.$(TitleID).innerHTML = this.Data[num][3] ;

            }

        };

        if (MemoID) {

            if (this.$(MemoID)) {

                this.$(MemoID).innerHTML = this.Data[num][4]

            }

        };

        if (SmallPicsID) {

            if (this.$(SmallPicsID)) {

                var sImg = this.$(SmallPicsID).getElementsByTagName("span"),

                i;

                for (i = 0; i < sImg.length; i++) {

                    if (i == num || num == (i - this.Data.length)) {

                        sImg[i].className = "selected"

                    } else {

                        sImg[i].className = ""

                    }

                }

            }

        };

        if (this.onselect) {

            this.onselect()

        };

        this.adNum = num

    };

    var absPosition = function(obj, parentObj) {

        var left = obj.offsetLeft,

        top = obj.offsetTop,

        tempObj = obj;

        while (tempObj.id != document.body & tempObj.id != document.documentElement & tempObj != parentObj) {

            tempObj = tempObj.offsetParent;

            left += tempObj.offsetLeft;

            top += tempObj.offsetTop

        };

        return {

            left: left,

            top: top

        }

    };

    this.show = function() {

        this.showSum--;

        this.aImgY.style.display = 'block';

        this.aImg.style.display = 'block';

        if (isIE) {

            this.aImg.style.filter = "alpha(opacity=0)";

            this.aImg.style.filter = "alpha(opacity=" + (10 - this.showSum) * 10 + ")"

        } else {

            this.aImg.style.opacity = 0;

            this.aImg.style.opacity = (10 - this.showSum) * 0.1

        };

        if (this.showSum <= 0) {

            this.aImgY.style.display = 'none';

            this.aImg.style.zIndex = 0;

            this.aImgY = null

        } else {

            this.aImg.style.zIndex = 2;

            this.showTime = setTimeout("FocusPic.childs[" + this.ID + "].show()", 5)

        }

    };

    this.next = function() {

        var temp = this.adNum;

        temp++;

        if (temp >= this.Data.length) {

            temp = 0

        };

        this.select(temp)

    };

    this.MInStopEvent = function(ObjID) {

        if (ObjID) {

            if (this.$(ObjID)) {

                if (this.$(ObjID).attachEvent) {

                    this.$(ObjID).attachEvent("onmouseover", Function("FocusPic.childs[" + this.ID + "].TimeOutEnd()"));

                    this.$(ObjID).attachEvent("onmouseout", Function("FocusPic.childs[" + this.ID + "].TimeOutBegin()"))

                } else {

                    this.$(ObjID).addEventListener("mouseover", Function("FocusPic.childs[" + this.ID + "].TimeOutEnd()"), false);

                    this.$(ObjID).addEventListener("mouseout", Function("FocusPic.childs[" + this.ID + "].TimeOutBegin()"), false)

                }

            }

        }

    };

    this.begin = function() {

        this.MInStopEvent(TitleID);

        this.MInStopEvent(SmallPicsID);

        this.MInStopEvent(BigPicID);

        this.adNum = 0;

        var i,

        temp = "";  if (BigPicID) {

            if (this.$(BigPicID)) {

                var aObj = this.$(BigPicID).getElementsByTagName("a")[0];

                aObj.style.zoom = 1;

                this.$(BigPicID).style.position = "relative";

                this.$(BigPicID).style.zoom = 1;

                this.$(BigPicID).style.overflow = "hidden";

                for (i = 0; i < this.Data.length; i++) {

                    temp += '<img src="' + this.Data[i][0] + '" id="F' + this.ID + 'BF' + i + '" style="display:' + (i == this.adNum ? 'block': 'none') + '" galleryimg="no"' + (this.width ? ' width="' + this.width + '"': '') + (this.height ? ' height="' + this.height + '"': '') + ' alt="' + this.Data[i][3] + '" />'

                };

                aObj.innerHTML = temp;

                var imgObjs = aObj.getElementsByTagName("img");

                XY = absPosition(imgObjs[0], this.$(BigPicID));

            }

        };

        if (SmallPicsID) {

            if (this.$(SmallPicsID)) {

                temp = "";

                for (i = 0; i < this.Data.length; i++) {

                    temp += "<span" + (this.adNum == i ? ' class="selected"': "") + "><img src='" + this.Data[i][1] + "' onmouseover='FocusPic.childs[" + this.ID + "].select(" + i + ")' alt='" + this.Data[i][3] + "' /></span>"

                };

                this.$(SmallPicsID).innerHTML = temp;

            }

        };

        if (TitleID) {

            if (this.$(TitleID)) {

                this.$(TitleID).innerHTML =  this.Data[this.adNum][3];

            }

        };

      

        if (MemoID) {

            if (this.$(MemoID)) {

                this.$(MemoID).innerHTML = this.Data[this.adNum][4];

            }

        };

        this.TimeOutBegin();

    };

    this.$ = function(objName) {

        if (document.getElementById) {

            return eval('document.getElementById("' + objName + '")');

        } else {

            return eval('document.all.' + objName);

        }

    }

};
