var hideMessages = function hideMessage() {
    $(".message").hide("slow");
    return false;
}
// wyświetlaniemessages
var showMessageFunction = function() {
	if($(".message")) {
		$(".message").hide();
		$(".message").show("slow");
	}
}
$(document).ready(showMessageFunction);

var bannerRedirectUrl = '';
$(document).ready(function() {
    $("a.chowajMsg").click(hideMessages);

    $('.banner_click').click(function()
    {
        var u = $(this).attr('id');
        u = u.replace(/_/g, '/');
        bannerRedirectUrl = $(this).attr('href');
        $.ajax({
            url: '/banners/click/'+u+'/',
            success:function(data)
            {
                if(data)
                {
                    document.location.href = data;
                }
                else
                {
                    document.location.href = bannerRedirectUrl;
                }
            }
        });
        return false;
    });

    $('.closePopup').live('click', function()
    {
        $('#popup').fadeOut();
        $('#popupErrorMsg').fadeOut();
        $('#popupGoodMsg').fadeOut();
        return false;
    });

    $('.needPass').click(function() {
        var link = $(this).attr('href');
        $.ajax({
            url:  '/index/isDownloadPassSaved/',
            success: function(msg){
                if (msg == 'true') {
                    window.location = link;
                } else {
                    var popup = $('#popup');
                    if(popup.length < 1) {
                        return;
                    } else {
                        if(popup.css('display') == "none") {
                            popup.fadeIn();
                            $('#popupControlls').fadeIn();
                        }
                    }
                }
            }
        });
        return false;
    });

    $('#passSend').click(function() {
        $.ajax({
            type: "POST",
            url:  '/index/checkDownloadPass/',
            data: "file_pass=" + $('#file_pass').val(),
            success: function(msg) {
                if (msg == 'true') {
                    $('#popupControlls').fadeOut();
                    $('#popupGoodMsg').fadeIn();
                    setTimeout('location = "/index/download/"',1000)
                } else {
                    $('#popupErrorMsg').fadeIn();
                }
            }
        });
        return false;
    });
});



