
// ===================== FlashImages 图片切换控件 ===========================
// name: FlashImages 图片切换控件
// author: sunyx
// version: 1.1

// ====================== 参数设置 ==============================
var FI_width = 760;                // 宽度
var FI_height = 180;               // 高度(如显示文字标题，图片高度应减去20像素)
var FI_showText = false;           // 是否显示文字标题
var FI_showFilter = true;          // 是否显示滤镜效果
var FI_switchDuration = 6000;      // 切换时间
var FI_filterDuration = 1;         // 滤镜周期
var FI_filterTransition = 12;       // 滤镜效果
/*
0 : 矩形收缩转换
1 : 矩形扩张转换
2 : 圆形收缩转换
3 : 圆形扩张转换
4 : 向上擦除
5 : 向下擦除
6 : 向右擦除
7 : 向左擦除
8 : 纵向百叶窗转换
9 : 横向百叶窗转换
10 : 国际象棋棋盘横向转换
11 : 国际象棋棋盘纵向转换
12 : 随机杂点干扰转换
13 : 左右关门效果转换
14 : 左右开门效果转换
15 : 上下关门效果转换
16 : 上下开门效果转换
17 : 从右上角到左下角的锯齿边覆盖效果转换
18 : 从右下角到左上角的锯齿边覆盖效果转换
19 : 从左上角到右下角的锯齿边覆盖效果转换
20 : 从左下角到右上角的锯齿边覆盖效果转换
21 : 随机横线条转换
22 : 随机竖线条转换
23 : 随机使用上面可能的值转换
*/

// ====================== 程序部分 ==============================
// 全局变量
var FI_switch = true;       // 切换开关
var FI_imageIndex = 1;      // 图片索引
var FI_imageCount = 0;      // 图片数量
var FI_filterValue;         // 滤镜样式

FI_filterValue = "progid:DXImageTransform.Microsoft.RevealTrans(duration=" + FI_filterDuration + ", transition=" + FI_filterTransition + ")";
FI_height = FI_showText == true ? FI_height - 20 : FI_height;

window.onload = function()
{
    // 迁移到resizeheight.js中
    // FI_CreateElements(); 
    // setTimeout("FI_SwtichImage()", 3000);
}

// 创建元素
function FI_CreateElements()
{
    // 获取容器
    var FI_box = document.getElementById("FI_box");
    
    FI_box.style.position = "absolute";
    FI_box.style.width = FI_width + "px";
    FI_box.style.height = FI_height + "px";
    
    // 创建图片
    var FI_images = document.createElement("div");
    FI_images.id = "FI_Images";
    
    FI_images.style.width = FI_width + "px";
    FI_images.style.height = FI_height + "px";
    
    FI_box.appendChild(FI_images);
    
    // 创建文字标题
    if (FI_showText == true)
    {
        var FI_textes = document.createElement("div");
        FI_textes.id = "FI_Textes";
        
        FI_textes.style.width = FI_width + "px";
        FI_textes.style.lineHeight = "20px";
        FI_textes.style.textAlign = "center";
        FI_textes.style.fontSize = "12px";
        FI_textes.style.background = "#fff";
        
        FI_box.appendChild(FI_textes);
    }
    
    // 创建数字按钮
    var FI_numbers = document.createElement("div");
    FI_numbers.id = "FI_Numbers";
    
    FI_numbers.style.position = "absolute";
    FI_numbers.style.styleFloat = "right";
    FI_numbers.style.bottom = "5px";
    FI_numbers.style.right = "5px";
    
    FI_box.appendChild(FI_numbers);
    
    var values = document.getElementById("FI_Values").value.split("|");
    FI_imageCount = values.length;
    
    for (var i = 0; i < FI_imageCount; i++)
    {
        var item = values[i].split(";");
        var a;
        var img;
        var text;
        
        // 图片项
        img = document.createElement("img");
        img.src = item[0];
        img.style.width = "100%";
        img.style.height = "100%";
        
        a = document.createElement("a");
        a.id = "FI_Images_" + i;
        a.style.display = i == 0 ? "" : "none";
        a.href = item[1];
        a.appendChild(img);
        
        FI_images.appendChild(a);
        
        // 文字项
        if (FI_showText == true)
        {
            text = document.createTextNode(item[2]);
            
            a = document.createElement("a");
            a.id = "FI_Textes_" + i;
            a.href = item[1];
            a.style.display = i == 0 ? "" : "none";
            a.appendChild(text);
            
            FI_textes.appendChild(a);
        }
        
        // 按钮项
        text = document.createTextNode(i + 1);
        
        a = document.createElement("a");
        
        a.style.styleFloat = "left";
        a.style.display = "block";
        a.style.marginLeft = "3px";
        a.style.width = "20px";
        a.style.lineHeight = "20px";
        a.style.textAlign = "center";
        a.style.color = "#fff";
        a.style.fontWeight = "bold";
        a.style.textDecoration = "none";
        a.style.background = i == 0 ? "red" : "black";
        
        a.id = "FI_Numbers_" + i;
        a.href = "javascript:FI_NumberClick(" + i + ");";
        a.appendChild(text);
        
        FI_numbers.appendChild(a);
    }
}

// 切换图片
function FI_SwtichImage()
{
    if (FI_switch == true)
    {
        var FI_images = document.getElementById("FI_Images");
        
        if (FI_images.filters && FI_showFilter == true)
        {
            FI_images.style.filter = FI_filterValue;
            FI_images.filters[0].Apply();
            FI_ShowImage();
            FI_images.filters[0].Play();
        }
        else
        {
            FI_ShowImage();
        } 
    }
    
    setTimeout("FI_SwtichImage()", FI_switchDuration);
}

// 显示图片
function FI_ShowImage()
{
    for (var i = 0; i < FI_imageCount; i++)
    {
        if (FI_imageIndex == i)
        {
            document.getElementById("FI_Images_" + i).style.display = "";
            if (FI_showText == true) {document.getElementById("FI_Textes_" + i).style.display = ""; }
            document.getElementById("FI_Numbers_" + i).style.background = "red";
        }
        else
        {
            document.getElementById("FI_Images_" + i).style.display = "none";
            if (FI_showText == true) {document.getElementById("FI_Textes_" + i).style.display = "none"; }
            document.getElementById("FI_Numbers_" + i).style.background = "black";
        }
    }
    
    FI_imageIndex = FI_imageIndex == FI_imageCount - 1 ? 0 : FI_imageIndex + 1;
}

// 数字按钮单击事件
function FI_NumberClick(numberIndex)
{
    FI_switch = false;
    FI_imageIndex = numberIndex;
    FI_ShowImage();
    
    setTimeout("FI_switch = true", 3000);
}
