function emailQuotation() {
  $('#fm-email').focus(function() {
    if ($(this).val() == 'Enter Your Email Address For A Price' || $(this).val() == 'Please Enter A valid Email Address') {
      $(this).val('');
      if ($(this).hasClass('error'))
        $(this).removeClass('error');
    }
  });
  $('#fm-email').blur(function() {
    if ($(this).val() == '')
      $(this).val('Enter Your Email Address For A Price');
  });
  $('#emailForm').submit(function(e) {
    e.preventDefault();
    var regex = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    if(regex.test($('#fm-email').val()) == false) {
      $('#fm-email').addClass('error');
      $('#fm-email').val('Please Enter A valid Email Address')
                  return false;
    }
    else {
      var urlString = "/price.php?prod-id=" + $('#fm-prod-id').val() + "&email=" + $('#fm-email').val();
      $.get(urlString + "&ajax=1", function(data){
        $('#emailForm').html('<p class="spacedT padded red">A price for this product has been sent to your inbox.</p>');
      });
    }
  });
}









$(document).ready( function() {
  emailQuotation();
  
  var searchFilter = 0;
  $("#searchFilter a").click(function() {
    if (searchFilter == 0) {
      $("#searchFilter").animate({width: '309'}, 750);
      searchFilter = 1;
    }
    else if (searchFilter == 1) {
      $("#searchFilter").animate({width: '35'}, 750);
      searchFilter = 0;
    }
  });
  

  
    
  $("#myContent h1, h1.notNeeded").hide();
 
  $("a.blank").click(function(e) {e.preventDefault();window.open($(this).attr("href"));});
  
  
  
  

  $('.styleProducts.fab30').hide(); $('#fab30').show();
  var leftHinged = $('.styleProducts.fab30').children('li.hin-left');
  var rightHinged = $('.styleProducts.fab30').children('li.hin-right');
  $('#productColours').html(rightHinged);


  function productColours(e) {
    e.preventDefault();
    $('#fab30 h2').html($(this).clone().attr('title'));
    $('#buyNow').html($(this).parent('li').clone().children('form'));
    $('#buyNow form').append('<p class="price alignRight"><label>&pound;' + $("#buyNow form input[name='price']").val() + '<span class="small"> Inc VAT &amp; FREE Delivery</span></label><input type="submit" value="Add To Shopping Basket &raquo;"></p>');
    $('#fab30 #image').css('background', 'url(' + $(this).children('img').attr('src') + ') no-repeat center center');
  }
  
  function productChange() {
    if ($("#fab30 input[name='hinged']:checked").val() == 'left')
      $('#productColours').html(leftHinged);
    else 
      $('#productColours').html(rightHinged);
    $('#productColours a').click(productColours);
    $('#fab30 h2').html($('#productColours a:first').clone().attr('title'));
    $('#buyNow').html($('#productColours form:first').clone());
    $('#buyNow form').append('<p class="price alignRight"><label>&pound;' + $("#buyNow form input[name='price']").val() + '<span class="small"> Inc VAT &amp; FREE Delivery</span></label><input type="submit" value="Add To Shopping Basket &raquo;"></p>');
    $('#fab30 #image').css('background', 'url(' + $('#productColours img:first').attr('src') + ') no-repeat center center');
  }
  
  productChange();
  $('#productColours a').click(productColours);
  $("#fab30 input[name='hinged']").change(productChange);


  
  $( "#tabs" ).tabs();

  

  
  $('.basket form input[type="submit"]').hide();
  $('.basket form a').click(function(e) {e.preventDefault(); window.location=$(this).attr("href");});
  $('.basket form input[type="radio"]').change(function() {$(this).parents('form').submit();});

  
//  $('.makeList li div').css('height', '0px');
//  $('.makeList li div').css('opacity', '.75');
//  $('.makeList li').hoverIntent(
//    function() {$(this).children('div').animate({height:100}, 750);},
//    function() {$(this).children('div').animate({height:0}, 750);}
//  );


  var autocompleteJSON = function(raw) {
      var json= typeof(raw) === "array" ? raw : raw.resultSet;
      var parsed = [];
      for (var i=0; i <json.length; i++) {
         var row =json[i];
         parsed.push({
             data: row,
            value: row["text"] + ' [' + row["url"] + ']',
           result: row["text"]
         });
      }
      return parsed;
   }; 

  $('#searchModel').autocomplete('/search.php?ajax=1',
    { 
      dataType: "json",
      parse: autocompleteJSON,
      scrollHeight: 620,
      formatItem: function(row) { return row["text"] },
      selectFirst: false
    }
  ).result(function(event, item) {
      location.href = item["url"];
  }); 
  
  
});
