function handler_news( guid )
{
    if ( guid == '' )
    {
        jQuery.get
        (
            '/cgi-bin/news/catalogue' ,
            {
            }                         ,
            function( data )
            {
                core_news_catalogue(data);
                $('div.core_news_archive').find('a:first')
                                          .click();

            } ///;~
        );
    }
    else
    {
        jQuery.get
        (
            '/cgi-bin/news/item' ,
            {
                guid: guid
            }                    ,
            function( data )
            {
                core_news_item(data);

            } ///;~
        );
    }

} ///;~


function core_news_slice( month ,
                          year  )
{
    jQuery.get
    (
        '/cgi-bin/news/slice' ,
        {
            m: month ,
            y: year
        }                     ,
        function( data )
        {
            core_news_list(data);

        } ///;~
    );

} ///;~

function core_news_catalogue( data )
{
    var size = $('item', data).size();

    if ( size == 0 )
    {
    }
    else
    {
    }

    $('item', data).each(function( position )
    {
        var m    = $('month' , this).text();
        var y    = $('year'  , this).text();
        var argv = $('year'  , this).size();
        var item = $(this).text();

        if ( argv == 0 )
        {
            var m = 'NULL'
            var y = item;
        }
        else
        {
            var month = month_as_string(parseInt(m) - 1);
            var item  = month + ' ' + y;
        }

        $('div.core_news_archive').find('div:last')
                                  .find('a')
                                  .text(item);

        $('div.core_news_archive').find('div:last')
                                  .find('a')
                                  .attr
        ({
            title: 'Все новости за ' + item ,
            alt:   'Все новости за ' + item
        });

        $('div.core_news_archive').find('div:last')
                                  .find('a')
                                  .click(function()
        {
            core_news_slice(m, y);
            $('span.core_news_archive').text(item);

        });

        if ( (position + 1) != size )
        {
            $('div.core_news_archive').find('div:last')
                                      .clone()
                                      .appendTo('div.core_news_archive');
        }
    });

    $('div.core_news_archive').show();

} ///;~

   function timestamp2date(timestamp) {
     var theDate = new Date(timestamp * 1000);
      var imonth=theDate.getMonth();

      switch(imonth+1)
      {
    case 1:
      imonth="Января";
	break;
    case 2:
      imonth="Февраля";
      break;
    case 3:
      imonth="Марта";
      break;
    case 4:
      imonth="Апреля";
      break;
    case 5:
      imonth="Мая";
      break;
    case 6:
      imonth="Июня";
      break;
    case 7:
      imonth="Июля";
      break;
   case 8:
      imonth="Августа";
      break;
   case 9:
      imonth="Сентября";
      break;
  case 10:
      imonth="Октября";
      break;
  case 11:
      imonth="Ноября";
      break;
  case 12:
      imonth="Декабря";
      break;
default:
      ;
      }


      var iyear=theDate.getFullYear();
      var idate=theDate.getDate();
      var alldate=idate.toString()+" "+imonth.toString()+" "+iyear.toString();
    return alldate;
   }
   function date2timestamp(year, month, day, hour, min, sec) {
     return (Date.UTC(year, month-1, day, hour, min, sec) / 1000);
   }



function core_news_slideshow_list( data )
{
    var size = $('item', data).size();
    var item = $('ul.core_news_slideshow').find('li:last');
    var total=2;

    if ( size == 0 )
    {
    }
    else
    {
    }

    $('ul.core_news_slideshow').html(item); 
    $('item', data).each(function( position )
    {
        var guid      = $('guid'      , this).text();
        var thumbnail = $('thumbnail' , this).text();
        var title     = $('title'     , this).text();
		var time     = $('time'     , this).text();

        $('ul.core_news_slideshow').find('li:last')
                                   .find('a')
                                   .text(title);

        $('ul.core_news_slideshow').find('li:last')
                                   .find('a')
                                   .attr
        ({
            href: '/news/' + guid + '/' ,
            title: title                ,
            alt:   title
        });

	//--- date news out


	$('ul.core_news_slideshow').find('li:last')
                                   .find('span')
                                   .text(timestamp2date(time));

	 //---

jQuery.post('/ex/news_comment2.php' , {gui: guid} , function (result) {
//var j_com = eval("(" + result + ")");
j_com=result.split('"');

ar_com=j_com[3].split(" "); //document.getElementById('num_com').style.display="block"; 

var elem = document.getElementsByTagName('B');
     var arr = new Array();
     for(ii = 0,iarr = 0; ii < elem.length; ii++) {
          att = elem[ii].getAttribute("name");
          if(att == "coms") {
               arr[iarr] = elem[ii];
               iarr++;
          }
     }

for(var i=0; i<arr.length; i++) {arr[i].innerHTML="комментарии ["+ar_com[i]+"]";  }
//alert(arr.length);


},'JSON');

 /*	$('ul.core_news_slideshow').find('li:last')
                                   .find('span:last')
                                   .text(document.getElementById('num_com').innerHTML);
*/

        $('ul.core_news_slideshow').find('li:last')
                                   .click(function()
        {
            location.href = '/news/' + guid + '/';
        });

        if ( thumbnail == 'NULL' )
        {
            $('ul.core_news_slideshow').find('li:last')
                                       .find('img')
                                       .attr
            ({
                src: '/libpixmap/thumbnail/news/empty.gif' ,
                alt:   title                               ,
                title: title
            });
        }
        else
        {
            $('ul.core_news_slideshow').find('li:last')
                                       .find('img')
                                       .attr
            ({
                src: '/libpixmap/thumbnail/news/' + thumbnail ,
                alt:   title                                  ,
                title: title
            });
        }

        if ( (position + 1) != size )
        {
            $('ul.core_news_slideshow').find('li:last')
                                       .clone()
                                       .appendTo('ul.core_news_slideshow');
        }
    });

    $('div.core_news_slideshow').show();
    $('#core_news_slideshow').accessNews
    ({
        speed:    'normal'            ,
        headline: 'Последние новости' ,
        slideBy:  '4'
    });

} ///;~

function core_news_list( data )
{
    var size = $('item', data).size();
    var item = $('ul.core_news_list').find('li:last');

    if ( size == 0 )
    {
    }
    else
    {
    }

    $('ul.core_news_list').html(item);
    $('item', data).each(function( position )
    {
        var guid  = $('guid'  , this).text();
        var title = $('title' , this).text();

        $('ul.core_news_list').find('li:last')
                              .find('a')
                              .text(title);

        $('ul.core_news_list').find('li:last')
                              .find('a')
                              .attr
        ({
            href:  '/news/' + guid + '/' ,
            title: title                 ,
            alt:   title
        });

        if ( (position + 1) != size )
        {
            $('ul.core_news_list').find('li:last')
                                  .clone()
                                  .appendTo('ul.core_news_list');
        }
    });

    $('ul.core_news_list').show();

} ///;~

function core_news_item( data )
{
    var guid    = $('guid'    , data).text();
    var title   = $('title'   , data).text();
    var body    = $('body'    , data).text();
    var protect = $('protect' , data).text();

    if ( guid == '' )
    {
        location.href = '/404/';
    }

    if ( parseInt(protect) == 1 )
    {
        $('div.core_comment_list').text('Комментарии запрещены администратором');
        $('div.core_comment_list').show();
        $('div.core_comment_form').hide();
    }
    else
    {
        core_comment_init(guid, 'news');
    }

    $('h3.core_news_title').text(title);
    $('div.core_news_body').html(body);

    core_news_tuning();

} ///;~

function core_news_tuning()
{
    var colLWidth = $('div.core_news_body').width();

    if ( colLWidth > 740 )
    {
        $('div.core_news_body').width('740');
    }

} ///;~
