
var blog = {

    init: function()
    {
        if ($('titleNews'))
        $('titleNews').getElements('ul > li a').each(function(elem)
        {
            if (!elem.get('class')) elem.addEvent('click', blog.loadTitleNews);
        });

        if ($('content').getElement('ul.tab32'))
        $('content').getElement('ul.tab32').getElements('li.users, li.topics, li.locations, li.albums, li.artists, li.languages').each(function(elem){
            elem.getElement('a').addEvent('click', blog.popupSelector);
        });

        if ($('content').getElement('li.blog > a'))  $('content').getElement('li.blog > a').addEvent('click', user.drawUnregInfo);

    },


    loadTitleNews: function(e)
    {
        e.stop();
        var elem = this;
        var id = $(this).get('href').replace('/news/','').replace(/\?.*$/i,'');
        if ($$('div.slide_shower').length) $$('div.slide_shower')[0].destroy();

        $('titleNewsPosts').set('load',
        {
            onComplete: function()
            {
                ymap.init();
                slideShow.init();
                elem.getParent().getParent().getElement('li.selected').set('class', '');
                elem.getParent().set('class', 'selected');
            }
        });
        $('titleNewsPosts').load('/ajax.php?do=getTitlePosts&id='+ id);
    },


    popupSelector: function(e)
    {
        e.stop();
        var li = this.getParent();
        var what = li.get('class').replace(' selected','');
        if (li.getNext().get('class') == 'gallery') what = 'photoUsers';

        win.init('popupSelector', '', 330);
        win.gotoThis('popupSelector', li, 'bottom');
        win.content('popupSelector').load('/ajax.php?do=popupSelector&what='+ what);
    }

}


var post = {

    preview: function()
    {
        var text = tinyMCE.get('editable-1').getContent();
        if (!$('preview')) new Element('div', {id: 'preview'}).inject($('postForm'), 'after');

        new Request.HTML({
            url: '/ajax.php?do=postPreview',
            update: $('preview')
        }).post({'text': text});
    },


    del: function(id, this_)
    {
        if (confirm('Точно удалить?'))
        new Request.JSON({
            url: '/ajax.php?do=deletePost',
            onComplete: function(response)
            {
                if (response) this_.getParent().getParent().set('style','text-decoration:line-through;');
            }
        }).post({'id': id});

    }

}
