﻿/// <reference path="../jquery/jquery-1.4.3.min.js" />
(function ($) {
    $.simpledropdown = function (selector) {
        $(selector).children("ul").addClass("dropdown");
        $("ul.dropdown>li:first-child").addClass("DDselected");
        $("ul.dropdown>li").not(".dropdown>li:first-child").addClass("drop");

        $(selector).find("ul.dropdown li.DDselected").click(function () {
            $(selector).find(".drop").slideToggle("fast", function () {
                var startWidth = $(selector).find("ul.dropdown").css("width");
                var tempWidth = parseInt(startWidth.substr(0, startWidth.length - 1));

                $(selector).find(".drop ul").css("width", "1000px");

                $(selector).find("ul.dropdown li.drop ul>li a").each(function () {
                    var thisWidth = $(this).css("width")

                    if (parseInt(thisWidth.substr(0, thisWidth.length - 1)) + 16 > tempWidth) {
                        tempWidth = parseInt(thisWidth.substr(0, thisWidth.length - 1)) + 16;
                    }
                });

                tempWidth = tempWidth < 292 ? tempWidth = 292 : tempWidth;
                $(selector).find(".drop ul").css("width", tempWidth.toString() + "px");
            });
        });
    };
})(jQuery);

(function ($) {
    $.simpledropdownPrep = function (selector) {
        $(selector).children("ul").addClass("dropdown");
        $("ul.dropdown>li:first-child").addClass("DDselected");
        $("ul.dropdown>li").not(".dropdown>li:first-child").addClass("drop");
    };
})(jQuery);

(function ($) {
    $.simpledropdownSP = function (selector, zindex) {
        $(selector).css("z-index",zindex);
        $(selector).css("position","absolute");
        $(selector).find(".dropdown").css("width","200px");
        $(selector).find(".dropdown").css("background","url(../images/dropdown_200.png) no-repeat 0px 0px transparent");

        $(selector).find("ul.dropdown li.DDselected").click(function () {
            $(selector).find(".drop").slideToggle("fast", function () {
                var startWidth = $(selector).find("ul.dropdown").css("width");
                var tempWidth = parseInt(startWidth.substr(0, startWidth.length - 1));

                $(selector).find(".drop ul").css("width", "1000px");

                $(selector).find("ul.dropdown li.drop ul>li a").each(function () {
                    var thisWidth = $(this).css("width")

                    if (parseInt(thisWidth.substr(0, thisWidth.length - 1)) + 16 > tempWidth) {
                        tempWidth = parseInt(thisWidth.substr(0, thisWidth.length - 1)) + 16;
                    }
                });

                $(selector).find(".drop ul").css("width", tempWidth.toString() + "px");
            });
        });
    };
})(jQuery);

(function ($) {
    $.simpledropdownSP129 = function (selector, zindex) {
        $(selector).css("z-index", zindex);
        $(selector).css("position", "absolute");
        $(selector).find(".dropdown").css("width", "129px");
        $(selector).find(".dropdown").css("background", "url(../images/dropdown_129.png) no-repeat 0px 0px transparent");

        $(selector).find("ul.dropdown li.DDselected").click(function () {
            $(selector).find(".drop").slideToggle("fast", function () {
                var startWidth = $(selector).find("ul.dropdown").css("width");
                var tempWidth = parseInt(startWidth.substr(0, startWidth.length - 1));

                $(selector).find(".drop ul").css("width", "1000px");

                $(selector).find("ul.dropdown li.drop ul>li a").each(function () {
                    var thisWidth = $(this).css("width")

                    if (parseInt(thisWidth.substr(0, thisWidth.length - 1)) + 16 > tempWidth) {
                        tempWidth = parseInt(thisWidth.substr(0, thisWidth.length - 1)) + 16;
                    }
                });

                $(selector).find(".drop ul").css("width", tempWidth.toString() + "px");
            });
        });
    };
})(jQuery);

function dropSelect(selection, value, selector) {
    var newWidth = $(selector).find(".dropdown").css("width");

    $(selector).find('ul.dropdown li.DDselected').text(selection);
    $(selector).find('ul.dropdown li.DDselected').attr("value", value);
    $(selector).find('ul.dropdown li.drop').slideToggle("fast");
}
