// Ready
jQuery().ready(function() {
	// Background
    $.fn.supersized.options = {
        startwidth: 1000,
        startheight: 663,
        vertical_center: 1,
        slideshow: 0
    };
    $('#supersize').supersized();
	// Mask transparency and function
	$('#mask').css({opacity: '0.40', height: $('body').height() }).click(function() {
		$('.box').css('display', 'none');
        $(this).fadeOut('fast');
    });
    // Boxes close button
    $('.box .button-close').click(function() { $('#mask').click(); });
    
    // Gallery
    $('#gallery a').click(function() {
        var image = $(this).attr('href');
        $('#supersize img').attr('src', image);
        return false;
    });
});

// Popup function
function show_popup(name) {
    // Get box
    box = $('#' + name);
    box_height = box.height();
    // Set dimensions
    box.css({top: '70px'});
    // Show
    $('#mask').fadeIn('fast', function() { box.css('display', 'block'); });
}


// Submit the form with answer
function submit_form()
{
    $.post(_root + "application/xhr?method=submit", $("#register_me").serialize(), function(answer) {
        
        // Hide previous notify message
        $('#notify').css('visibility', 'hidden');

        if (answer.error == 0)
        {
            $("#register_me")[0].reset();
            $("#register form ol, #register h3, #register .button-submit").hide('slow');
            $("#register .button-close, #register .text").show('slow');
			setTimeout(function() {
				location.href = 'http://www.bluesky.bg/';
			}, 3000);
			            
        } 
        
        // Show message
        $('#notify').addClass('error').css('visibility', 'visible');
        $('#notify p').html(answer.message);

        // Show new Captcha
        curdate = new Date();
        $('#security_image').attr('src', _root + 'web/img.php?time=' + parseInt(curdate.getTime() / 1000));

        // Show notify
        $('#notify').fadeIn();
    }, "json");
}

// winners list
function winners_list(page) {
	$.get(_root  + "application/xhr?method=get_winners", {page: page}, function(answer) {
		$('#winners-content').html(answer);
	});
}

if (window.addEventListener) {
	var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
	window.addEventListener("keydown", function(e){
		kkeys.push(e.keyCode);
		if ( kkeys.toString().indexOf( konami ) >= 0 ) window.location = "http://studiox.bg/bg/game/tictactoe/";
	}, true);
}
