var monthes = ['Января','Февраля','Марта','Апреля','Мая','Июня','Июля','Августа','Сентября','Октября','Ноября','Декабря'];

$(document).ready(function()
{
   var currentTime  = new Date();
   var currentDay   = currentTime.getDate();
   var currentMonth = monthes[currentTime.getMonth()];
   var currentYear  = currentTime.getFullYear();
   if(document.getElementById('top_date')) document.getElementById('top_date').innerHTML = currentDay + ' ' + currentMonth + ', ' + currentYear;
   TopClock();
   window.setInterval(TopClock, 60000);
});

function TopClock()
{
   var currentTime = new Date();
   var currentHours = currentTime.getHours();
   var currentMinutes = currentTime.getMinutes();
   currentMinutes = (currentMinutes < 10 ? "0" : "") + currentMinutes;
   currentHours   = (currentHours < 10 ? "0" : "") + currentHours;
   if(document.getElementById('top_clock')) document.getElementById('top_clock').innerHTML = currentHours + ':' + currentMinutes;
}

function SubmitSearch()
{
   q = document.getElementById('query').value;
   if(q == '' || q == 'Поиск по сайту') return false;
   return true;
}

function Send2friendUp()
{
   $('#send2friend').fadeIn(600);
   $('#send2friend input:text').focus();
}

function Send2friendDown()
{
   $('#send2friend').fadeOut(600);
}

function Send2friendSend()
{
   var eml = $('#send2friend input[name="email"]').val();
   var id  = $('#send2friend input[name="id"]').val();
   var cat = $('#send2friend input[name="cat"]').val();

   $.ajax({
      type: "POST",
      url: "/send2friend.html",
      data: "cat="+cat+"&id="+id+"&mail="+eml,
      success: function(msg){
         if(msg == 1)
         {
            var box = '#send2succ';
         } else
         {
            var box = '#send2fail';
         }
         $(box).fadeIn(600);
         window.setTimeout(function(){$(box).fadeOut(600);}, 5000);
      }
   });
}

function embedFlash(fileName, lib, tm, w, h)
{
   /*
   fileName - path to flash file
   lib - flash variables
   tm - flash timestamp for anticaching
   w - width
   h - height
   */
   var flob='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+w+'" height="'+h+'" id="picture" align="middle">';
   flob+='<param name="allowScriptAccess" value="sameDomain" />';
   flob+='<param name="movie" value="'+fileName+'?' + tm + '" />';
   flob+='<param name="quality" value="high" />';
   flob+='<PARAM NAME=FlashVars VALUE="'+lib+'">';
   flob+='<PARAM NAME=wmode VALUE="transparent">';
   flob+='<param name="bgcolor" value="#eaeff4" />';
   flob+='<embed src="'+fileName+'?' + tm + '" quality="high" wmode="transparent" FlashVars="'+lib+'" bgcolor="#eaeff4" width="'+w+'" height="'+h+'" name="picture" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
   flob+='</object>';
   document.write(flob);
}

