(function ($) {
    var c = /:(nth)-last-child(?:\((even|odd|[\dn+-]*)\))?/,
        a = $.expr,
        b = a.filter.CHILD;
    a[":"]["nth-last-child"] = function (h, g, e, k) {
        var j = e[0].match(c),
            f = $(h.parentNode).children(),
            d;
        j = a.preFilter.CHILD(j);
        b(h, j);
        d = f.eq(f.length - h.nodeIndex)[0];
        return b(d, j)
    }
})(jQuery);
(function ($) {
    var cache = [];
    $.preLoadImages = function () {
        var args_len = arguments.length;
        for (var i = args_len; i--;) {
            var cacheImage = document.createElement('img');
            cacheImage.src = arguments[i];
            cache.push(cacheImage)
        }
    }
})(jQuery);
$(document).ready(function () {
    $('.MainNavDiv').load('/chunks/main_nav_dd', function () {
        $('.MainNavDiv ul:first').addClass('NAV MainNav');
        $('.MainNav ul').addClass('Drop');
        $('.MainNav li:nth-last-child(3) ul, .MainNav li:nth-last-child(2) ul, .MainNav li:last-child ul').addClass('DropRight');
        $('.Drop li:last-child').addClass('Last');
        $('.Drop li:first-child').before('<li class="Top"></li>');
        $('.MainNav').superfish({
            autoArrows: false,
            dropShadows: true
        })
    });
    $('.MainNavDiv ul ul li.active').parent().parent().children('a:first').addClass("Selected");
    $('.SecondNavDiv ul li.Selected ul.sidesub').show();
    $('.SecondNavDiv ul.sidesub li.Selected').parent().show();
	
    $('.GraphicSlideWrapper').scrollable({
        vertical: true,
        keyboard: 'static',
        circular: true
    }).navigator('.Slide_Nav');

    $('.facts').scrollable({
        keyboard: 'static',
        circular: true
    });

	$('#goToNextFact').click(function (e) {
		e.preventDefault();
		$('.facts').data('scrollable').next();
    });
	
    $('.media').bind('click', function (e) {
        e.preventDefault();
        $('#mediaContent').load('/chunks/media/' + $(this).attr('rel'), function () {
            $('.VideoDialog').dialog({
                dialogClass: 'Dialog_VideoDialog',
                height: '364',
                width: '762',
                modal: true,
                position: 'center'
            });
            $('#mediaClose').bind('click', function (e) {
                e.preventDefault();
                $('.VideoDialog').dialog('close');
                $('#mediaContent').empty()
            })
        })
    });
    $('#BTN_Registration, .reg').bind('click', function (e) {
        e.preventDefault();
        $('.RegistrationForm').dialog({
            dialogClass: 'Dialog_RegistrationForm',
            height: '480',
            width: '650',
            modal: true,
            position: 'center'
        });
        $('.BTN_Close').bind('click', function (e) {
            e.preventDefault();
            $('.RegistrationForm').dialog('close')
        })
    });
    $('#FRM_REG_Btn').bind('click', function () {
        $('#FRM_REG_Username').val($('#FRM_REG_Email').val());
        $('#FRM_REG_Email_Con').val($('#FRM_REG_Email').val());
        $('#FRM_REG').submit()
    });
    $('#transWin').dialog({
        height: '200',
        width: '300',
        modal: true,
        autoOpen: false
    })
});

function selectLang() {
    $("#transWin").dialog('open')
};
