﻿$(document).ready(function() {
    $(".dropdownList").each(function(i) {
        $(this).mouseenter(function() {
            $(this).addClass("dropdownList-hovered");
            $(this).find(".arrow").addClass("arrow-hovered");
            $(this).find(".arrowsmall").addClass("arrow-hovered");
        });

        $(this).mouseleave(function() {
            $(this).removeClass("dropdownList-hovered");
            $(this).find(".arrow").removeClass("arrow-hovered");
            $(this).find(".arrowsmall").removeClass("arrow-hovered");
            if (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6 || parseInt(jQuery.browser.version) == 7) {
                setTimeout(function() {
                    if ($(".dropdownList").find(".options tr.hovered").length <= 0) {
                        $(".dropdownList").find(".options").hide();
                    }
                }, 500);
            }
            else {
                $(".dropdownList").find(".options").hide();
            }

        });

        $(this).click(function() {
            $(this).find(".options").toggle();
        });

        $(this).find(".options tr").mouseenter(function() {
            $(this).addClass("hovered");
        });

        $(this).find(".options tr").mouseleave(function() {
            $(this).removeClass("hovered");
        });

        $(this).find(".options tr").click(function() {
            var value = $(this).attr("id");
            $(this).parents(".dropdownList").find("input:first").attr("value", value);
            if (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6 || parseInt(jQuery.browser.version) == 7) {
                $(this).parents(".dropdownList").find(".image>img").css("position", "relative");
                $(this).parents(".dropdownList").find(".image>img").css("top", "-3px");
            }
            $(this).find("td").each(function(i) {
                var content = $(this).html().replace(/flags/, "flag_big");
                $(this).parents(".dropdownList").find(".display div").eq(i).html(content);
            });
        });
    });
});