var flag = 0;
jQuery.extend(jQuery.easing,
{
    def: 'easeOutQuad',
    easeInOutExpo: function (x, t, b, c, d) {
        if (t == 0) return b;
        if (t == d) return b + c;
        if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
        return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
    }
});

var H3C = {};
H3C.namespace = function (str) {
    var arr = str.split('.'), o = H3C;
    for (i = (arr[0] == 'H3C') ? 1 : 0; i < arr.length; i++) {
        o[arr[i]] = o[arr[i]] || {};
        o = o[arr[i]];
    }
}

H3C.namespace('page.mainView');
H3C.namespace('form');

H3C.page.isIE6 = function () {
    var isIE = ! +'\v1'; 
    var IE6 = isIE && /MSIE (\d)\./.test(navigator.userAgent) && parseInt(RegExp.$1) < 7;
    return IE6;
}
H3C.page.mainView = function () {
    var c = $('#mainview .mainviewul');
    var w = $('#mainview').width();
    var t = c.find('li').length;
    var tw = $("#mainview .width1003").offset().left; 
    var h = '';
    var o = null;
    var autohide = $('#mainview').attr('autoHideController');
    var easing = 'easeInOutExpo', speed = 8000, is = false;
    var animate = $('#mainview').attr('animate');

    c.attr('index', 0);
    $('#menu li').removeClass('current');
	if($('#menu li:eq(' + 0 + ')').hasClass('dark'))
    {
      $('.news').attr('id','newsdiv');
    }
    else
    {
      $('.news').attr('id','');
    }
    $('#menu li:eq(0)').addClass('current');
    if (animate && animate == 'hide') {
        c.css({ 'width': w + 'px', 'position': 'relative' }).find('li').each(function (index) {
            $(this).css({ 'position': 'absolute', 'left': '0px', 'top': '0px', 'z-index': (t - index) });
        });
    } else {
        c.css('width', t * w + 'px');
    }
    c.find('li').each(function () {
        var bc = $(this).attr('backgroundcolor');
        if (!bc) bc = 'transparent';
        $(this).css('background', 'url(' + $(this).attr('src') + ') center top no-repeat scroll ' + bc).css('width', w + 'px');
        var links = eval('(' + $(this).attr('links') + ')');
        var me = $(this);
        if (links) {
            $(links).each(function () {
                $('<a href="' + this.href + '" class="imglinks" style="width:' + this.w + 'px;height:' + this.h + 'px;left:' + (tw + this.x) + 'px;top:' + this.y + 'px;"> </a>').appendTo(me);
            })
        }
    });
    var play = function (p) {
        is = true;
        c.attr('index', p);
        if (animate && animate == 'hide') {
            c.find('li:lt(' + p + ')').fadeOut(1000);
            c.find('li:gt(' + p + ')').fadeOut(1000);
            c.find('li:eq(' + p + ')').fadeIn(2000, function () { is = false });
        } else {
            c.animate({ marginLeft: -p * $('#mainview').width() + 'px' }, 500, easing, function () {
                is = false;
            });
        }
		if($('#menu li:eq(' + p + ')').hasClass('dark'))
    {
      $('.news').attr('id','newsdiv');
    }
    else
    {
      $('.news').attr('id','');
    }

        $('#menu li').removeClass('current');
        $('#menu li:eq(' + p + ')').addClass('current');
    }
    var autoplay = function () {
        var p = parseInt(c.attr('index'));
        p++;
        if (p >= t) p = 0;
        play(p);
    }
    if (t > 1) {
        o = setInterval(autoplay, speed);
        $('#menu a').each(function (i) {
            $(this).click(function () {
                if (!is) {
                    clearInterval(o);
                    o = null;
                    var p = parseInt($(this).attr('index'));
                    c.find('li').stop(true, true);
                    play(p);
                    o = setInterval(autoplay, speed);
                }
            });
        });
        c.find('li').each(function () {
            $(this).hover(function () {
                clearInterval(o);
                o = null;
            }, function () {
                o = setInterval(autoplay, speed);
            });

        });
    }
    setInterval(function () {
        if (!is) {
            if (!(animate && animate == 'hide')) {
                var p = parseInt(c.attr('index'));
                c.css('marginLeft', -p * $('#mainview').width() + 'px');
            }
            c.find('li').each(function () {
                var links = eval('(' + $(this).attr('links') + ')');
                var me = $(this);
                if (links) {
                    $(links).each(function (index) {
                      me.find('a.imglinks:eq(' + index + ')').css('left', ($('#mainview .width1003').offset().left + this.x) + 'px');
                    })
                }
            });
        }
    }, 100);
    $(window).resize(function () {
        w = $('#mainview').width();
        c.find('li').css('width', w + 'px');
        c.css('width', t * w + 'px')
    });


}
H3C.page.onLoad = function () {
    H3C.page.mainView();
}
$(function () {
    H3C.page.onLoad();
})

