﻿// ------ CUSTOM DROP DOWN SCRIPT ------ WAUSTIN[08/2010]

// ------ "select"s with the class "custom-dd" will have all of it's contents
// ------ cloned and appended to a un-ordered list with links, where the 
// ------ "value" attribute of each "option" tag is the "a" tag's "href" 
// ------ text in the "option" tag is placed in the text for the "a" tag

function manipulateDropDown(element) {
    var options = new Array();
    options.count = $(element).children().length;
    var newDropDownList = "<ul class='custom-dropdown'>";
    $(element).children('option').each(function() {
        options.value = $(this).val();
        options.text = $(this).text();
        if(options.value == "0") {
            return;
        } else {
            newDropDownList += "<li><a href='"+options.value+"'>"+options.text+"</a></li>";
        }
    });
    newDropDownList += "</ul>";
    $(element).css('display','none');
    $(element).parent('div').append(newDropDownList);
}

$(document).ready(function() {
    var fadeTimeout;
    $('.custom-dd').each(function() {
        manipulateDropDown($(this));
    });
    $('ul.custom-dropdown').mouseout(function() {
        fadeTimeout = setTimeout("$('ul.custom-dropdown').fadeOut(500)", 1000);
    }).mouseover(function() {
        clearTimeout(fadeTimeout);
    });
});
