$(document).ready(function() {
    $('#content').show();
    //if (!$.support.opacity) { $('#content').show(); }

    $('#main-menu li:eq(0)').fadeIn(500, function() {
        $('#main-menu li:gt(0)').each(function(i) {
            $(this).fadeIn().animate({ top: (i + 1) * 119 + 'px' }, 500, 'easeOutCirc', function() {
                //$('#content').fadeIn(500, function() { $(this).css('filter', ''); });
            });
        });
    });
    if (!(jQuery.browser.msie)) $('#main-menu li a').blend(500);

    var nextClick = function(e) {
        if (!$.support.opacity) {
            $(this).parents('.slide').hide().nextAll('.slide').eq(0).show();
        }
        else {
            $(this).parents('.slide').hide().nextAll('.slide').eq(0).fadeIn();
        }
        e.preventDefault();
    };

    var prevClick = function(e) {
        if (!$.support.opacity) {
            $(this).parents('.slide').hide().prevAll('.slide').eq(0).show();
        }
        else {
            $(this).parents('.slide').hide().prevAll('.slide').eq(0).fadeIn();
        }
        e.preventDefault();
    };

    $('.regprev').click(prevClick);
    $('.regnext').click(nextClick);

    $('form input, form select').blur(function() {
        var inputId = $(this).attr('id');
        var inputVal = $(this).val();
        $('.' + inputId).text(inputVal);
    });


    var openDialog = function(myTitle, mySource, tabNo) {
        $('body').append('<div id="popup"></div>');
        $('#popup').dialog({
            title: myTitle,
            modal: false,
            resizable: false,
            width: 600,
            height: 500,
            position: ['center', 'center'],
            open: function() {
                $("#popup").load(mySource, function() {
                    $('.scroll-pane').jScrollPane({ showArrows: false, scrollbarWidth: 10, arrowSize: 16 });
                    $('#tabs').tabs();
                    $('#tabs .ui-tabs-nav li:eq(' + tabNo + ')').find('a').trigger('click');
                });
            },
            close: function() {
                $('#popup').remove();
            }
        });
    }

    $('.btn_nyilatkozat').click(function(e) {
        e.preventDefault();
        openDialog("Felhasználási és adatvédelmi nyilatkozat", "html/nyilatkozat.html", 0);
    });

    $('.btn_szabalyzat').click(function(e) {
        e.preventDefault();
        openDialog("Verseny és Játék szabályzat", "html/szabalyzat.html", 0);
    });

    $('.btn_nyeremenyjatek_szabalyzat').click(function(e) {
        e.preventDefault();
        openDialog("Verseny és Játék szabályzat", "html/szabalyzat.html", 1);
    });

    $('.btn_impresszum').click(function(e) {
        e.preventDefault();
        openDialog("Kapcsolat", "html/impresszum.html", 0);
    });

    $('.btn_gyik').click(function(e) {
        e.preventDefault();
        openDialog("Gyakran Ismételt Kérdések (GYIK)", "html/gyik.html");
    });

    /* tooltip */
    $('.info').each(
    function() {
        var myString = $(this).parents('.inputunit').find('span').text();
        $(this).CreateBubblePopup({ position: 'top', align: 'center', width: 200, innerHtml: myString, innerHtmlStyle: { color: '#FFFFFF', 'text-align': 'center' }, themeName: 'all-black', themePath: 'images' });
    });
});
