$(document).ready(function(){
  
  if (/MSIE 6/i.test(navigator.userAgent) || /MSIE 7/i.test(navigator.userAgent)) {
    $("hr").remove();
  }
	if (/MSIE 6/i.test(navigator.userAgent) == false) {
		Cufon.replace( "h2" );
		Cufon.replace( "h3" );
		Cufon.replace( ".menu a", {hover: 'true'} );
		Cufon.replace( "#sloogan" );
		Cufon.replace( "#slogan-alasivu p" );
	   // Cufon.replace("#titlebar", {textShadow: "#479116 0px 1px"});
	}

  
  $( ".text, textarea" ).inputDefault();
  $( "#menu-item-17" ).addClass( "joujou" );
  $( "#tulevat-keikat .keikka-wrapper" ).last().addClass("viimene");
  //$( "#sub-menu li" ).last().css( { border-bottom: "none" } );
  
  /*albumeille ja thumbnaileille joka kuudes on last*/
  $( ".ngg-galleryoverview .ngg-gallery-thumbnail-box:nth-child(6n)" ).addClass( "last" );
  $( ".ngg-albumoverview .ngg-album-compact:nth-child(6n)" ).addClass( "last" );
  
  
  
  $("ul").each(function(){
    $(this).find("li").last().addClass("last");
    $(this).find("li").first().addClass("first");
  });
  $("ol").each(function(){
    $(this).find("li").last().addClass("last");
    $(this).find("li").first().addClass("first");
  });
  
  $("table").each(function(){
    if ( $(this).find("tr").size() > 1 ) {
      $(this).find("tr").last().addClass("last");
    }
    $(this).find("tr").first().addClass("first");
  });
  
  $("tr").each(function(){
    if ( $(this).find("td").size() > 1 ) {
      $(this).find("td").last().addClass("last");
      $(this).find("td").first().addClass("first");
    }
    if ( $(this).find("th").size() > 0 ) {
      $(this).find("th").last().addClass("last");
      $(this).find("th").first().addClass("first");
    }
  });
  
  $("#panorama-link").fancybox({
    type: 'iframe',
    width: 640,
    height: 480,
    scrolling: 'no',
    margin: 0,
    padding: 10
  });
  
  $(".fancy").fancybox({
    titleShow: false
  });
  
  
    $(".btn").mouseenter(function(){
    $(this).stop(true,true).animate({
      marginLeft: '+=2px',
      opacity: 0.85
    },100);
    $(this).mouseleave(function(){
      $(this).animate({
        marginLeft: 47,
        opacity: 1
      },100);
    });
  });
  
    $(".submit").mouseenter(function(){
    $(this).stop(true,true).animate({
      marginLeft: 4,
      opacity: 0.85
    },100);
    $(this).mouseleave(function(){
      $(this).animate({
        marginLeft: 0,
        opacity: 1
      },100);
    });
  });
  
   $(".ngg-album-compact").mouseenter(function(){
    $(this).stop(true,true).animate({
      opacity: 0.7
    },200);
    $(this).mouseleave(function(){
      $(this).animate({
        opacity: 1
      },100);
    });
  });
  
  //lista
  
  $(".home #content").css({height: $("#lounaslista").outerHeight()-80});
  
  //heightfix
  
  $("#sidebar-right").css({height: $("#content").outerHeight()});
  $("#sidebar-middle").css({height: $("#content").outerHeight()});
  
  
  //formit
  $("#yhteys").validate({
    rules: {
      nimi: "required",
      puhelin: "required",
      sposti: "required",
      viestisi: "required",
	  halu: "required"
    },
    success: "valid",
    submitHandler: function(form){
      $(form).ajaxSubmit({
        success: function() {
          $(form).slideUp();
          $(form).html("<h3>Kiitos yhteydenotostanne!</h3><p>Viesti vastaanotettiin onnistuneesti.</p>");
          $(form).slideDown();
        }
      });
    }
  });
  
});
