function openDateBirth(object,id) {
    if(!$(object).parent().find('.popout').get(0)) {
        $.ajax({
            method: "get",
            url: 'http://'+location.host+'/calendarev/getItem/'+id+'/',
            dataType:"json",
            cache:true,
            success: function(data){
                var position = $(object).position();
                var title = data.name;
                if($('.popout').attr('class')) $('.popout').remove();
                if($('.popoutBirth').attr('class')) $('.popout').remove();
                
                var left = position.left*1-250;
                left = left > 0 ? left : 0;
                $(object).parent().append('<div class="popoutBirth" style="top:'+(position.top*1-260)+'px; left:'+left+'px;"><div onclick="return closeWin(this);" onmouseover="enableClose()" onmouseout="disableClose();" class="closeBirth">&nbsp;</div><div class="popoutTextBirth"><a href="/calendarev/show/'+data.id+'/">'+title+'</a><br />'+data.text+'</div></div>');
                return false;
            }
        });
    }
    return false;
}
function openDate(object,id) {
    if(!$(object).parent().find('.popout').get(0)) {
        $.ajax({
            method: "get",
            url: 'http://'+location.host+'/calendarev/getItem/'+id+'/',
            dataType:"json",
            cache:true,
            success: function(data){
                var position = $(object).position();
                var title = data.img ? '<img src="'+data.img+'" />' : data.name;
                if($('.popout').attr('class')) $('.popout').remove();
                
                var left = position.left*1-250;
                left = left > 0 ? left : 0;
                $(object).parent().append('<div class="popout" style="top:'+(position.top*1-200)+'px; left:'+left+'px;"><div onclick="return closeWin(this);" onmouseover="enableClose()" onmouseout="disableClose();" class="close">&nbsp;</div><div class="popoutLeft"><a href="/calendarev/show/'+data.id+'/">'+title+'</a></div><div class="popoutRight"><h2><a href="/news/show/'+data.id+'/">'+data.name+'</a></h2>'+data.text+'</div></div>');
                return false;
            }
        });
    }
    return false;
}

function openMonth(month) {
    if(month == 'prev') month = $('.cf_ac').attr('id').replace('month','')*1-1;
    if(month == 'next') month = $('.cf_ac').attr('id').replace('month','')*1+1;

    $.ajax({
        method: "get",
        url: 'http://'+location.host+'/calendarev/items/'+month+'/1/',
        dataType:"json",
        cache:true,
        success: function(data){
            $('.home_calendar').html(data['html']);
//            $('.calendarEvs').hide('fast',function(){$(this).show('fast');});
//            $('.calendarEvs').show('fast');
//            $('.home_calendar').hide('fast',function(){$(this).html(data['html']).show('fast');}); 
            return false;
        }
    });

    return false;
}

function enableClose() {
    $('.close').css({'background-position':'-21px', 'cursor':'pointer'});
}

function disableClose() {
    $('.close').css('background-position','0px');
}

function closeWin(object) {
    $(object).parent().remove();
    return false;
}

function showForm() {
    if ($('.comform').css('display') == 'none') $('.comform').show('fast');
    else $('.comform').hide('fast');
    return false;
}

function sendComment(form) {
    var validation = true;
    $(form).find("[color='vRed']").each(function(){validation = false;});
    if(validation) {
        $.ajax({
        	type: "POST",
        	url: $(form).attr('action'),
        	dataType: "html",
        	data: $(form).serialize(),
        	cache: false,
    //    	beforeSend: function(){},
        	success: function(data){
        	   $('.comcount').html($('.comcount').html()*1+1);
               $('.comcountbig').html($('.comcountbig').html()*1+1);
        	   $(data.replace('[name]','<div class="com_bek"><span>').replace('[/name] [date]', ' <i>').replace('[/date]', '</i>').replace('[text]', '</span>').replace('[/text]', '</div>')).insertAfter($('.firstcom'));
               $('.comform').hide('fast');
               
               return false;
            }
        });
    }
	    
    return false;
}

function order(mode,object,rub) {
    if(rub && rub == 'smi') var href = 'smi';
    else var href = 'news';
    $.ajax({
    	type: "get",
    	url: '/'+href+'/order/'+mode+'/',
    	dataType: "html",
    	cache: true,
    	success: function(data){
           $('.event_img_ul').hide('fast',function(){$(this).html(data).show('fast');});
           $('.ei_filter').find('.active').each(function(){$(this).removeAttr('class').removeAttr('onclick').unbind('click').click(function(){return order($(this).attr('id').replace('act',''), this, rub);}).html($(this).html().replace('b','i'));});
           $(object).attr('class', 'active').removeAttr('onclick').unbind('click').click(function(){return false;}).html($(object).html().replace('i','b'));
           
           $('.pg_ac').removeAttr('class');
           $('.pages').find('a:first').attr('class','pg_ac');
           
           return false;
        }
    });
    
    return false;
}

function selectPostcard(src,id) {
    $('#postcardImg').attr('value',id); 
    $('.selectedPostcard').html('<img width="59" height="59" src="'+src+'" /><a title="Удалить" href="/" onclick="return delSelectedPostcard()"></a>');
    
    return false;
}

function delSelectedPostcard() {
    $('#postcardImg').attr('value',0);
    $('.selectedPostcard').html('Открытка не выбрана!');
    
    return false;
}

function getPostcard(object) {
    if($(object).attr('class') != 'gf_ac') {
        $.ajax({
        	type: "get",
        	url: $(object).attr('href'),
        	dataType: "html",
        	cache: true,
        	success: function(data){
        	   $('.g_ul').hide('fast', function(){$(this).html(data).show('fast',function(){$('a[rel=imagebox]').lightBox({txtImage: 'Изображение',txtOf: 'из',imageBlank: '/img/lightbox/blank.gif',imageLoading: '/img/lightbox/loading.gif',imageBtnClose: '/img/lightbox/close.gif',imageBtnPrev: '/img/lightbox/prev.gif',imageBtnNext: '/img/lightbox/next.gif'});});});
               $('.gf_ac').removeAttr('class');
               $(object).attr('class','gf_ac');
               return false;
            }
        });
    }
    
    return false;
}

function nextCalEv(object) {
    var next = $(object).parent().find('a.active').removeAttr('class').css('display','none').next('a');
    if($(next).attr('class') != 'cl_pl') {
       $(next).attr('class','active').css('display',''); 
    }
    else $(object).parent().find('a:first').attr('class','active').css('display','');
    
    return false;
}

