$(document).ready(function(){

    $('.toggle_note').live('click',function(){

        aParents = $(this).parents();
        var target = $(aParents[4]).find(".domena_rozwiniecie_2");
        
        if(target.css('display') == 'none')
        {
            target.html('<img class="ajax_loader" src="gfx/ajax-loader.gif" alt=""/>');
            target.slideToggle("slow");
	    $.post('ajax/getDomainNote.php', {
	        iId: $(this).attr('alt')
	    }, function(xml){
	        target.html(xml);
	    });
        }
        else
            target.slideToggle("slow");
    });

    $('.toggle_note_keyword').live('click',function(){

        aParents = $(this).parents();

        var target = $(aParents[4]).find(".domena_rozwiniecie_2");

        if(target.css('display') == 'none')
        {
            target.html('<img class="ajax_loader" src="gfx/ajax-loader.gif" alt=""/>');
            target.slideToggle("slow");
	    $.post('ajax/getKeywordNote.php', {
	        iId: $(this).attr('alt')
	    }, function(xml){
	        target.html(xml);
	    });
        }
        else
            target.slideToggle("slow");
    });

    $('.save_note').live('click',function(){
        var aParents = $(this).parents();
	    $.post('ajax/saveDomainNote.php', {
	        iIdDomain: $(this).attr('id'),
                sNote: $(aParents[2]).find('textarea').val()
	    }, function(xml){
                $.prompt(eval(xml)[1], {
                    top: '40%',
                    overlayspeed: 'fast',
                    promptspeed: 'fast'
                });
	    });
    });

    $('.save_note_keyword').live('click',function(){
        var aParents = $(this).parents();
	    $.post('ajax/saveKeywordNote.php', {
	        iIdKeyword: $(this).attr('id'),
                sNote: $(aParents[2]).find('textarea').val()
	    }, function(xml){
                $.prompt(eval(xml)[1], {
                    top: '40%',
                    overlayspeed: 'fast',
                    promptspeed: 'fast'
                });
	    });
    });

});
