﻿$.fn.SimulateSelect = function (data, f)
{
    var obj = $(this);
    var container = $("body").append("<div id='js_dropdown'><ul></ul></div>");
    var width = obj.width() - 33;
    var top = obj.offset().top + 21;
    var left = obj.offset().left + 1;
    var list = $("#js_dropdown");
    list.css({ "width": width, "top": top, "left": left });

    obj.click(function (eb)
    {
        list.show();
        try { eb.stopPropagation(); } catch (e) { event.cancelBubble = true; }
    });

    $.each(data.value, function (o, ov)
    {
        $("<li/>").html(ov).attr('v', ov).click(function (eb)
        {
            obj.val($(this).attr("v"));
            list.hide();

            try { eb.stopPropagation(); } catch (e) { event.cancelBubble = true; }
            switch (o)
            {
                case "1":
                    window.location.href = "result.aspx?n=main";
                    break;
                case "2":
                    window.location.href = "innertyre.aspx";
                    break;
                case "3":
                    window.location.href = "wheel.aspx";
                    break;
                case "4":
                    window.location.href = "other.aspx";
                    break;
            }
        }).hover(function ()
        {
            //floatred为hover的样式
            $('#js_dropdown').find('li[class=floatred]').removeClass('floatred');
            $(this).addClass('floatred');
        }, function ()
        {
            $(this).removeClass('floatred');
        }).appendTo($('#js_dropdown ul'));
    });

    $(document).click(function () { list.hide(); }); //点击位置隐藏

}





/*
*
*
*/
$.fn.SimulateSelect1 = function (data, f)
{
    var inOb = $(this);
    var currentid = $(this).attr("id");
    var id = 'divSelect' + currentid;
    var width = $(this).width();
    //$(this).hide();
    $(this).parent().append('<div id="a_' + id + '"></div>' + '<div id="b_' + id + '"></div>');
    $('#a_' + id).addClass("dropselectbox dropdown").css({
        'width': width - 22
    }).html('').html($(this).val());
    $('#a_' + id).click(function (eb)
    {
        $('#b_' + id).show();
        try
        {
            eb.stopPropagation();
        }
        catch (e)
        {
            event.cancelBubble = true;
        }
    });
    var changeleft = false;
    // 这里只针对IE8,其他浏览器无此问题
    if ($.browser.msie)
        changeleft = ($.browser.version) >= 8;
    if (changeleft)
    {
        $('#b_' + id).addClass("ullist").css({
            'width': width - 16,
            'top': $('#a_' + id).offset().top + 22
        }).hide();
    } else
    {
        $('#b_' + id).addClass("ullist").css({
            'width': width - 16,
            'top': $('#a_' + id).offset().top + 22,
            'left': $('#a_' + id).offset().left
        }).hide();
    }
    $('<ul style="margin:0;"></ul>').appendTo($('#b_' + id));
    var _count = 0;
    $.each(data.value, function (o, ov)
    {
        _count++;
        $("<li/>").html(ov).attr('v', ov).click(function (eb)
        {
            $(inOb).val($(this).attr('v'));
            $('#a_' + id).html('').html($(this).html());
            $("#" + currentid).val($(this).html());
            $('#b_' + id).hide()
            if (f)
                f($(this).attr('v'), $(this).html());
            try
            {
                eb.stopPropagation();
            }
            catch (e)
            {
                event.cancelBubble = true;
            }
        }).hover(function ()
        {
            $('#b_' + id).find('li[class=floatred]').removeClass('floatred');
            $(this).addClass('floatred');
            $('#b_' + id).find('li').removeClass("over");
            $(this).addClass("over").addClass("selectedli");
        }, function ()
        {
            $(this).removeClass('floatred');
            $(this).removeClass("over");
        }).appendTo($('#b_' + id + ' ul'));
    });
    // 绑定初始值
    if (data.select != "")
    {
        $('#a_' + id).html('').html(data.select);
        $("#" + currentid).val(data.select);
    }
    if (_count > 8)
    {
        $('#b_' + id).find("ul").css("height", "150px");
    }
    var liobj = $('#b_' + id).find('li[v=' + inOb.val() + ']');
    if (liobj.html())
    {
        liobj.addClass('floatred');
        $('#a_' + id).html(liobj.html());
    }
    else
    {
        inOb.val('');
    }
    $(document).click(function ()
    {
        $("#b_" + id).hide();
    });
};

