
$(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' }
  ]);

  $("#right .options li:not(:first)").css({'opacity':0, 'display':'none'});
  var curImg, nextImg, t;
  var fadeOptions = function (){
    clearTimeout(t);
    var children;
    if (curImg == null){
      curImg = 0;
      nextImg = 1;
    }

    children = $('ul.options').children();
    nextImg = children[nextImg] ? nextImg : 0;

    $(children[nextImg]).css({'display':'block'}).animate({'opacity': 1}, 500, function(){});
    $(children[curImg]).animate({'opacity': 0}, 500, function(){
      $(this).css({'display':'none'});
      curImg = nextImg;
      nextImg = nextImg + 1;
      t = setTimeout(fadeOptions, 5000);
    });
  };

  t = setTimeout(fadeOptions, 5000);

  $('.green .prev').click(function(){
    nextImg = curImg - 1;
    var children = $('ul.options').children();
    if (nextImg < 0){
      nextImg = children.length - 1;
    }
    fadeOptions();
    return false;
  });

  $('.green .next').click(function(){
    fadeOptions();
    return false;
  });


  /*
   *  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.");
    }
  });


  $(".view_images").click(function(){
    $('a.lightbox-enabled:first').trigger('click');
    return false;
  });

  /*
  $("#prod-description").css({height:'190px', overflow:'hidden'});
  $("#prod-description").jScrollPane({
      showArrows: true,
      scrollbarWidth: 10,
      arrowSize: 10
  });
  */

  /*
   *  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.show(500);
    } else {
      HidePriceList();
    }
  });

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

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


});


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