﻿function addEvent(element, type, listener, useCapture) {
    if (element.addEventListener) {
        element.addEventListener(type, listener, useCapture);
        return true;
    }
    else if (element.attachEvent) {
        var r = element.attachEvent('on' + type, listener);
        return r;
    }
    else {
        element['on' + type] = listener;
    }
}
addEvent(window, 'load', function() { onloadshow() }, false);
function onloadshow() {
    showStroe();
    beginAutoShow();
    var small_li_array = $('tabsmall').getElementsByTagName('li');
    var fn;
    for (var i = 0; i < small_li_array.length; i++) {
        if (i == 0) {
            fn = function() { show(0); stopAutoShow(); };
        } else if (i == 1) {
            fn = function() { show(1); stopAutoShow(); };
        } else if (i == 2) {
            fn = function() { show(2); stopAutoShow(); };
        } else if (i == 3) {
            fn = function() { show(3); stopAutoShow(); };
        } else if (i == 4) {
            fn = function() { show(4); stopAutoShow(); };
        }
        addEvent(small_li_array[i], 'mouseover', fn, false);
        addEvent(small_li_array[i], 'mouseout', beginAutoShow, false);
    }
    var big_li_array = $('tabbig').getElementsByTagName('li');
    for (var x = 0; x < big_li_array.length; x++) {
        addEvent(big_li_array[x], 'mouseover', stopAutoShow, false);
        addEvent(big_li_array[x], 'mouseout', beginAutoShow, false);
    }
}
function show(index) {
    var big_li_array = $('tabbig').getElementsByTagName('li');
    for (var i = 0; i < big_li_array.length; i++) {
        if (index == i) {
            big_li_array[i].className = 'on';
        } else {
            big_li_array[i].className = '';
        }
    }
    var small_li_array = $('tabsmall').getElementsByTagName('li');
    for (var x = 0; x < small_li_array.length; x++) {
        if (index == x) {
            small_li_array[x].className = 'on';
        } else {
            small_li_array[x].className = '';
        }
    }
}
var timeCounter = 1;
function showTimer() {
    if (timeCounter > 4) {
        timeCounter = 0;
        show(0);
    } else {
        show(timeCounter);
    }
    timeCounter++;
}
function beginAutoShow() {
    autoShow = setInterval("showTimer();", 4000);
}
function stopAutoShow() {
    if (autoShow) {
        clearInterval(autoShow);
    }
}
function showStroe() {
    getPhotoNum();
    setInterval('getPhotoNum();', 3000);
}
function getPhotoNum() {
    XMLHttp.sendReq('POST', '/CommonHandler.ashx?action=HomeGetPhotoNum', null, getResult);
}
function getResult(obj) {
    if (obj.readyState == 4) {
        if (obj.status == 200 || obj.status == 304) {
            if (obj.responseText != '') {
                $('photonum').innerHTML = obj.responseText;
            }
        }
    }
}