$j().ready(function () {
});

/**
* Inicjuje galerie dla zdjecia dolaczonego do ogloszenia (LightBox)
*/
$j(function(){
	$j('li.announcement-item dd.a-desc a').each(function(){
        $j(this).lightBox({
        	overlayBgColor: '#000',
        	overlayOpacity: 0.6,
        	imageLoading: 'frontend/img/lightbox/loading.gif',
        	imageBtnClose: 'frontend/img/lightbox/close.gif',
        	containerResizeSpeed: 350
        });
    });
});

/**
* Odswieza obrazek captcha
*/
$j(function(){
    $j('img#captcha-refresh').click(function(){
        $j('img#captcha-img').attr('src', 'image/captcha?token=' + new Date().getTime());
    });
});

/**
* Usuwa ogloszenie (AJAX)
*/
$j(function(){
    $j('a.announcement-remove').click(function(event){
        event.preventDefault();
        var li = $j(this).parents('li');
        var announcement_id = li.attr('id').substr(13);

        if (confirm('Czy na pewno usunąć ogłoszenie?'))
        {
            $j.ajax({
                type: 'GET',
                url: cp + '/announcement/x_remove_announcement/' + announcement_id,
                data: {},
                dataType: 'json',
                async: true,
                success: function(data){
                    if (data.success)
                    {
                        li.fadeOut(function(){
                            li.remove();
                        });
                    }
                    else
                    {
                        alert(data.message);
                    }
                },
                error: function() {
                    alert('Błąd!');
                }
            });
        }
    });
});
