
	jQuery( function($) {
		
		
		// set up a new Search Results for each refinableProductsContainer
		var sections = [];
		var allResults = [];
		
		$(".refinableProductsContainer").each(function() {
			var section = new SearchResults($(this).find(".product"), $(this), showNoProducts);
			sections.push(section);
			allResults = allResults.concat(section.results);
		});
		
		SearchResults.initFilterOptions(allResults);
		
		function showNoProducts() {
			
			var showMsg = true;
			$.each(sections, function(i, section) {
				if (this.visibleCount() > 0) {
					showMsg = false;
				}
			});
			
			if (showMsg) {
				$("#noProducts").fadeIn(SPEED_FADE);
			} else {
				$("#noProducts").fadeOut(SPEED_FADE);
			}
		}

		
		
	
	
		$('.refinableProductsContainer .productImage').tooltip({
			track: true,
			delay: 0,
			showURL: false,
			showBody: " - ",
			extraClass: "productFeaturesToolTip",
			bodyHandler: function() { 
				var parts = $(this).attr("rel").split(" -- ");
						
				//var attr = parts[2] ? JSON.parse(parts[2]) : [];
				
				var sortingData = JSON.parse($(this).parents(".product").find(".sortingData").val());
	
				
				var toolTip = "<h3>" + parts[0] + "</h3>" +
				(parts[1] ? "<div class='shortDesc'>" + parts[1] + "</div>" : "");
				
				features = sortingData.features;
				
				if (features.length) {
					toolTip = toolTip + "<table cellpadding='0' cellspacing='0'>";

					for (var i=0; i<features.length; i++) {
						feature = features[i];
							
						toolTip = toolTip +
							"<tr>" +
								"<td class='nameCell'>" + feature.name + "</td>" +
								"<td class='valueCell'>" + feature.value + "<td>" +
							"</tr>"
					}
					toolTip = toolTip + "</table>";
					
				}
				return toolTip;
	       		//return $($(this).attr("href")).html(); 
    		}
		});
		
		
		$('.product a:not(.productImage)').tooltip({
			track: true,
			delay: 0,
			showURL: false,
			showBody: " - "
		});
		
		$('.product .compare').tooltip({
			track: true,
			delay: 0,
			showURL: false,
			showBody: " - "
		});
		
		$('.product .compare').bind("click", function(){
			var add = $(this).attr("checked");
			
			$("#compareSummary").show();
	
			if (add) {
				$(this).effect("transfer",{to: $("#compareSummary")},1000);
			} else {
				$("#compareSummary").effect("transfer",{to: $(this)},1000);
			}
					
			$.get('/cgi-bin/compare.pl',
				{
					com			:	(add ? 'add' : 'delete'),
					id			:	$(this).attr("rel"),
					time		:	(new Date()).getTime()
				},
				function (data) {
					$("#basketSummary").basketSummary.update();	// update the basket summary
				}
			);

		});
			
	});

