/* Responsive Design Addition: Create Navigation with Combo Box for iPhone etc. */

jQuery(window).resize(function() {
    CreateComboMenu();
});

function AddComboMenu(){
    // create hierarchical combo box from menu
    var combo = '<select id="comboMenu" width="100%" style="width:100%; padding: 10px;">';

    combo += '<option value="http://www.urban-e.com">Startseite</option>';

    jQuery("#menu-main-menu > li > a ").each(function(item,index) {

        var href = jQuery(this).attr('href');

        if (typeof href !== 'undefined' && href !== false)
        {
            var currentUrl = document.location.href.toString();
            var selected = currentUrl == href.toString() ? ' selected="selected"' : '';

            combo += '<option value="' + href + '"' + selected + '>' + jQuery(this).text() + '</option>';
        }
        else
        {
            combo += '<option value="">' + jQuery(this).text() + '</option>';
        }

        jQuery(this).parent().find("ul li > a").each(function(item,index) {
            var url = jQuery(this).attr('href');

            var currentUrl = document.location.href.toString();
            var selected = currentUrl == url ? ' selected="selected"' : '';

            var label = "&nbsp;&nbsp;&nbsp;&nbsp;" + jQuery(this).text();

            combo += '<option value="' + url + '"' + selected + '>' + label + '</option>';
        });
    });

    combo += '</select>';

    jQuery(".menu-header").append(combo);
    jQuery("#comboMenu").css('visibility', 'visible');
    jQuery("#comboMenu").change(function() {
        var url = jQuery("#comboMenu").val();
        if (url != "")
            document.location.href = jQuery("#comboMenu").val();
    });
}

function CreateComboMenu() {
    if (jQuery("#comboMenu").length == 0) AddComboMenu();

    if (jQuery("#comboMenu").css('display') == 'block')
        jQuery("#menu-main-menu").hide();
    else
        jQuery("#menu-main-menu").show();
}
