// JavaScript Document
$(window).load(function(){
		//左侧产品菜单
$("#nav_all").show();
		// second simple accordion with special markup
                $("#nav_all > ul > li > ul > li > ul").show();
		$("#sidebar_product > li").addClass("h2_line");
		$("#nav_all > ul > li > ul:first").addClass("navigation");
		$("#nav_all > ul > li > a:first").hide();
		$("#nav_all > ul > li:eq(1)").hide();
		$("#nav_all > ul > li:eq(2)").hide();
		$("#nav_all > ul > li:eq(3)").hide();
		$("#nav_all > ul > li > ul > li").find("a:eq(0)").addClass("head")
				.wrapInner("<span></span>");
               $("#nav_all > ul > li > ul > li > ul li a").prepend("> ");
		var $nav_all_li = $("#nav_all > ul > li > ul > li")
		$nav_all_li.eq(0).addClass("honda");
		$nav_all_li.eq(1).addClass("suzuki");
		$nav_all_li.eq(2).addClass("kawasaki");
		$nav_all_li.eq(3).addClass("yamaha");
		$nav_all_li.eq(4).addClass("dukati");
		$(".navigation").accordion({
			autoheight: false,
			active: false,
			header: ".head",
			navigation: true,
			event: "mouseover",
			fillSpace: false,
			animated: "easeslide"
		});
		
       //文章
       $("#main_list li:even").addClass("singular");

			//首页滚动一次横向滚动一个
			$("#marquee1").kxbdSuperMarquee({
								isMarquee:true,
				isEqual:false,
				scrollDelay:10,
				direction:'left'
			});
			
		//产品统计
		function addTotal(){
		//计算总价格的函数
			var fTotal = 0;
		//对于选中了的复选项进行遍历
			//获取每一个的数量
		
		var iNum = parseInt($("input[name=txt_number]").val());
		//获取每一个的单价
		var fPrice = parseFloat($("input[name=hdn_price]").val());
		fTotal += iNum * fPrice;
		$("#prc").html(fTotal+"元");
		}
					$(function(){
							  $("input[name=txt_number]").change( function() {
								  //根据单价和数量计算价格
								addTotal();	//计算总价格
								});
							$("input[name=txt_number]")
							.attr({"disabled": false,
									"value":"1",	//表示份数的value值为1
									"maxlength":"5"	//最都只能输入2位数（不提供100份以上）
							}).change();			//触发change事件，让span都显示出价格

					});
		
		
		//会员
		$(".cart_table_padding tr:odd").addClass("hideall_odd");
		$(".hovery").hover(
		  function () {
			$(this).removeClass("hideall_odd");
			$(this).addClass("hideall_h");
		  },
		  function () {
			$(this).removeClass("hideall_h");
			$(".cart_table_padding tr:odd").addClass("hideall_odd");
		  }
		); 
		
		
		//客服在线
			$("#float_div_pic").fadeIn(500);
			$("#float_div_pic").hover(
			  function () {
				$(this).stop(true).animate({right: '0px'}, 500);
			
			  },
			  function () {
				$(this).stop(true).animate({right: '-154px'}, 500);
			  }
			);
});


//随屏幕移动的JS
var floatingMenuId = 'floatdiv';
var floatingMenu =
{
    targetX: -189,
    targetY: 182,

    hasInner: typeof(window.innerWidth) == 'number',
    hasElement: document.documentElement
        && document.documentElement.clientWidth,

    menu:
        document.getElementById
        ? document.getElementById(floatingMenuId)
        : document.all
          ? document.all[floatingMenuId]
          : document.layers[floatingMenuId]
};

floatingMenu.move = function ()
{
    if (document.layers)
    {
        floatingMenu.menu.left = floatingMenu.nextX;
        floatingMenu.menu.top = floatingMenu.nextY;
    }
    else
    {
        floatingMenu.menu.style.left = floatingMenu.nextX + 'px';
        floatingMenu.menu.style.top = floatingMenu.nextY + 'px';
    }
}

floatingMenu.computeShifts = function ()
{
    var de = document.documentElement;

    floatingMenu.shiftX =
        floatingMenu.hasInner
        ? pageXOffset
        : floatingMenu.hasElement
          ? de.scrollLeft
          : document.body.scrollLeft;
    if (floatingMenu.targetX < 0)
    {
        if (floatingMenu.hasElement && floatingMenu.hasInner)
        {
            // Handle Opera 8 problems
            floatingMenu.shiftX +=
                de.clientWidth > window.innerWidth
                ? window.innerWidth
                : de.clientWidth
        }
        else
        {
            floatingMenu.shiftX +=
                floatingMenu.hasElement
                ? de.clientWidth
                : floatingMenu.hasInner
                  ? window.innerWidth
                  : document.body.clientWidth;
        }
    }

    floatingMenu.shiftY =
        floatingMenu.hasInner
        ? pageYOffset
        : floatingMenu.hasElement
          ? de.scrollTop
          : document.body.scrollTop;
    if (floatingMenu.targetY < 0)
    {
        if (floatingMenu.hasElement && floatingMenu.hasInner)
        {
            // Handle Opera 8 problems
            floatingMenu.shiftY +=
                de.clientHeight > window.innerHeight
                ? window.innerHeight
                : de.clientHeight
        }
        else
        {
            floatingMenu.shiftY +=
                floatingMenu.hasElement
                ? document.documentElement.clientHeight
                : floatingMenu.hasInner
                  ? window.innerHeight
                  : document.body.clientHeight;
        }
    }
}

floatingMenu.doFloat = function()
{
    var stepX, stepY;

    floatingMenu.computeShifts();

    stepX = (floatingMenu.shiftX +
        floatingMenu.targetX - floatingMenu.nextX) * .07;
    if (Math.abs(stepX) < .5)
    {
        stepX = floatingMenu.shiftX +
            floatingMenu.targetX - floatingMenu.nextX;
    }

    stepY = (floatingMenu.shiftY +
        floatingMenu.targetY - floatingMenu.nextY) * .07;
    if (Math.abs(stepY) < .5)
    {
        stepY = floatingMenu.shiftY +
            floatingMenu.targetY - floatingMenu.nextY;
    }

    if (Math.abs(stepX) > 0 ||
        Math.abs(stepY) > 0)
    {
        floatingMenu.nextX += stepX;
        floatingMenu.nextY += stepY;
        floatingMenu.move();
    }

    setTimeout('floatingMenu.doFloat()', 20);
};

// addEvent designed by Aaron Moore
floatingMenu.addEvent = function(element, listener, handler)
{
    if(typeof element[listener] != 'function' ||
       typeof element[listener + '_num'] == 'undefined')
    {
        element[listener + '_num'] = 0;
        if (typeof element[listener] == 'function')
        {
            element[listener + 0] = element[listener];
            element[listener + '_num']++;
        }
        element[listener] = function(e)
        {
            var r = true;
            e = (e) ? e : window.event;

            for(var i = element[listener + '_num'] -1; i >= 0; i--)
            {
                if(element[listener + i](e) == false)
                    r = false;
            }
            return r;
        }
    }

    //if handler is not already stored, assign it
    for(var i = 0; i < element[listener + '_num']; i++)
        if(element[listener + i] == handler)
            return;
    element[listener + element[listener + '_num']] = handler;
    element[listener + '_num']++;
};

floatingMenu.init = function()
{
    floatingMenu.initSecondary();
    floatingMenu.doFloat();
};

// Some browsers init scrollbars only after
// full document load.
floatingMenu.initSecondary = function()
{
    floatingMenu.computeShifts();
    floatingMenu.nextX = floatingMenu.shiftX +
        floatingMenu.targetX;
    floatingMenu.nextY = floatingMenu.shiftY +
        floatingMenu.targetY;
    floatingMenu.move();
}

if (document.layers)
    floatingMenu.addEvent(window, 'onload', floatingMenu.init);
else
{
    floatingMenu.init();
    floatingMenu.addEvent(window, 'onload',
        floatingMenu.initSecondary);
}