$(document).ready(function() {

    var bodyW = $('body').width();

    /*menu position*/
    var paddingL = (bodyW - 1000) / 2;
    var menuW = $('.menu').width();
    var menuArrow = $('.main').attr('id');
    var menuText = $('.menu a').width();
    $('.menu').css({
        'width': menuW,
        'padding-left': paddingL
    });




    var backgroundT = 0;
    $('.menu li').each(function() {
        var txt = $(this).find('a').attr('name').slice(3);
        var liH = $(this).height();
        var liP = parseInt($(this).css('padding-bottom'));
        liH += liP;

        if (txt == menuArrow) {
            $(this).find('.children').show();
            $(this).addClass('on');
            $('.menu').css('background-position', 'right ' + (backgroundT) + 'px');
        }
        backgroundT += liH;
    })




    /*
    if(menuArrow=='index'){$('.menu li:eq(0)').addClass('on');}
    if(menuArrow=='product'){$('.menu li:eq(1)').addClass('on');}
    if(menuArrow=='design'){$('.menu li:eq(2)').addClass('on');}
    if(menuArrow=='about' || menuArrow=='certificate'){
    $('.menu li:eq(3)').addClass('on');
    $('.menu li:eq(3) a').css('background','none');
    var children=$('.guidelines').text();
    $('.children ul').addClass('on');
    if(children=='公司简介'){$('.children li:eq(0)').addClass('on');}
    if(children=='公司荣誉'){$('.children li:eq(1)').addClass('on');}
    }
    if(menuArrow=='contact'){$('.menu li:eq(4)').addClass('on');}
    */


    function doubleColor(tag) {
        tag.each(function(index) {
            var chkNum = chk(index);
            var chkTxt = $(this).find('a').length;
            if (chkNum == 'odd') {
                $(this).css('background-color', '#cddec5');
                if (chkTxt != 0) {
                    $(this).addClass('odd');
                }
            } else if (chkNum == '0' || chkNum == 'even' && chkTxt == 1) {
                $(this).addClass('even');
            }
        })
    }

    doubleColor($('.eltDownload li'));
    doubleColor($('.downloadList li'));

    $('.productsImgs li').hover(function() {
        $(this).addClass('hover');
    }, function() {
        $(this).removeClass('hover');
    })

    var subMenuArrow = $('.product h6:eq(0)').text();
    $('.productMenu li').each(function() {
        var txt = $(this).find('a').text();
        if (subMenuArrow == txt) { $(this).addClass('on'); } else { $(this).removeClass('on'); }
    })


})


function chk(num){ 
  return num?num%2?"odd":"even":"0" ;
} 


