$(document).ready(function() {
  $("#productsearch").focus(function() {
    if ($(this).val() == "Search Products...") {
      $(this).val("");
    }
  }).blur(function() {
    if ($(this).val() == "") {
      $(this).val("Search Products...");
    }
  }).keyup(function(e) {
    var keycode = e.keyCode;
    if (timeout) clearTimeout(timeout);
    switch(keycode) {
      case 27:
        $("#searchresults").hide().html("");
        break;
      default:
        if ($(this).val().length > 2) {
          var timeout = setTimeout('search()', 500)
        } else {
          $("#searchresults").hide().html("");
        }
    }
  });
  $(".searchresult").live("mouseover", function() {
    $(this).children(".searchresulttitle").animate({"opacity" : 0}, "fast");
  }).live("mouseout", function() {
    $(this).children(".searchresulttitle").animate({"opacity" : 0.75}, "fast");
  }).live("click", function() {
    document.location.href = $(this).children("input:hidden").val();
  });
  
  $("#chooseregion").click(function() {
    var offset = $("#chooseregionribboncontainer").position();
    var crwidth = $("#chooseregionribboncontainer").width()-20;
    $("#regionchooser").toggle().css({"left": offset.left + 90 + 19, "width": crwidth + "px"});
  });
  
    $(".homestyle").hover(function() {
        $(this).children(".homestyledesc").stop().animate({"top": "177px"}, "fast");
        $(this).children(".homestylefade").stop().animate({"opacity": 0.5}, 200);
    },function() {
        $(this).children(".homestyledesc").stop().animate({"top": "355px"}, "fast");
        $(this).children(".homestylefade").stop().animate({"opacity": 0}, 200);
    });
  
  //--- Accordian
  $("#accordion").accordion({
    event: "mouseover"
  });

});

function search() {
  $("#searchresults").show().load("/_inc/search.php", { "q": $("#productsearch").val()});
}

