﻿//从Prototype库抠出来的，版权归Prototype
var Prototype = {
    Version: '1.6.0',
    Browser: {
        IE: !!(window.attachEvent && !window.opera),
        Opera: !!window.opera,
        WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
        Gecko: navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1,
        MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/)
    },
    BrowserFeatures: {
        XPath: !!document.evaluate,
        ElementExtensions: !!window.HTMLElement,
        SpecificElementExtensions:
      document.createElement('div').__proto__ &&
      document.createElement('div').__proto__ !==
        document.createElement('form').__proto__
    },
    ScriptFragment: '<script[^>]*>([\\S\\s]*?)<\/script>',
    JSONFilter: /^\/\*-secure-([\s\S]*)\*\/\s*$/,
    emptyFunction: function() { },
    K: function(x) { return x }
};
//透明度间变
//id:目标引用，step:变化步长可为正或负，currentValue:当前值，targetValue：目标值
function addOpacity(id, step, currentValue, targetValue) {
    if (step < 0 && currentValue <= targetValue || step > 0 && currentValue >= targetValue)
        return;
    currentValue = currentValue + step;
    setOpacity(id, currentValue / 100);
   setTimeout(function() { addOpacity(id, step, currentValue, targetValue); },50);
}
//设置图片透明度
function setOpacity(id, value) {
    if (Prototype.Browser.IE) {
        id.filters.alpha.opacity = value * 100;
    }
    if (Prototype.Browser.Opera) {
        id.filters.alpha.opacity = value * 100;
    }
    if (Prototype.Browser.WebKit) {
        id.style.MozOpacity = value;
        id.style.Opacity = value;
    }
    if (Prototype.Browser.Gecko) {
        id.style.MozOpacity = value;
        id.style.Opacity = value;
    }
    if (Prototype.Browser.MobileSafari) {
        id.style.MozOpacity = value;
        id.style.Opacity = value;
    }
}

    var currentIndex = 0;
    var opacity 
    function animateImage(adimges, objDiv, timespan) {
        if (adimges && adimges.length == 0) return;
        if (currentIndex >= adimges.length) currentIndex = 0;
        objDiv.innerHTML = "<img src='" + adimges[currentIndex].image + "' alt='" + adimges[currentIndex].title + "' title='"+adimges[currentIndex].title+"' style='cursor:pointer;'/>";
        addOpacity(objDiv, 5, 0, 100);
        if (currentIndex == 0) timespan = 6000;
        else timespan = 4000;
        currentIndex++;
        opacity=setTimeout(function() { animateImage(adimges, objDiv, timespan) }, timespan);
        objDiv.onmouseover = function() {
            clearTimeout(opacity);
        }
        objDiv.onmouseout = function() { opacity = setTimeout(function() { animateImage(adimges, objDiv, timespan) }, timespan); }
    }

    function extendAnimateImage(adimges, objDiv, timespan) {
        if (adimges && adimges.length == 0) return;
        if (currentIndex >= adimges.length) currentIndex = 0;
        objDiv.innerHTML = "<img src='" + adimges[currentIndex].image + "' alt='" + adimges[currentIndex].title + "' title='" + adimges[currentIndex].title + "' onclick=\"zoom(this, this.src);\" onload=\"extendAttachimg(this, 'load',356);\" onmouseover=\"attachimg(this, 'mouseover')\"   />";
        if (adimges.length==1) return;
        addOpacity(objDiv, 5, 0, 100);
        currentIndex++;
        opacity = setTimeout(function() { extendAnimateImage(adimges, objDiv, timespan) }, timespan);
        objDiv.onmouseover = function() {
            clearTimeout(opacity);
        }
        objDiv.onmouseout = function() { opacity = setTimeout(function() { extendAnimateImage(adimges, objDiv, timespan) }, timespan); }
    }
