$(document).ready(function() {

    $(function() {
	    $('#slides').superslides({
		    hashchange: false,
		    animation: "fade",
		    pagination: false,
		    play: 5000
	    });
	});

});


function getLanguageWidth() {
    var dropDown = $('.dropdown.dropdown-language').find('.dropdown-menu'),
        len = dropDown.length;

    if (len > 0) {
        var parseDrop = function () {

            var obj = $(this),
                linkWidth = obj.find('a'),
                maxWidth = Math.max.apply(null, linkWidth.map(function () {
                    return $(this).outerWidth(true);
                }).get());

            obj.css('min-width', maxWidth);
            dropDown.parent('.dropdown.dropdown-language').find('.dropdown-toggle').css('width', maxWidth);
        };

        dropDown.each(parseDrop);
    }
}

function onHover() {
    var $soonDropdown = $('.main-wrapper').find('.dropdown'),
        FF = !(window.mozInnerScreenX == null);

    var outClass = function () {
        $(this).removeClass('fastdelay');
    };

    var putClass = function () {
        $(this).addClass('fastdelay');
    };

    if ($soonDropdown.length > 0) {
        $soonDropdown.hover(putClass, outClass);

        if (FF) {
            $soonDropdown.hover(outClass, putClass);
        }
    }
}

var collectAll = function () {
    onHover();
    getLanguageWidth();
};

$(window).on("load", onHover);
$(document).ready(getLanguageWidth);
$(window).on('resize', collectAll);