var KKV = window.KKV || {};

KKV.Mobile = {
    isSmartPhone: function() {
    if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.indexOf('Android') > -1) || (navigator.userAgent.match(/iPod/i))) {
            return true;
        }
        return false;
    },
    appendAnchor: function() {

        var hasOrIsAnchorOrAreExternal = function(href) {
            return href.indexOf('#') !== -1 || href.indexOf('http') !== -1;
        };

        var targetID = '#left_menu';

        $('a').each(function() {
            var href = $(this).attr('href');
            if (!hasOrIsAnchorOrAreExternal(href)) {
                $(this).attr('href', href + targetID);
            }
        });
    },
    insertAnchors: function() {
        var globalNavLink = $('<a></a>').text('Navigation').attr('href', '#main_menu').addClass('mobile-anchor').prependTo('#content_left');
        var topLink = $('<a></a>').text('Top').attr('href', '#').addClass('mobile-anchor').prependTo('#content_left');
    },
    removeElements: function() {
        var elements = ['#main_menu li:eq(0)', '#quick_menu li:eq(2)'];
        for (var i in elements) {
            $(elements[i]).remove();
        }
        $('#alternates_menu li').not(':last').remove();
    },
    init: function() {
        KKV.Mobile.removeElements();
        KKV.Mobile.appendAnchor();
        KKV.Mobile.insertAnchors();
    }
};

$(document).ready(function() {
    if (KKV.Mobile.isSmartPhone()) {
        KKV.Mobile.init();
    }
});
