/*
window.onerror = function() {
	return true;
}
*/

var cat_id = 1;

/** messages funcs */
var cur_id = 'mf';
function dropMsg(el) {
    $.ajax({
        type: 'POST',
        url: el.attr('href'),
        data: 'is_ajax=1&type=' + el.attr('rel'),
        success: function(msg) {
            if (msg == 'ok') {
                dropMsgAnimate(el);
            }
        }
    });
}
function readItems(cb) {
    $.each(cb, function(i, val) {
        $.ajax({
            type: 'POST',
            url: '/messages/in/' + val.value + '.html',
            data: 'is_ajax=1',
            success: function(msg) {
                if (msg == 'ok') {
                    $('#item_' + val.value).parent().removeClass('no-read');
                    cb.attr('checked', false);                }
            }
        });
    });
}
function dropItems(cb, type) {
    $.each(cb, function(i, val) {
        $.ajax({
            type: 'POST',
            url: '/messages/drop/' + val.value + '.html?type=' + type,
            data: 'is_ajax=1&type=' + type,
            success: function(msg) {
                if (msg == 'ok') {
                    dropMsgAnimateById('item_' + val.value);
                }
            }
        });
    });
}
function dropMsgAnimateById(id) {
    $('#' + id).addClass('drop');
    $('#' + id).stop().animate({
        opacity: 1,
        backgroundColor: '#ffffff'
    }, 3500);
}
function dropMsgAnimate(el) {
    var elem = el.parent().parent().parent().parent().parent().parent().parent();
    elem.addClass('drop');
    elem.stop().animate({
        opacity: 1,
        backgroundColor: '#ffffff'
    }, 3500);
}
function loadData(href) {
    var msg = '';
    
    $.get(href, { ajax: true }, function(response) {
        if (response != 'no_login') {
            var data = eval("(" + response + ")");
            if (data.body) {
                $('.f-mes-text').html(data.body);
                if (data.type == 'in') {
                    $('#from_id').val(data.to_id);
                    $('#to_id').val(data.from_id);
                    $('#ok a').attr('href', $('#catpath').val() + data.from_id + '.html');
                    $('.img-mes').parent().attr('href', $('#catpath').val() + data.from_id + '.html');
                    $('.inf-text a').attr('href', $('#catpath').val() + data.from_id + '.html');
                    $('.history').attr('href', $('#msgpath').val() + 'history/' + data.from_id + '.html');
                }
                else {
                    $('#from_id').val(data.from_id);
                    $('#to_id').val(data.to_id);
                    $('#ok a').attr('href', $('#catpath').val() + data.to_id + '.html');
                    $('.img-mes').parent().attr('href', $('#catpath').val() + data.to_id + '.html');
                    $('.inf-text a').attr('href', $('#catpath').val() + data.to_id + '.html');
                    $('.history').attr('href', $('#msgpath').val() + 'history/' + data.to_id + '.html');
                }
		var t = ( data.surname ? data.surname + " " : "" ) + data.name;
		if ( t.length > 30 ) t = t.substr( 0, 30 ) + "\u2026";
                $('.inf-text a').html( t );
                $('#ok a').html(data.name);
                if (data.img_arr.small) {
                    $('.img-mes').attr('src', data.img_arr.mini.src).attr('width', data.img_arr.mini.width).attr('height', data.img_arr.mini.height);
                }
            }
            if (data.block) {
                var cur_id = 'block';
                msg = data.reason;
            }
        }

        if (!data || !data.block) {
            var cur_id = (response == 'no_login') ? 'no_login' : 'mf';
        }

        showMsg(cur_id, msg);
        showDisable();
        
        $('#mf .bord-l').css({
            height: $('#mf .form-box').height() + 80 + 'px'
        });
        
        setPos(false, 'slow');
    });
}

function showCreateTopicForm() {
    showMsg('mf', '');
    showDisable();
}

function sendSpam(link) {
    $.ajax({
        type: 'POST',
        url: link.attr('href'),
        data: '',
        success: function(msg) {
            if (msg == 'ok') {
                showDisable();
                showMsg('spam');
                dropMsgAnimate(link);
            }
            else {
                showDisable();
                showMsg('error');
            }
        }
    });
}
function sendMsg() {
    $.ajax({
        type: 'POST',
        url: $('#mf').attr('action'),
        data: 'action=ajaxSaveMessage&from_id=' + $('#mf #from_id').val() + '&to_id=' + $('#mf #to_id').val() + '&body=' + $('#body',$('#mf')).val(),
        success: function(msg) {
            if (msg == 'ok') {
                $('#mf textarea.inp-text').val('');
                $('#mf input.enter').addClass('dis');
                $('#mf input.enter').attr('disabled', 'disabled');
                closeMsg();
                showMsg('ok');
            }
            else if (msg == 'error') {
                closeMsg();
                showMsg('error');
            }
            else {
                closeMsg();
                showMsg('block', msg);
            }
        }
    });
}
function sendForumTopic(){
    $.ajax({
        type: 'POST',
        url: $('#mf').attr('action'),
        data: 'action=ajaxSaveTopic&cat_id=' + $('#mf #cat_id').val() + '&head=' + $('#mf #head').val() + '&body=' + $('#mf #bb_body').val(),
        success: function(msg){
            if (msg > 0) {
                location.href = $('#mf').attr('action') + $('#mf #cat_id').val() + '/' + msg + '/';
            }
            else {
                closeMsg();
                showMsg(msg);
            }
        }
    });
}
function showMsg(id, msg) {
    if (!id) id = 'mf';
    cur_id = id;
    setPos(false, '', id);
    $(window).scroll(function() {
        setPos(true, 'slow', id);
    });
    $(window).resize(function() {
        setPos(true, 'slow', id);
        //showDisable();
    });
    if (msg) {
        $('#' + id + ' #msg').html(msg);
    }

    $('#' + id + ' .bord-l').height($('#' + id).height());
    $('#' + id).fadeIn('fast').find('textarea').val('');
    if ($('#' + id + ' input[type=text]:first').length)
        $('#' + id + ' input[type=text]:first').focus();
    else
        $('#' + id + ' textarea').focus();

/*    
    $('#' + id + ' .bord-l').height($('#' + id).height());
    $('#' + id).fadeIn('fast').find('textarea').focus().val('');
*/    
    if (id != 'mf' && id != 'block') {
        var timer = setTimeout(
            function() {
                closeMsg(1000);
                hideDisable(1000);
            },
            2000
        );
    }
}

function closeMsg(speed, esc) {
    if (!esc)
        showDisable();
    if ($('#' + cur_id).hasClass('relative')) {
        return false;
    }
    if (!speed) speed = 'fast';
    $('#' + cur_id).fadeOut(speed);
}

function showDisable() {
  $('.disable').css({
        position: 'absolute',
        left: '0',
        top: '0',
        zIndex: 1,
        backgroundColor: '#ffffff'
    });

    $('.disable').fadeTo('fast', 0.5);
    $('.disable').width($('body').width());
    $('.disable').height($('body').height());
}
function hideDisable(speed) {
    if (!speed) speed = 'fast';
    $('.disable').fadeOut(speed);
}
function setPos(anim, speed, id) {
    if (!id) id = 'mf';

    var x = 0;
    var y = 0;
    x = (($(window).width() - $('#' + id).width()) >> 1) + $('html').scrollLeft();
    y = (($(window).height() - $('#' + id).height()) >> 1) + $('html').scrollTop();

    if (anim) {
        $('#' + id).stop().animate({
	    opacity: 1,
            left: x + 'px',
            top: y + 'px'
        }, speed);
    }
    else {
        $('#' + id).css({
            left: x + 'px',
            top: y + 'px'
        });
    }
}
/** end messages funcs */

$(document).ready(function(){
    /** messages */
    $('html').keypress(function(e) {
        if (e.keyCode == 27) {
            closeMsg('', true);
            hideDisable();
        }
    });
    $('.sendmsg, .showmsgform').click(function() {
        $(this).blur();
        loadData($(this).attr('href'));
        return false;
    });
    $('.show_topic_form').click(function() {
        showCreateTopicForm();
        return false;
    });
    $('.close').click(function() {
        $(this).blur();
        closeMsg();
        hideDisable();
        return false;
    });
    $('#mf .enter').not('.forum').click(function(){
        sendMsg();
        return false;
    });
    $('#mf .enter.forum').not('#preview_button').click(function(){
        sendForumTopic();
        return false;
    });
    $('.dropbtn').click(function() {
        if (!confirm('Удалить сообщение?')) return false;
        dropMsg($(this));
        return false;
    });
    $('.showspam').click(function() {
        if (!confirm('Сообщить администратору об этом сообщении?')) return false;
        sendSpam($(this));
        return false;
    });
    $('.links .del').click(function() {
        if ($('.checkdrop:checked').length > 0) {
            if (!confirm('Удалить выбранные сообщения?')) return false;
        }
        else {
            alert('Не выбрано ни одного сообщения?'); return false;
        }
        dropItems($('.checkdrop:checked'), $(this).attr('rel'));
        
        return false;
    });
    $('.links .read').click(function() {
        if ($('.checkdrop:checked').length > 0) {
            if (!confirm('Пометить выбранные сообщения как прочитанные?')) return false;
        }
        else {
            alert('Не выбрано ни одного сообщения?'); return false;
        }
        readItems($('.checkdrop:checked'));
        
        return false;
    });

    var t = $('#body, #bb_body', $('#mf'));
    t.keyup(
     function(e) {
        if ($(this).val()) {
            $('#mf input.enter').removeClass('dis');
            $('#mf input.enter').attr('disabled', false);
        }
        else {
            $('#mf input.enter').addClass('dis');
            $('#mf input.enter').attr('disabled', 'disabled');
        }
    });
    t.keyup();
    $('.checkdrop_all').click(function() {
        $('.checkdrop').attr('checked', $(this).attr('checked'));
        if ($('.checkdrop:checked').length > 0) {
            $('.links').show();
        }
        else {
            $('.links').hide();
        }
    });
    $('.checkdrop').click(function() {
        if ($('.checkdrop:checked').length > 0) {
            $('.links').show();
        }
        else {
            $('.links').hide();
        }
    });
    
    $('.hideread').click(function() {
        $('#' + $(this).attr('rel')).parent().removeClass('no-read');
    });
    /** end messages */

    $(".search-form input[type='checkbox']").custCheckBox();
	//.showTitle();
    $("div.lm-razdel").css( { 'cursor': 'pointer' } );
    $("div.lm-razdel").click(
        function() {
            if ($(this).hasClass("lm-active")) return false;
            
            var index = $("div.lm-razdel").index(this) + 1;

            $("div.lm-razdel").removeClass("lm-active");
            $(this).addClass("lm-active");
            $(this).find("a").blur();
            
            $("ul.lm-submenu").hide();
            $("ul#sm" + index).show();
            
            return false;
        }
    );

    $("div#rules a").toggle(
        function() {
            this.blur();
            $("div#rules dl").css({
                "display": "block"
            });
            return false;
        },
        function() {
            this.blur();
            $("div#rules dl").css({
                "display": "none"
            });
            return false;
        }
    );

/*    
    $("div.plash a").click(function() {
        $(this).blur();

        $('div.plash span').removeClass('active');
        $(this).parent().parent().addClass('active');
        var id = $(this).attr('rel');

        if ($('#' + id).length) {
            $('div.ajaxbox').hide();
            $('#' + id).show();
        }
        else {
            $('#body-cont').append('<div class="ajaxbox" id="' + id + '"></div>');
            $('#' + id).load(
                this.href,
                { 'action': 'showForm' },
                function () {
                    prepare();
                    $('div.ajaxbox').hide();
                    $('#' + id).show();                   
                }
            );
        }
        return false;
    });
    
    $("ul.plashes a").click(function() {
        $(this).blur();

        $('ul.plashes li').removeClass('active');
        $(this).parent().addClass('active');
        var id = $(this).attr('rel');
        
        if ($('#' + id).length) {
            $('div.ajaxbox').hide();
            $('#' + id).show();
        }
        else {
            $('#form-cont').append('<div class="ajaxbox" id="' + id + '"></div>');
            $('#' + id).load(
                this.href,
                { 'action': 'showForm' },
                function () {
                    prepare();
                    $('div.ajaxbox').hide();
                    $('#' + id).show();
                }
            );
        }
        return false;
    });
    /**/

    $("a.addfav").click(function() {
        $(this).blur();

        $.getJSON(
            this.href,
            { ajax: '1' },
            function(data) {
                var text = (data.type == 'add') ? 'Удалить из избранных' : 'Добавить в избранное';
                $("span", "a.addfav").html(text);
                $("#box").load(
                    '/?action=showTemplate&template=blocks/right_box.tpl'
                );
            }
        );
        
        return false;
    });

    $("a.addsubs").click(function() {
        $(this).blur();

        $.getJSON(
            this.href,
            { ajax: '1' },
            function(data) {
                var text = (data.type == 'add') ? 'Убрать подписку на новости' : 'Подписаться на новости';
                $("span", "a.addsubs").html(text);
            }
        );
        
        return false;
    });

    $("a.recomm").click(function() {
        $(this).blur();

        $.getJSON(
            this.href,
            { ajax: '1' },
            function(data) {
                var text = (data.type == 'add') ? 'Убрать рекомендацию' : 'Я рекомендую';
                $("span", "a.recomm").html(text);
            }
        );
        
        return false;
    });
        
    var t = function(e) {
        if (!$('#filter-cat').length) return false;
	var hash;
        if ( e ) {
	        if (e.value == '/') return false;
        	hash = e.value;
	}
	else {
		hash = "" + window.location;
		if ( !hash ) return false;
		var t = hash.indexOf( "?" );
		if ( t < 0 ) return false;

		hash = hash.substring( hash.indexOf( "?" ) - 1 );
	}

	var name = getVariable('name', hash);
	if ( name && !/^(?:%[0-9A-Z]{2}|\+)+$/i.test( name ) ) {
            $('#filter-cat #name').attr('value', unescape( name ) );
	}

        if (getVariable('city_id', hash))
            $('#filter-cat #city_id option[value=' + getVariable('city_id', hash) + ']').attr('selected', 'selected');
        if (getVariable('cat_id', hash))
            $('#filter-cat #cat_id option[value=' + getVariable('cat_id', hash) + ']').attr('selected', 'selected');
        if (getVariable('summ1', hash))
            $('#filter-cat #summ1').attr('value', getVariable('summ1', hash));
        if (getVariable('summ2', hash))
            $('#filter-cat #summ2').attr('value', getVariable('summ2', hash));
        if (getVariable('is_photo', hash) == 1) {
            $('#filter-cat #is_photo').attr('checked', true);
            $('#filter-cat #is_photo').parent().find('span.cust_checkbox').removeClass('cust_checkbox_off').addClass('cust_checkbox_on');
        }
        if (getVariable('is_video', hash) == 1) {
            $('#filter-cat #is_video').attr('checked', true);
            $('#filter-cat #is_video').parent().find('span.cust_checkbox').removeClass('cust_checkbox_off').addClass('cust_checkbox_on');
        }
        if (getVariable('is_audio', hash) == 1) {
            $('#filter-cat #is_audio').attr('checked', true);
            $('#filter-cat #is_audio').parent().find('span.cust_checkbox').removeClass('cust_checkbox_off').addClass('cust_checkbox_on');
        }

        if (getVariable('is_feedbacks', hash) == 1) {
            $('#filter-cat #is_feedbacks').attr('checked', true);
            $('#filter-cat #is_feedbacks').parent().find('span.cust_checkbox').removeClass('cust_checkbox_off').addClass('cust_checkbox_on');
        }
        if (getVariable('is_blog', hash) == 1) {
            $('#filter-cat #is_blog').attr('checked', true);
            $('#filter-cat #is_blog').parent().find('span.cust_checkbox').removeClass('cust_checkbox_off').addClass('cust_checkbox_on');
        }
        if (getVariable('is_scheduler', hash) == 1) {
            $('#filter-cat #is_scheduler').attr('checked', true);
            $('#filter-cat #is_scheduler').parent().find('span.cust_checkbox').removeClass('cust_checkbox_off').addClass('cust_checkbox_on');
        }
        if (getVariable('is_online', hash) == 1) {
            $('#filter-cat #is_online').attr('checked', true);
            $('#filter-cat #is_online').parent().find('span.cust_checkbox').removeClass('cust_checkbox_off').addClass('cust_checkbox_on');
        }

        getAjaxList(getVariable('page', hash), true);
    };

    t();

    $.address.change(t);

    chessTable();
    prepare();
    catalogFilter();
});

function getVariable(val, hash) {
    if (!hash.split(val + '=')) return '';
    if (!hash.split(val + '=')[1]) return '';
    if (!hash.split(val + '=')[1].split('&')) return '';
    if (!hash.split(val + '=')[1].split('&')[0]) return '';
    return hash.split(val + '=')[1].split('&')[0];
}

function clearFavs(link){
    if (!confirm('Очистить список избранных артистов?')) 
        return false;
    
    $.post(link.href, {
        ajax: '1'
    }, function(data){
        $("#box").load('/?action=showTemplate&template=blocks/right_box.tpl');
    });
    
    return false;
}

function addCategory() {
    for (var i = 1; i <= 3; i++) {
        if (!$('#cat' + i + ':visible').length) {
            break;
        }
        cat_id = i;
    }
    cat_id++;
    
    if ($.browser.msie)
        $('#cat' + cat_id).css({ display: 'inline' });
    else
        $('#cat' + cat_id).css({ display: 'table-row' });
    
    if (cat_id >= 3) {
        $('a.addcat').parent().parent().remove();
    }

    return false;
}

function catalogFilter() {
    $('div.filter a').click(function( e ) {
        var link = $(this);
        link.blur();
        if (link.hasClass('active')) return false;

        var sort = this.href.split('?sort=')[1];

        $('#body').load(
            '/catalog/',
            {
                action: 'showList',
                name: escape( $('#name').attr('value') ),
                city_id: $('#city_id').attr('value'),
                cat_id: $('#cat_id').attr('value'),
                summ1: $('#summ1').attr('value'),
                summ2: $('#summ2').attr('value'),
                is_photo: $('#is_photo').attr('checked') ? 1 : 0,
                is_video: $('#is_video').attr('checked') ? 1 : 0,
                is_audio: $('#is_audio').attr('checked') ? 1 : 0,
                is_feedbacks: $('#is_feedbacks').attr('checked') ? 1 : 0,
                is_blog: $('#is_blog').attr('checked') ? 1 : 0,
                is_scheduler: $('#is_scheduler').attr('checked') ? 1 : 0,
                is_scheduler: $('#is_online').attr('checked') ? 1 : 0,
                sort: sort
            },
            function() {
                $('div.filter a.active').removeClass('active');
                link.addClass('active');
                preparePagesLinks();
            }
        );
        
        return false;
    });
   
    var timer = null;
    var delay = 300;
    $('#name').keyup(function() {
        if (timer) clearTimeout(timer);
        timer = setTimeout(function() {
            getAjaxList();
        }, delay);
    });
    $('#city_id').change(function() {
        getAjaxList( null, null, true );
    });
    $('#cat_id').change(function() {
        getAjaxList();
    });
    $('#summ1').keydown(function(event) {
        return checkNum(event);
    });
    $('#summ1').keyup(function(event) {
        if (timer) clearTimeout(timer);
        timer = setTimeout(function() {
            getAjaxList();
        }, delay);
    });
    $('#summ2').keydown(function(event) {
        return checkNum(event);
    });
    $('#summ2').keyup(function() {
        if (timer) clearTimeout(timer);
        timer = setTimeout(function() {
            getAjaxList();
        }, delay);
    });
    $('div.search-form label').click(function() {
        getAjaxList();
    });
    $('div.search-form span').click(function() {
        getAjaxList();
    });
    
    preparePagesLinks();
}

function checkNum(event) {
    if (event.keyCode >= 96 && event.keyCode <= 105 || event.keyCode >= 48 && event.keyCode <= 57 || event.keyCode >= 37 && event.keyCode <= 40 || event.keyCode == 8 || event.keyCode == 46 || event.keyCode == 36 || event.keyCode == 35 || event.keyCode == 9) {
        return true;
    }
    else {
        return false;
    }
}

function preparePagesLinks() {
    $('#cat_pages a').click(function() {
        getAjaxList($(this).attr('rel'));
        return false;
    });
}

function getAjaxList(topage, update, reloadPage) {
    if (!topage) topage = 1;
    var summ1 = parseInt($('#summ1').attr('value'));
    var summ2 = parseInt($('#summ2').attr('value'));
    if (!summ1) summ1 = '';
    if (!summ2) summ2 = '';
    if (summ2 > 0 && summ2 < summ1) return false;
    
    var name = $('#name').attr('value');
    var city_id = $('#city_id').attr('value');
    var cat_id = $('#cat_id').attr('value');
    var is_photo = $('#is_photo').attr('checked') ? 1 : 0;
    var is_video = $('#is_video').attr('checked') ? 1 : 0;
    var is_audio = $('#is_audio').attr('checked') ? 1 : 0;
    var is_feedbacks = $('#is_feedbacks').attr('checked') ? 1 : 0;
    var is_blog = $('#is_blog').attr('checked') ? 1 : 0;
    var is_scheduler = $('#is_scheduler').attr('checked') ? 1 : 0;
    var is_online = $('#is_online').attr('checked') ? 1 : 0;
    
    var params = {
            action: 'showList',
            name: name,
            city_id: city_id,
            cat_id: cat_id,
            summ1: summ1,
            summ2: summ2,
            is_photo: is_photo,
            is_video: is_video,
            is_audio: is_audio,
            is_feedbacks: is_feedbacks,
            is_blog: is_blog,
            is_scheduler: is_scheduler,
            is_online: is_online,
            page: topage
        };
    
    if (reloadPage) {
        var addr = '';
        for (a in params) {
	    if ( a == "action" ) continue;
	    if ( a == "name" ) addr += a + '=' + escape( params[a] ) + '&';
	    else addr += a + '=' + params[a] + '&';
        }

    	window.location = "?" + addr;
	return;
    }

    if ( reloadPage ) window.location = "?" + addr;

    if (!update) {
        var addr = '';
        for (a in params) {
            addr += a + '=' + params[a] + '&';
        }
        $.address.value(addr);
    }
   
    if (update) {
        $('#body').load('/catalog/', params, function(){
            preparePagesLinks();
        });
    }
}

function chessTable() {
    $("table.chess tr").removeClass("odd");
    $("table.chess tr:nth-child(even)").addClass("odd");
}

function prepare() {
    $(".cloudy").showTitle();
    $(".reg-form .greybody input[type=file]").each(function(){
		if($(this).css('opacity')!=0) $(this).fstyle({ 
	    	imageSrc: '/images/structure/choose-file.gif',
            imagewidth: 61,
            imageheight: 18,
		    height: 18,
            width: 163
        });
    });
	$(".reg-form input.sf-text[type=file]").each(function(){
		if($(this).css('opacity')!=0) $(this).fstyle({ 
	    	imageSrc: '/images/structure/choose-file.gif',
            imagewidth: 61,
            imageheight: 18,
		    height: 18,
            width: 163
        });
    });
    //$('select:visible').sSelect();
    
    $('input.int').keydown(function(event) {
        return checkNum(event);
    });

    $("a.dropItem").click(function() {
        if ($(this).attr('rel') && !confirm($(this).attr('rel'))) {
            return false;
        }
        
        $(this).blur();
        
        var id = this.href.split('id=')[1];
        if (!$('#item_' + id).length) return false;
        
        $.post(
            this.href,
            { ajax: '1' },
            function(data) {
                $('#item_' + data).remove();
                chessTable();
            }
        );
        
        return false;
    });
    
    /*$("input[name=phone]").mask("+7 (999) 999-99-99");
    $("input[name=work_phone]").mask("+7 (999) 999-99-99");*/
    
    //$('div.reg-right').css({ 'visibility': 'hidden' });
    
    /*$('input#confirm').click(function() {
        this.blur();
        if (this.checked) {
            $('div.reg-right').css({ 'visibility': 'visible' });
        }
        else {
            $('div.reg-right').css({ 'visibility': 'hidden' });
        }
    });*/
}

jQuery.fn.setFocusValue = function(defaultValue) {
    return this.each(function(){
        $(this).focus(
            function(){
                if (this.value == defaultValue) this.value = '';
            }
        );
        $(this).blur(
            function(){
                if (this.value == '') this.value = defaultValue;
            }
        );
    });
}

jQuery.fn.showTitle = function() {
    return this.each(function(){
		if(!this.titleCloud) {
	        var newCloud = $('<div class="cloud"><div class="c-top"></div><div class="c-body">'+$(this).attr('title')+'</div><div class="c-bot"></div></div>');
    	    $('body').append(newCloud);
        	this.titleCloud = newCloud;
	        $(this).hover(
				function(){
	    			var offset = $(this).offset();
            		this.titleCloud.css({left: offset.left - 150, top: offset.top - this.titleCloud.height()}).show();
				},
				function(){ $(".cloud").hide(); }
			).attr({title: ''});
		}
    });
}

function artistIlike( o, artist_id ) {
	var img = $( "img", o )[0];
	var like = img.src.indexOf( "Gray" ) < 0;

	$.getJSON(
		"?action=ilike",
		{
			"ajax": 1,
			"like": like ? 0 : 1,
			"artist_id": artist_id
		},
		function( data ) {
                        if ( data.like == 1 ) {
                        	img.src = "/images/structure/ilike.gif";
                        	$( "#ilikeLabel" ).html( "Мне не нравится" );
                        }
                        else {
                        	img.src = "/images/structure/ilikeGray.gif";
                        	$( "#ilikeLabel" ).html( "Мне нравится" );
                        }

			$( "#ilikeTotal" ).html( data.total );
		}
	);

	return false;
}

function blogIlike( o, blog_id ) {
	var img = $( "img", o )[0];
	var like = img.src.indexOf( "Gray" ) < 0;

	$.getJSON(
		"?action=ilike_blog",
		{
			"ajax": 1,
			"like": like ? 0 : 1,
			"blog_id": blog_id
		},
		function( data ) {
                        if ( data.like == 1 ) {
                        	img.src = "/images/structure/ilike.gif";
                        	$( "#blog_ilikeLabel" ).html( "Мне не нравится" );
                        }
                        else {
                        	img.src = "/images/structure/ilikeGray.gif";
                        	$( "#blog_ilikeLabel" ).html( "Мне нравится" );
                        }

			$( "#blog_ilikeTotal" ).html( data.total );
		}
	);

	return false;
}

function forumMsgIlike( o, msg_id, type ) {
	$.getJSON(
		"?action=ilike_forum",
		{
			"ajax": 1,
			"like": type ? 1 : 0,
			"msg_id": msg_id
		},
		function( data ) {
			$( "a", o.parentNode ).hide();
			$( "span", o.parentNode ).html( data.total );
		}
	);

	return false;
}

