$(function(){

	// faq and special offers boxes
	$(".promo-box").addClass('js-enabled').click(function(){
		window.location = $(this).find('a').attr("href");
	});

	// sifr
	if(typeof sIFR == "function") {
		sIFR.replaceElement(named({sSelector:".main-content h1", sColor: "#191919", sFlashSrc:"/assets/flash/tradegothic.swf",sWmode:'transparent'}));
	}

	// FIND YOUR PRODUCT

	fyi = document.getElementById("fypIndustry");
	if(fyi)  fyi.selectedIndex = 0;

	// industry
	$("#fypIndustry").change(function(){
      $("#fyp-ind-plus").addClass("plus-wait");
			$.ajax({
				type: "GET",
				url: "/search/fyp_categories/"+$("#fypIndustry").val(),
				success: function(d){
					$("#fyp-category").html(d);
  		    $("#fyp-brand").load("/search/fyp_brands/");
  				$("#fyp-product").load("/search/fyp_products/");
					$("#fyp-ind-plus").removeClass("plus-wait");
				}
			});
   });

	// submit
	$("#fypSubmit").click(function(){
      fyp_process();
   });

});

// these need to be called by onclick as ie won't play with dynamically changing form elements, even if we use .live(). Lovely.
function change_category() {
		$("#fyp-cat-plus").addClass("plus-wait");
		$.ajax({
			type: "GET",
			url: "/search/fyp_brands/"+$("#fypIndustry").val()+"/"+$("#fypCategory").val(),
			success: function(d){
				$("#fyp-brand").html(d);
				$("#fyp-product").load("/search/fyp_products");
				$("#fyp-cat-plus").removeClass("plus-wait");
			}
		});
}

function change_brand() {
	$("#fyp-brand-plus").addClass("plus-wait");
	$.ajax({
		type: "GET",
		url: "/search/fyp_products/"+$("#fypIndustry").val()+"/"+$("#fypCategory").val()+"/"+$("#fypBrand").val(),
		success: function(d){
			$("#fyp-product").html(d);
			$("#fyp-brand-plus").removeClass("plus-wait");
		}
	});
}

function change_product() {
	fyp_process();
}

// this is shared
function fyp_process() {
	window.location = "/search/fyp/"+$("#fypIndustry").val()+"/"+$("#fypCategory").val()+"/"+$("#fypBrand").val()+"/"+$("#fypProduct").val();
}