$(document).ready(function(){

  var allowSend = 1;

  $("#nav > li").hover(
    function(){$(this).addClass("jshover")},
    function(){$(this).removeClass("jshover")}
  );

  if($("a.commentsA").length > 0)
    $("p.serv_info").hide();

  $("div.date").append("<img height=\"9\" width=\"9\" title=\"Сегодня\" alt=\"Сегодня\" src=\"/images/date.gif\"/>&nbsp;<span id='curDate'></span>, <img height=\"9\" width=\"9\" title=\"Время\" alt=\"Время\" src=\"/images/time.gif\"/>&nbsp;<span id=\"curTime\"></span>");
  getCurTime();

 /////////////////////////////////////
 // Rating functions
 /////////////////////////////////////

  var curObj;

  $(".ratingForm .star-rating").click(function(){
    var newRating = $(this).parents(".ratingForm").children(".star-rating-control").children(".star-rating-on").length;
    $(this).parents(".ratingForm").children("input[name='f_rateCount']").attr("value",newRating);
    $(this).parents(".ratingForm").submit();
  });

  $(".ratingForm").submit(function(){
    if($(this).children("input[name=f_rateSent]").val() == 0) {
      vurObj = $(this);
      $(this).ajaxSubmit(setRateOptions);
    }
    return false;
  });

  // options
  var setRateOptions = { 
    target: "",
    beforeSubmit: showRequest,
    success: showResponse,
    timeout: 3000
  };

  // Actions before sending form
  function showRequest(formData, jqForm, options) { 
//    var queryString = $.param(formData); 
//    alert('Вот что мы передаем: \n\n' + queryString); 
    vurObj.children(".rateSend").show();
    return true; 
  } 

  // Callback function
  function showResponse(responseText, statusText)  {
    // submit of loaded form for a form turned back from a server
    var input_file = responseText.substring(responseText.indexOf("<!--BEGIN CONTENT-->"),responseText.indexOf("<!--END CONTENT-->"));
//    alert(input_file);
    vurObj.children(".thanks").fadeIn("slow");
    vurObj.children(".tech").html(input_file);
    vurObj.children(".rateSend").hide();
    vurObj.children("input:radio").each(function(){
      $(this).attr("disable","disabled");
    });
    vurObj.children("input[name=f_rateSent]").val("1");
  }

/*

  // Скрываем комменты, если есть ссылка на них
  // И не скрываем, если есть #comment
  if($("div.comment > h2 > a").length > 0 && window.location.hash!="#comments")
    $("div.comment > div").hide();

  $("a.toComments").click(function(){
    $("div.comment > div:hidden").toggle("slow");
    return true;
  });

  $("div.comment > h2 > a").click(function(){
    $("div.comment > div").toggle("slow");
    return false;
  });

*/
/*
  $("div.comment > h2 > a").click(function(){
    if($("div.comment_list").html() == "")
    {
      $("div.loading").fadeIn("slow");
      $("div.comment_list").hide();
      var ajURL = $(this).attr("href").substr(0,$(this).attr("href").indexOf("#"))+"&a=1";
      $("div.comment_list").load(ajURL+" div.comment_list","",function(data){ 
        $("div.loading").fadeOut("slow",function(){
          alert(data);
          $("a.commentsA").click(function(){
            eval("$('a.commentsA').attr('onclick')");
          });
          $("div.comment_list").slideDown("slow");
        });  
      });
    }
    return false;
  });
*/

  // Скрываем сеансы на другие дни
  $("#otherDays").hide();
  $(".otherDaysLinkShow").show();

  $(".otherDaysLinkShow").click(function(){
    $("#otherDays").slideDown();
    $(".otherDaysLinkShow").hide();
    $(".otherDaysLinkClose").show();
  });

  $(".otherDaysLinkClose").click(function(){
    $("#otherDays").slideUp();
    $(".otherDaysLinkClose").hide();
    $(".otherDaysLinkShow").show();
  });

  $("p.hdr3.catalog:first").addClass("firstH3");
  $("p.hdr3.catalog").prev("span.catalog").each(function(){
    var thisText = $(this).html();
    $(this).html(thisText.substring(0,thisText.length-1)+".");
  });
//  $("span.catalog").each(function(){
//  if($(this).next())
//  });

// end of document.ready

	/* TV */
		/* добавляем класс к элементу у передачи которого нет полного описания */
		$("#tvguide_detail .description .full").each(function() {
			if ($(this).is(':empty')) {
				$(this).parent().parent().addClass('no_desc_full')
			}
		})
		
		/* клик на .name */
		$("#tvguide_detail li:not(.no_desc_full) .name a").toggle(
			function () {
				$(this).parent().parent().find('.description .anons, .description .full').slideToggle()
			},
			function () {
				$(this).parent().parent().find('.description .anons, .description .full').slideToggle()
			}
		)
		/* клик на .image */
		$("#tvguide_detail li:not(.no_desc_full) .image").toggle(
			function () {
				$(this).parent().find('.description .anons, .description .full').slideToggle()
			},
			function () {
				$(this).parent().find('.description .anons, .description .full').slideToggle()
			}
		)
		
		/* отключаем клик на название, у элемента без анонса или полного описания */
		$("#tvguide_detail li.no_desc_full .name a, #tvguide_detail li.no_desc_full .image").click(
			function () {
				return false
			}
		)
		
		/* Проставляем класс first к программам */
		$("#tvguide_short .chanel_00001:first, #tvguide_short .chanel_00002:first, #tvguide_short .chanel_00623:first, #tvguide_short .chanel_00826:first, #tvguide_short .chanel_00003:first, #tvguide_short .chanel_00108:first, #tvguide_short .chanel_00326:first, #tvguide_short .chanel_00004:first, #tvguide_short .chanel_00235:first, #tvguide_short .chanel_00226:first, #tvguide_short .chanel_00101:first, #tvguide_short .chanel_00107:first, #tvguide_short .chanel_00104:first, #tvguide_short .chanel_00255:first").addClass('first');
		$("#tvguide_short .chanel_00001:last, #tvguide_short .chanel_00002:last, #tvguide_short .chanel_00623:last, #tvguide_short .chanel_00826:last, #tvguide_short .chanel_00003:last, #tvguide_short .chanel_00108:last, #tvguide_short .chanel_00326:last, #tvguide_short .chanel_00004:last, #tvguide_short .chanel_00235:last, #tvguide_short .chanel_00226:last, #tvguide_short .chanel_00101:last, #tvguide_short .chanel_00107:last, #tvguide_short .chanel_00104:last, #tvguide_short .chanel_00255:last").parent().addClass('last');
		/*$("#tvguide_short .chanel_00001:first, #tvguide_short .chanel_00002:first, #tvguide_short .chanel_00623:first, #tvguide_short .chanel_00826:first, #tvguide_short .chanel_00003:first, #tvguide_short .chanel_00108:first, #tvguide_short .chanel_00326:first, #tvguide_short .chanel_00004:first, #tvguide_short .chanel_00235:first, #tvguide_short .chanel_00226:first, #tvguide_short .chanel_00101:first, #tvguide_short .chanel_00107:first, #tvguide_short .chanel_00104:first, #tvguide_short .chanel_00255:first").parent().parent().addClass('first');
		$("#tvguide_short li.first:first").removeClass('first');*/
	/* /TV */

});

var months = new Array("января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря");
var days = new Array("воскресенье", "понедельник", "вторник", "среда", "четверг", "пятница", "суббота");

function getCurTime()
{
  var curTime = new Date();
  var timeString = curTime.getHours();
  (curTime.getSeconds()%2!= 0 ? timeString += ":" : timeString += "<span style='visibility:hidden;'>:</span>");
  (curTime.getMinutes().toLocaleString().indexOf(",")!= -1 ? curTimeMinutes = curTime.getMinutes().toLocaleString().substr(0,curTime.getMinutes().toLocaleString().indexOf(",")) : curTimeMinutes = curTime.getMinutes().toLocaleString());
  (curTimeMinutes.length != 2 ? timeString += "0"+curTimeMinutes : timeString += +curTimeMinutes);

  var dateString = curTime.getDate()+" "+months[curTime.getMonth()]+", "+days[curTime.getDay()];

  $("#curDate").html(dateString);
  $("#curTime").html(timeString); //+":"+curTime.getSeconds()
  setTimeout("getCurTime()",1000);
}

