$(document).ready(function() {

  $("div.contentM > ul > li:last").addClass("noBorder");

  $("#showCalendarLink a").click(function(){
    $("#showCalendarLink").slideUp();
    $("#calendarBox").slideDown("slow");
    return false;
  });

  $("#hideCalendarLink").click(function(){
    $("#calendarBox").slideUp("slow");
    $("#showCalendarLink").slideDown();
    return false;
  });

  if($("#theme option:last:selected").length == 0) $("#otherThemeDiv").hide();

  $("#theme").change(function(){
    if($("#theme option:last:selected").length > 0)
      $("#otherThemeDiv").slideDown();
    else {
      $("#otherThemeDiv").slideUp();
      $("#otherTheme").attr("value","");
    }
  });

  // Filter
  $(".applyFilter").hide();
  $(".filterBy").change(function(){
    if($(this).parents("form").attr("action") != "")
    {
      var queryString = $(this).parents("form").attr("action")+"&filterBy="+$(this).children("option:selected").attr("value");
      document.location.href = queryString;
    }
    else
      $(this).parents("form").submit();
  });

  // Adding Print Link
  $("#printLink").click(function(){
    window.open($(this).attr("href"),"Страница печати","width=800,height=600,toolbars=no,menubar=no,scrollbars=yes");
    return false;
  });

  // Font size changing
  $("div.aaa span").addClass("clickable");

  $("div.aaa span").click(function(){
    $.cookie("fontChanged",$(this).attr("id"),{expires: 7,path: "/",domain: "rebuild.rentapower.ru"});
    switch($(this).attr("id"))
    {
      case('font1') : $("div.leftMenu ul li").css("font-size","14px");$("div.leftMenu ul ul li").css("font-size","12px");$("table.content").css("font-size","12px");$("h1").css("font-size","14px");$("h4").css("font-size","12px");break;
      case('font2') : $("div.leftMenu ul li").css("font-size","16px");$("div.leftMenu ul ul li").css("font-size","14px");$("table.content").css("font-size","14px");$("h1").css("font-size","18px");$("h4").css("font-size","13px");break;
      case('font3') : $("div.leftMenu ul li").css("font-size","18px");$("div.leftMenu ul ul li").css("font-size","16px");$("table.content").css("font-size","18px");$("h1").css("font-size","22px");$("h4").css("font-size","15px");break;
    }
//    alert($.cookie("fontChanged"));
  });

  if($.cookie("fontChanged")) $("div.aaa img#"+$.cookie("fontChanged")).click();

//    alert($.cookie("fontChanged"));

//
  $("select[name=f_type]").change(function(){
    var selectedValue = $("select[name=f_type] option:selected").attr("value");
    if(selectedValue==1){
     $("#commercialList").show();
     $("#livingList").hide();
    }
    if(selectedValue==2){
     $("#commercialList").hide();
     $("#livingList").show();
    }
    if(selectedValue==3){
     $("#commercialList").hide();
     $("#livingList").hide();
    }
    if(selectedValue==4){
     $("#commercialList").hide();
     $("#livingList").hide();
    }
  });

// то же при загрузке документа
//
  var selectedValue = $("select[name=f_type] option:selected").attr("value");
  if(selectedValue==1){
   $("#commercialList").show();
   $("#livingList").hide();
  }
  if(selectedValue==2){
   $("#commercialList").hide();
   $("#livingList").show();
  }
  if(selectedValue==3){
   $("#commercialList").hide();
   $("#livingList").hide();
  }
  if(selectedValue==4){
   $("#commercialList").hide();
   $("#livingList").hide();
//   $("#workType").hide();
  }


  $("div.topMenu td").hover(
    function(){$(this).children("ul").show();},
    function(){$(this).children("ul").hide();}
  )

//  var randomHead = Math.floor(headImages.length*Math.random());
//  alert(headImages[randomHead]);
//  $("div.header").css("background","url('"+headImages[randomHead]+"') no-repeat left top");

// END OF DOCUMENT.READY
/////////////////////////////////////////
});

