
$(document).ready(function () {

  /*
   *  Other stuff
   */                             

  $("ul.nav").superfish();

  $("#colour_show").innerfade({ speed: 2000, timeout: 4000, type: 'sequence', containerheight: '102px' });
  $(".accessory_show").innerfade({ speed: 2000, timeout: 5000, type: 'sequence', containerheight: '102px' });

  $("#centrecontent > p:contains('The Playhouse Company')").each(function() {
    var str = $(this).html();
    str = str.replace(/The Playhouse Company/gi, "<span class=\"company_name\">The Playhouse Company</span>");
    $(this).html(str);
  })

  $("area[alt='a']").click(function(e) { e.preventDefault(); $('#explain_a').modal(); })
  $("area[alt='b']").click(function(e) { e.preventDefault(); $('#explain_b').modal(); })
  $("area[alt='c']").click(function(e) { e.preventDefault(); $('#explain_c').modal(); })
  $("area[alt='d']").click(function(e) { e.preventDefault(); $('#explain_d').modal(); })
  $("area[alt='e']").click(function(e) { e.preventDefault(); $('#explain_e').modal(); })
  $("area[alt='f']").click(function(e) { e.preventDefault(); $('#explain_f').modal(); })
  $("area[alt='g']").click(function(e) { e.preventDefault(); $('#explain_g').modal(); })
  $("area[alt='h']").click(function(e) { e.preventDefault(); $('#explain_h').modal(); })

  $("#homeslideshow").crossSlide({
    speed: 27,
    fade: 1
  }, [
    { src: 'images/template/domestic/home1.jpg', dir: 'up'   },
    { src: 'images/template/domestic/home2.jpg', dir: 'down' },
    { src: 'images/template/domestic/home3.jpg', dir: 'up'   },
    { src: 'images/template/domestic/home4.jpg', dir: 'down' }
  ]);

  /*
   *  SEARCH BY CODE
   */
  $("input[name='code']").each(function() {
    if ($(this).val() == "" || $(this).val() == "enter code") {
      $(this).val("enter code");
      $("input[name='code']").css('color', '#888');
    }
  });

  $("input[name='code']").focus(function () {
    if ($(this).val() == "enter code") {
      $(this).val("");
      $("input[name='code']").css('color', '#444');
    }
  });

  $("input[name='code']").blur(function () {
    if ($(this).val() == "") {
      $(this).val("enter code");
      $("input[name='code']").css('color', '#888');
    }
  });

  $("#codesearch_submit").click(function () {
    if ($("input[name='code']").val() != "" && $("input[name='code']").val() != "enter code") {
      document.codesearch.submit();
    } else {
      alert("Please enter a project code.");
    }
  });



  /*
   *  SEARCH BY PRICE
   */
  var pricelist_timeout;

  // show or hide dropdown menu on click
  $("#search-price").click(function () {
    var list = $("#pricelist");
    if (list.css('display') == 'none') {
      list.fadeTo(1, 0.8, function() {
        list.slideDown();
      });
    } else {
      HidePriceList();
    }
  });

  // start timeout when mouse leaves the dropdown area
  $("#pricelist").mouseout(function() {
    pricelist_timeout = setTimeout("HidePriceList()", 200);
  });

  // cancel timeout when mouse enters the dropdown area
  $("#pricelist").mouseover(function() {
    clearTimeout(pricelist_timeout);
  });


});


function HidePriceList() {
  $("#pricelist").hide();
}