

      $j_eme_calendar=jQuery.noConflict();
      $j_eme_calendar(document).ready( function() {
         initCalendar();
      });
      
      function initCalendar() {
         $j_eme_calendar('a.prev-month').click(function(e){
            e.preventDefault();
            tableDiv = $j_eme_calendar(this).closest('table').parent();
            ($j_eme_calendar(this).hasClass('full-link')) ? fullcalendar = 1 : fullcalendar = 0;
            ($j_eme_calendar(this).hasClass('long_events')) ? long_events = 1 : long_events = 0;
            prevMonthCalendar(tableDiv, fullcalendar, long_events);
         } );
         $j_eme_calendar('a.next-month').click(function(e){
            e.preventDefault();
            tableDiv = $j_eme_calendar(this).closest('table').parent();
            ($j_eme_calendar(this).hasClass('full-link')) ? fullcalendar = 1 : fullcalendar = 0;
            ($j_eme_calendar(this).hasClass('long_events')) ? long_events = 1 : long_events = 0;
            nextMonthCalendar(tableDiv, fullcalendar, long_events);
         } );
      }
      function prevMonthCalendar(tableDiv, fullcalendar, showlong_events) {
         if (fullcalendar === undefined) {
             fullcalendar = 0;
         }
         if (showlong_events === undefined) {
             showlong_events = 0;
         }
         month_n = tableDiv.children('div.month_n').text();
         year_n = tableDiv.children('div.year_n').text();
         cat_chosen = tableDiv.children('div.cat_chosen').text();
         author_chosen = tableDiv.children('div.author_chosen').text();
         contact_person_chosen = tableDiv.children('div.contact_person_chosen').text();
         parseInt(month_n) == 1 ? prevMonth = 12 : prevMonth = parseInt(month_n,10) - 1 ; 
            if (parseInt(month_n,10) == 1)
            year_n = parseInt(year_n,10) -1;
         $j_eme_calendar.get("http://lightsoundnews.ru/lsn", {eme_ajaxCalendar: 'true', calmonth: prevMonth, calyear: year_n, full: fullcalendar, long_events: showlong_events, category: cat_chosen, author: author_chosen, contact_person: contact_person_chosen }, function(data){
            tableDiv.replaceWith(data);
            initCalendar();
         });
      }
      function nextMonthCalendar(tableDiv, fullcalendar, showlong_events) {
         if (fullcalendar === undefined) {
             fullcalendar = 0;
         }
         if (showlong_events === undefined) {
             showlong_events = 0;
         }
         month_n = tableDiv.children('div.month_n').text();
         year_n = tableDiv.children('div.year_n').text();
         cat_chosen = tableDiv.children('div.cat_chosen').text();
         author_chosen = tableDiv.children('div.author_chosen').text();
         contact_person_chosen = tableDiv.children('div.contact_person_chosen').text();
         parseInt(month_n,10) == 12 ? nextMonth = 1 : nextMonth = parseInt(month_n,10) + 1 ; 
            if (parseInt(month_n,10) == 12)
            year_n = parseInt(year_n,10) + 1;
         $j_eme_calendar.get("http://lightsoundnews.ru/lsn", {eme_ajaxCalendar: 'true', calmonth: nextMonth, calyear: year_n, full : fullcalendar, long_events: showlong_events, category: cat_chosen, author: author_chosen, contact_person: contact_person_chosen }, function(data){
            tableDiv.replaceWith(data);
            initCalendar();
         });
      }
      
      // function reloadCalendar(e) {
      //    // e.preventDefault();
      //    console.log($j_eme_calendar(this).parents('table'));
      //     $j_eme_calendar.get("", {ajax: 'true'}, function(data){
      //       tableDiv = table.parent();
      //       tableDiv.html(data);
      //             });
      // }
      //
      

