/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * 根据日期是不是过去的三天，返回相应的图片代码。
 */
function imgCode(date) {
    var img = new Array("images00/new.gif","images/bullet1.gif");
    var arr = date.split("-");
    var b = new Date(arr[0],arr[1]-1,arr[2]).getTime();
    var a = new Date().getTime();
    if(a-b<=3*1000*3600*24){
        return "<img src='"+img[0]+"'/>";
    }else{
        return "<img src='"+img[1]+"'/>";
    }
}
/**
 * 此方法使图片自动保持长宽比缩放在一个方形的框内。<br/>
 * 方法过程为：首先把图片显示在一个10x10的层中，层的样式设置为<b>overflow:hidden</b>。
 * 当图片装载完成，则自动调整大小，并自动改变层的样式为<b>overflow:visible</b>。
 * 已达到自适应大小的目的。<br/>
 * em，图片对象；id，层的id；length，方框的宽。
 */
function drawImage(em,length){
    if(em.width > em.height){
        em.width = length;
    }else{
        em.height = length;
    }
    em.style.cssFloat = "left";
    em.parentNode.style.width = em.width;
    em.parentNode.style.height = em.height;
}

function ColorEffect(id) {
    this.Em = document.getElementById(id);
    if(this.Em == null){
        alert("您要设置的\"" + id + "\"初始化错误\r\n请检查标签ID设置是否正确!");
        return;
    }
    this.colorArray = new Array("#66CCFF","#9999FF","#99CC33","#CC66FF","#D2691E");
    if(arguments[1] instanceof Array){
        this.colorArray = arguments[1];
    }
    this.time = 200;
    if(typeof arguments[2] == "number"){
        this.time = arguments[2];
    }
}
ColorEffect.prototype.Start = function(){
    if(this.Em == null){
        return;
    }
    var em = this.Em;
    var title = em.innerHTML;
    var colorArray = this.colorArray;
    var time = this.time;
    var sum = 0;
    setInterval(function (){
        var i = sum % title.length;
        var j = sum % colorArray.length;
        sum = (i==0 && j==0) ? 0:sum;
        var a = title.substr(0,i);
        var b = "<span style='color:"+colorArray[j]+";'>" + title.substr(i,1) + "</span>";
        var c = title.substr(i+1,title.length);
        em.innerHTML = a+b+c;
        sum++;
    },time);
}
