﻿//create by chenhao 2009-08-27  version 1.0.0.09082700
//edit by chenhao 2009-08-28   version 1.0.0.09082800
function newPictureNews() {
    ///	<summary>
    ///	创建图片新闻脚本的实例
    ///	</summary>
    ///<returns>返回新的实例</returns>
    return {
        jsonData: null,   //总条数     jsonData格式：[{imgsrc:value,url:value,title:value,message:value,button:value}]
        select: 0, //当前所显示的滚动图
        key: 0,  //标识是否为第一次开始执行
        tt: null,   //标识作用
        delay: 4000, //延迟多久刷新
        unSelectStyleClassName: "unSelect", //未选中的样式
        selectStyleClassName: "select", //选中的样式
        pictureContent: null, //展示图片的元素
        pictureTitle: null,
        link: null,
        newsTitle: null, //图片新闻摘要的标题
        newsSummary: null, //图片新闻摘要的容器
        newsDetail: null, //图片新闻摘要的内容
        change_img: function() {
            ///	<summary>
            ///	图片切换
            ///	</summary>
            if (this.key == 0)
            { this.key = 1; } //如果第一次执行KEY=1，表示已经执行过一次了。
            else if (document.all)//document.all仅IE6/7认识，firefox不会执行此段内容
            {
                if (this.pictureContent.filters.length > 0) {
                    this.pictureContent.filters[0].Apply(); //将滤镜应用到对像上
                    this.pictureContent.filters[0].Play(duration = 2);  //开始转换
                    this.pictureContent.filters[0].Transition = 23; //转换效果
                }
            }

            var data = eval(this.jsonData);
            this.pictureContent.src = data[this.select].imgsrc;
            this.pictureContent.title = data[this.select].message;
            this.pictureTitle.value = data[this.select].title;
            this.pictureTitle.title = data[this.select].message;
            this.link.href = data[this.select].url;


            //yf:图片中心右侧新闻摘要随着图片的切换而切换
            if (this.newsTitle != null) {
                this.newsTitle.innerHTML = data[this.select].newsTitle;
                this.newsSummary.innerHTML = data[this.select].newsSummary;
                this.newsDetail.href = data[this.select].url;
            }
            //yf:图片中心右侧新闻摘要随着图片的切换而切换

            for (var i = 0; i < data.length; i++) {
                document.getElementById(data[i].button).className = this.unSelectStyleClassName;   //将下面黑条上的所有链接变为未选中状态
            }
            document.getElementById(data[this.select].button).className = this.selectStyleClassName;    //将当前页面的ID设置为选中状态
            this.select++;
            if (this.select == data.length || this.select > data.length)
            { this.select = 0; }

            var _this = this; //当使用Windows.seInterval方法时,回调的函数会被作为一个window下的成员, 会提示不存在这样的方法
            var go = function() { _this.change_img(); } //当使用Windows.seInterval方法时,回调的函数会被作为一个window下的成员, 会提示不存在这样的方法
            this.tt = setTimeout(go, this.delay);  //在4秒后重新执行change_img()方法.
        },
        changeimg: function(newPicIndex)//点击黑条上的链接执行的方法。
        {
            ///	<summary>
            ///	切换到指定索引的图片
            ///	</summary>
            ///<param name="newPicIndex">需要切换到的索引</param>
            this.select = newPicIndex; //当前页面的ID等于传入的N值,
            this.stop();
            this.change_img();
        },
        start: function() {
            ///	<summary>
            ///	启动
            ///	</summary>
            this.change_img();
        },
        stop: function() {
            ///	<summary>
            ///	停止
            ///	</summary>
            clearTimeout(this.tt); //清除用于循环的TT
        },

        initThis: function(title, url, pic, newsT, newsS, newsD) {
            ///	<summary>
            ///	初始化当前对象   默认为picTitle,url,picTemp,newsTitle,newsSummary,newsDetail
            ///	</summary>
            ///<param name="title">标题容器的id</param>
            ///<param name="url">链接的id</param>
            ///<param name="pic">图片容器的id</param>
            ///<param name="newsT">图片新闻摘要的标题</param>
            ///<param name="newsS,">图片新闻摘要的容器</param>
            ///<param name="newsD">图片新闻摘要的内容</param>

            if (title == null)
                title = "picTitle";
            if (url == null)
                url = "url";
            if (pic == null)
                pic = "picTemp";
            if (newsT == null)
                newsT = "newsTitle";
            if (newsS == null)
                newsS = "newsSummary";
            if (newsD == null)
                newsD = "newsDetail";

            this.pictureContent = document.getElementById(pic);
            this.pictureTitle = document.getElementById(title);
            this.link = document.getElementById(url);

            this.newsTitle = document.getElementById(newsT);
            this.newsSummary = document.getElementById(newsS);
            this.newsDetail = document.getElementById(newsD);

        }

    };
}


