// JavaScript Document

$(document).ready(function(){

    $("#load-icon").ajaxStart(function(){
        if ($(this).css("display") == 'none') {
            $(this).fadeIn();
        }
    });

    $("#load-icon").ajaxSuccess(function(evt, request, settings){
        if ($(this).css("display") == 'block') {
            $(this).fadeOut();
        }
    });

    $('#load-icon').hide();
	
	$("img.lazy").lazyload({ 
		effect : "fadeIn"
	});
	
	$('.buttons-group.click-select .button').click(function(){
		$(this).parent().find('.button').removeClass('current');
		$(this).addClass('current');		
	});

	$('.buttons-group.click-check .button').click(function(){
		$(this).toggleClass('current');
	});

});


function get_comment_form (comment_id) {	
    $('.comments-list').find('.comment-form').remove();
    $('#comment-form > .comment-form').clone().insertAfter($('#comment-'+comment_id+' > .content'));
    $("#comment-"+comment_id+" input[name='parent_id']").val(comment_id);		
}

function rate_this (content_id, content_type, direction) {
	$('#rating-box-'+content_id+'-'+content_type+' > .current').load('/actions/update-rating/?content_id='+content_id+'&content_type='+content_type+'&direction='+direction);	
}


// ----------------------------------------------------------------------------
// Stikr, jQuery plugin
// v 1.0
// ----------------------------------------------------------------------------
// Copyright (C) 2010 recens
// http://recens.ru/jquery/plugin_stickr.html
// ----------------------------------------------------------------------------
(function($) {
	$.stickr = function(o) {
		var o = $.extend({   // настройки по умолчанию
			time:5000, // количество мс, которое отображается сообщение
			speed:'slow', // скорость исчезания
			note:null, // текст сообщения
			className:null, // класс, добавляемый к сообщению
			sticked:false, // не выводить кнопку закрытия сообщения
			position:{top:0,right:0} // позиция по умолчанию - справа сверху
		}, o);
		var stickers = $('#jquery-stickers'); // начинаем работу с главным элементом
		if (!stickers.length) { // если его ещё не существует
			$('body').prepend('<div id="jquery-stickers"></div>'); // добавляем его
			var stickers = $('#jquery-stickers');
		}
		stickers.css('position','fixed').css({right:'auto',left:'auto',top:'auto',bottom:'auto'}).css(o.position); // позиционируем
		var stick = $('<div class="stick"></div>'); // создаём стикер
		stickers.append(stick); // добавляем его к родительскому элементу
		if (o.className) stick.addClass(o.className); // если необходимо, добавляем класс
        stick.html(o.note); // вставляем сообщение
		if (o.sticked) { // если сообщение закреплено
			var exit = $('<div class="exit"></div>');  // создаём кнопку выхода
			stick.prepend(exit); // вставляем её перед сообщением
			exit.click(function(){  // при клике
				stick.fadeOut(o.speed,function(){ // скрываем стикер
					$(this).remove(); // по окончании анимации удаляем его
				})
			});
		} else { // если же нет
			setTimeout(function(){ // устанавливаем таймер на необходимое время
				stick.fadeOut(o.speed,function(){ // затем скрываем стикер
					$(this).remove(); // по окончании анимации удаляем его
				});
			}, o.time);
		}
	};
})(jQuery);
