﻿/*-----实现阴影艺术字效果-------
-------fctText  文字内容
-------fctTop   文字在页面中距顶位置
-------fctLeft  文字在页面中距左位置
-------fctBold  阴影宽度
-------Color    文字颜色
-------bgColor  阴影颜色
-------FontSize 文字大小*/
if(typeof(pyzy)=='undefined'){
	var pyzy={}; //起用封装方法名称，避免脚本命名污染
	pyzy.$ = function(fctId) { return document.getElementById(fctId); };
}
pyzy.ColorText=function(fctText,fctTop,fctLeft,fctBold,Color,bgColor,FontSize){
	var varZBT=(fctTop-fctBold/2);
	var varZBL=(fctLeft-fctBold/2);
	var varWriteText="";
	for(var i=1;i<fctBold;i++){
		for(var j=1;j<fctBold;j++){
			varWriteText=varWriteText+'<div style="position:absolute;z-index:98;margin:'+(varZBT+i)+'px '+(varZBL+j)+'px;color:'+bgColor+';font-size:'+FontSize+'px;">'+fctText+'</div>';
		}
	}
	return varWriteText+'<div style="position:absolute;z-index:98;margin:'+fctTop+'px '+fctLeft+'px;color:'+Color+';font-size:'+FontSize+'px;">'+fctText+'</div>';
}
//CloseImgBox
//图片盒子展示工具主要方法
pyzy.MinImgsBox = {
    intImgId: 0, //默认图片ID
    arrImgs: [["图片名称", "大图路径", "小图路径","图片介绍"]], //图片数据
    objMaxImgBoxObj: null, //大图片容器
    objMinImgBoxObj: null, //小图片容器	
    objMinImgObj: null,    //当前正在播放的小图的IMG对象，用于校对小图容器的滚动条位置等
    objPlayRateObj: null,  //播放进度对象
    /*Init索引方法：
    @fctArrImgs：图片信息数据数组，参见arrImgs的格式*/
    Init: function(fctArrImgs) {
        this.arrImgs = fctArrImgs;  //将图片数据存储于变量中
        this.objMaxImgBoxObj = pyzy.$("divPyzyImgBoxContent"); //将大图片容器存储于变量
        this.objMinImgBoxObj = pyzy.$("divPyzyMinImgs"); //将小图片容器存储于变量
        this.objPlayRateObj = pyzy.$("divPyzyImgBoxRate"); //将播放进度对象存储于变量
        var tmpMinImgsBoxHTML = []; //临时小图列表存储
        for (var intI = 0; intI < this.arrImgs.length; intI++) {
            tmpMinImgsBoxHTML[tmpMinImgsBoxHTML.length] = "<img id='imgMinItem" + intI + "' onClick='pyzy.MinImgsBox.Show(" + intI + ")' alt='" + this.arrImgs[intI][0] + "' src='" + this.arrImgs[intI][2] + "' />"
        }
        this.objMinImgBoxObj.innerHTML = tmpMinImgsBoxHTML.join(""); //输出小图列表到容器
        this.Show(0); //默认显示第一个图片
    },
    Show: function(fctId) {
        if (this.arrImgs.length == 0) {
            alert("缺少图片数据");
            return;
        }
        //判断ID并矫正为正确编号
        fctId = (fctId < 0 ? this.arrImgs.length - 1 : (fctId >= this.arrImgs.length ? 0 : fctId));
        //播放进度
        this.objPlayRateObj.title = "共[" + this.arrImgs.length + "]张图片，当前为第[" + (fctId+1) + "]张图片，播放进度为" + ((fctId + 1) / this.arrImgs.length * 100) + "%。";
        this.objPlayRateObj.style.width = ((fctId + 1) / this.arrImgs.length * this.objPlayRateObj.parentNode.offsetWidth) + "px";
        //取得当前播放图片的小图对象
        this.objMinImgObj = pyzy.$("imgMinItem" + fctId)
        //调整小图片容器滚动条位置，使得当前图片在容器的中间
        pyzy.MinImgsScroll.Init(
            this.objMinImgBoxObj,
            (
                ( //先通过小图片对象的左边距与得出图片与容器左边的距离：因为IE环境下的元素边距是相对于父容器的，而火狐下是相对于窗体，所以这里用到了浏览器环境的判断
                    this.objMinImgObj.offsetLeft -
                    (navigator.appVersion.indexOf("MSIE") == -1 ? this.objMinImgObj.parentNode.offsetLeft:0)
                ) -  //减掉图片容器滚动条已经卷掉的相素，这样取到的是可以使小图片始终居于容器最左边的，所以接下来减掉容器一半的宽度恰巧就可以使小图片居于容器中间
                this.objMinImgBoxObj.scrollLeft
                -
                (this.objMinImgBoxObj.offsetWidth / 2)
             )
        );
        //输出图片名称到大图片容器
        this.objMaxImgBoxObj.innerHTML = pyzy.ColorText(this.arrImgs[fctId][0], 0, 0, 4, "#444;bottom:2px;right:10px", "#444;bottom:2px;right:10px", 12) + pyzy.ColorText(this.arrImgs[fctId][0], 2, 2, 4, "#666;bottom:2px;right:10px", "#fff;bottom:2px;right:10px", 12);
        //用当前大图片路径替掉大图片容器的背景
        this.objMaxImgBoxObj.style.backgroundImage = "url(" + this.arrImgs[fctId][1] + ")";
        //取消先前的默认图片的选中状态
        pyzy.$("imgMinItem" + this.intImgId).className = "";
        //设置先前的默认图片为样式为选中状态
        this.objMinImgObj.className = "Sel";
        this.intImgId = fctId;
		document.getElementById("Note").innerHTML=this.arrImgs[fctId][3];
    }
};
//滚动条控制方法
pyzy.MinImgsScroll = {
    intAllScrollSeep: 0, //步长，单次滚动的幅度
    intScrollCount: 0,   //滚动长度记录 记录按象素滚动的长度与步长对比 用以实现动态滚动效果
    objScroll: null,     //要控制其滚动条的目标对象
    boolLeft: true,      //滚动条类型，默认为左右水平滚动条
    /*Init索引方法：
    @(fctBoxObj)：要控制其滚动条的目标对象，必须指定
    @[fctSeep]：移动步长，按正负数控制左右滚动，不指定则默认为目标对象的宽度（如果是垂直则为其高度）
    @[fctTop]：滚动条类型，默认Left为左右水平滚动条，此参数指定任意值则为垂直滚动条*/
    Init: function(fctObj, fctSeep, fctTop) {
        this.objScroll = fctObj;
        this.boolLeft = (fctTop == null);
        this.intAllScrollSeep = (fctSeep == null ? (this.boolLeft ? this.objScroll.offsetWidth : this.objScroll.offsetHeight) : fctSeep);
        //判断滚动步长值，如果为当前状态的反方向，则将滚动幅度取反
        this.intSeep = ((this.intAllScrollSeep < 0 && this.intSeep > 0) || (this.intAllScrollSeep > 0 && this.intSeep < 0) ? -1 : 1) * this.intSeep;
        this.intScrollCount = 0; //初始化步长执行进度统计为0
        this.AutoSeep();
    },
    intSeep: 5, //自动滚动时的幅度，默认为10象素
    AutoSeep: function() {
        if (Math.abs(this.intAllScrollSeep) > Math.abs(this.intScrollCount)) { //是否已经完成滚动步长
            this.intScrollCount += this.intSeep;
            if (this.boolLeft) { this.objScroll.scrollLeft += this.intSeep; }
            else { this.objScroll.scrollTop += this.intSeep; }
            window.setTimeout("pyzy.MinImgsScroll.AutoSeep();", 8); //8毫秒后继续执行滚动，也可以更改此参数控制滚动时的速度
        }
    }
};

/*--------------------------------幻灯片js----------------------------------------*/

function $(id) {return document.getElementById(id);}
function $$(tag,id){return (id==undefined?document:this.$(id)).getElementsByTagName(tag);}
function poptit(tsID,n){//文字上下运动函数
	var ts = $$('li',tsID);
	var setway=function(obj,y){obj.style.bottom=y+'px';}
	var getway=function(obj){return parseInt(obj.style.bottom);}
	var up=function(){
		if (ts[n].movement) clearTimeout(ts[n].movement);//为了兼容变化中的点击
		if (y1 == 0) return true;
		y1+=Math.ceil((0 - y1) / 5);
		setway(ts[n],y1);
		if(y1<0) ts[n].movement = setTimeout(up, 1);
	}
	var down=function(){
		if (ts[N].movement) clearTimeout(ts[N].movement);
		if (y2 == -32) return true;
		y2+=Math.floor((-32 - y2) / 5);
		setway(ts[N],y2);
		if(y2>-32) ts[N].movement = setTimeout(down, 1);
	}
	for(var i=0;i<ts.length;i++){
		if (!ts[i].style.bottom) ts[i].style.bottom = "-32px";
		if(ts[i].name=='up') var N=i;
	}
	if(!N&&n==0) {//开始载入...
		ts[n].name='up';
		var y1=getway(ts[n]);
		up();
		return true;
	} 
	if(N==n) return true;//防止快速移出移入的抖动
	ts[N].name=''//标记淡入的name为空
	ts[n].name='up';
	var y1=getway(ts[n]);
	var y2=getway(ts[N]);
	down();
	up();
}
function opa(pics,n){//图片淡入淡出函数
	var pics = $$('img',pics);
	var setfade=function(obj,o){
		if (document.all) obj.style.filter = "alpha(opacity=" + o + ")";
		else obj.style.opacity = (o / 100);
	};
	var getfade=function(obj){
		return (document.all)?((obj.filters.alpha.opacity)?obj.filters.alpha.opacity:false):((obj.style.opacity)?obj.style.opacity*100:false);
	}
	var show=function(){
		if(pics[n].move) clearTimeout(pics[n].move);
		if (o1 == 100) return true;
		o1+=5;
		setfade(pics[n],o1);
		if(o1<100) pics[n].move=setTimeout(show,1);
	};
	var hide=function(){
		if(pics[N].move) clearTimeout(pics[N].move);
		if (o2 == 0) return true;
		o2-=5;
		setfade(pics[N],o2);
		if(o2>0) pics[N].move=setTimeout(hide,1);
	};
	for(var i=0;i<pics.length;i++){
		if(!getfade(pics[i])) setfade(pics[i],0);
		if(pics[i].name=='out') var N=i;
	}
	if(!N&&n==0) {//开始载入...
		pics[n].name='out';
		var o1=getfade(pics[n]);
		show();
		return true;
	}
	if(N==n) return true;
	pics[N].name=''
	pics[n].name='out';
	var o1=getfade(pics[n]);
	var o2=getfade(pics[N]);

	hide();
	show();
}
function classNormal() {//数字标签样式清除
    var focusBtnList = $$('li','btn');
    for (var i = 0; i < focusBtnList.length; i++) {
        focusBtnList[i].className = '';
    }
}
function autoFocusChange() {//自动运行
    if (atuokey) return;
    var focusBtnList = $$('li','btn');
    for (var i = 0; i < focusBtnList.length; i++) {
        if (focusBtnList[i].className == 'current') {
            var currentNum = i;
        }
    }
	if(currentNum<focusBtnList.length-1){
		poptit('ts',currentNum+1);
		opa('pics',currentNum+1);
       	classNormal();
       	focusBtnList[currentNum+1].className = 'current';
	}else if(currentNum==focusBtnList.length-1){
		poptit('ts',0);
		opa('pics',0);
       	classNormal();
       	focusBtnList[0].className = 'current';
	}
}
function focusChange() {//交互切换
    var focusBtnList = $$('li','btn');
    for (var i = 0; i < focusBtnList.length; i++) {
		focusBtnList[i].I=i;
		focusBtnList[i].onclick = function(){
        	poptit('ts',this.I);
			opa('pics',this.I);
        	classNormal();
        	focusBtnList[this.I].className = 'current';
		}
		focusBtnList[i].onmouseover = function(){
			this.style.backgroundColor='#f60';
			this.style.cursor='pointer';
		}
		focusBtnList[i].onmouseout = function(){
			this.style.backgroundColor='';
		}
	}
}
var atuokey = '';
function init(){//初始化
	$('btn_bg').innerHTML=$('btn').innerHTML;
	$('focus_change').removeChild($$('div','focus_change')[0]);
	poptit('ts',0);
	opa('pics',0);
    classNormal();
    $$('li','btn')[0].className = 'current';
	$('focus_change').onmouseover = function() {
        atuokey = true;
		clearInterval(auto);
    }
    $('focus_change').onmouseout = function() {
        atuokey = false;
		auto=setInterval('autoFocusChange()', T);
    }
}
var T=3000;//每帧图片停留的时间，1000=1秒
var auto='';
window.onload=function(){
	init();
	focusChange();
	auto=setInterval('autoFocusChange()', T);
}
/*-------------------------------汇率js----------------------------------------*/

