﻿$(function()
{
    $("ul.menu li").each(function(i)
    {
        $(this).hover(function()
        {
            $("ul.menu li").removeClass("h");
            $(this).addClass("h");
            $("#m" + i).show();
            $("#m" + i).css({ "left": $(this).offset().left - 1, "top": $(this).offset().top + 36 });
        }, function()
        {
            //$(this).removeClass("h");
            checkArea("#m" + i, event);
        });
    });

    $(".submenu").each(function(i)
    {
        $(this).hover(function() { }, function()
        {
            $(this).hide();
        });
    });

    //设置广告图片
    var _id = window.location.search.replace("?id=", "");

    if (window.location.href.indexOf("tyre.aspx") > 0 || window.location.href.indexOf("grain.aspx") > 0)
    {
        _id = "13";
    }
    switch (_id)
    {
        case "7":
        case "8":
        case "9":
        case "10":
            //走进浪马
            $("#ad").css("background", "url(../images/zjlm.gif)");
            break;
        case "11":
        case "12":
            //行业信息
            $("#ad").css("background", "url(../images/hyxx.gif)");
            break;
        case "13":
        case "14":
        case "15":
        case "16":
        case "17":
        case "18":
        case "19":
            //产品展示
            $("#ad").css("background", "url(../images/cpzs.gif)");
            break;
        case "20":
            //无内胎区
            $("#ad").css("background", "url(../images/wntq.gif)");
            break;
        case "21":
        case "22":
        case "23":
        case "24":
            //营销服务
            $("#ad").css("background", "url(../images/yxfw.gif)");
            break;
        case "25":
            //联系我们
            $("#ad").css("background", "url(../images/lxwm.gif)");
            break;
        default:
            $("#ad").css("background", "url(../images/ad.gif)");
            break;
    }

    //获取下拉列表框
    $.ajax({
        type: "get",
        url: "ashx/service.ashx?t=3",

        success: function(result)
        {
            $("#ddlgg").html($("#ddlgg").html() + result);
        }
    });
    $.ajax({
        type: "get",
        url: "ashx/service.ashx?t=4",
        success: function(result)
        {
            $("#ddlhw").html($("#ddlhw").html() + result);
        }
    });
});

function search()
{
    var t = "tyre.aspx";
    if ($("#ddlgg").find("option:selected").text() != "规格")
    {
        t += "?gg=" + $("#ddlgg").find("option:selected").text();
    }
    else
    {
        t += "?p=1";
    }
    if ($("#ddlhw").find("option:selected").text() != "花纹")
    {
        t += "&hw=" + $("#ddlhw").find("option:selected").text();
    }
    window.location.href = t;
}

function checkArea(id,event)
{
    //如果鼠标不在子菜单区，则隐藏子菜单。
    if (event.clientX < $(id).offset().left)
    {
        $(id).hide();
        return;
    }
    if (event.clientX > $(id).offset().left+$(id).width())
    {
        $(id).hide();
        return;
    }
    
    var scrollTop=0;
    if (document.documentElement && document.documentElement.scrollTop)
    {
        scrollTop = document.documentElement.scrollTop;
    }
    else if (document.body)
    {
        scrollTop = document.body.scrollTop;
    }
    if ((event.clientY + scrollTop) < $(id).offset().top - 36)
    {
        
        $(id).hide();
        return;
    }

}


