$(function(){
  $("select#fabric").change(function(getcolour){
	$("quote").html("");
    $.get("ajaxincludes/selectcoltest.php",{"q": $(this).val(), "ajax": 'true'}, function(colours){
      $("#colour").html(colours);
    })
  })

  $("#colour").change(function(insertimage){
  var fab = $("#fabric").val().replace(/[\s\xA0]+/g,'');
  var col = $("#colour").val().replace(/[\s\xA0]+/g,'');
  var src = "http://www.easygreenstore.co.uk/images/energy-saving-blinds/"+fab+"/"+col+".jpg";
  var img = "<img style='background: url("+src+");width:225px;' src='images/sale_overlay.png' alt='blind fabric preview' />";
  $("#imagePreview").html(img+"<br /><a href='colour-chooser.php'><img src='images/colour-chooser-mini.png' alt='blind colour chooser' style='margin-top:10px;' /></a>");
	if ($("#width").val().length > 0 && $("#drop").val().length > 0 ) { 
	  $.get("ajaxincludes/quote.php",{"f": $("#fabric").val().replace(/[\s\xA0]+/g,''), "c": $("#colour").val().replace(/[\s\xA0]+/g,''), "w": $("#width").val(), "d": $("#drop").val(), "ajax": 'true'}, function(getquote){
      $("#quote").html(getquote);
      })
    }
  })

  $(".dimensions").keyup(function(refreshquote){
  var w = $("#width").val().replace(/[\s\xA0]+/g,'');
  var d = $("#drop").val().replace(/[\s\xA0]+/g,'');
    if (w.length == 0 && d.length == 0 ) { $("#quote").html(""); }
    else if (3 > w.length > 0 || 3 > d.length > 0) { $("#quote").html("<img src='images/ajax-loader.gif' />"); }
    else if (w.length >= 3 && d.length >= 3) { 
 	  $.get("ajaxincludes/quote.php",{"f": $("#fabric").val().replace(/[\s\xA0]+/g,''), "c": $("#colour").val().replace(/[\s\xA0]+/g,''), "w": $("#width").val(), "d": $("#drop").val(), "ajax": 'true'}, function(getquote){
        $("#quote").html(getquote);
      })
	}
  })

  $("#advSub").hide();
	$('#arrow').toggle(
      function(){
	    $('#advSub').slideToggle('fast');
	    $('#arrowImage').attr('src','images/arrow_up.gif');
	  }, function() {
	    $('#advSub').slideToggle('fast');
	    $('#arrowImage').attr('src','images/arrow_down.gif');
	  }
	);
})