function searchResultsAjax(isGECA, categoryID, brandID, page)
{
	var url = "search_results2.php?isGECA=" + isGECA + "&categoryID=" + categoryID + "&brandID=" + brandID + "&page=" + page;

//	alert(url);
	var request = new Request.JSON( {
		url: url,
		method: 'get', 
		onComplete: function (jsonObj) {	
			updateProducts(jsonObj);
			$(brandID).fade('in');
		},
		onRequest: function (jsonObj)	{
			$(brandID).fade('out');			
			loading($(brandID));		
		},		
		onFailure: function (jsonObj) {
			alert('failed');
		},		
		onException: function (e,e2) {
//			alert('exception');
		},
		onCancel: function() {
//			alert('it was canceled');
		}	
	}).send();
}

function loading(brandID)
{	
	content = "";
	
	for (i=0; i<4; i++)
	{
		content += "<div class=\"loading\">\n";
		content += "<img src='images/mozilla_giallo.gif' alt=''>";
		content += "</div>\n";
	}
	
//	alert(brandID);
	brandID.innerHTML = content;
	
}


function updateProducts(jsonObj)
{
	brandID = jsonObj.brandID;	

	products = jsonObj.products;

	content = "";
	products.each(function(product) {						   
		content+= getProductDetails(product);						   		
		
	});	
	
	document.getElementById(brandID).innerHTML = content;
}

function getProductDetails(product)
{
	
	content = "<div class=\"productWrap\">\n";

		content += "<div class=\"productImage\"><table width=\"138\" height=\"138\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td height=\"138\" align=\"center\" valign=\"middle\">\n";
				content += "<a href=\"details.php?id=" + product.ID + "\">\n";
						content += "<img src=\"product_images/thumb/" + product.filename + "\" alt=\"" + product.title + "\"  border=\"0\" />\n";
				content += "</a></td></tr></table>\n";
				
		content += "</div>\n";
		
		content += "<div class=\"productTitle\">\n";
				content += "<a href=\"details.php?id=" + product.ID + "\">\n";
						content += product.title +"</a>\n"; 
		content += "</div>\n";		
		
	content += "</div>\n";		
	
	return content;
}

$(function(){

	showPop = function(t,e)
	{ 
				//alert("e.pageX: " + e.pageX + ", e.pageY: " + e.pageY); 
		if (e.pageX || e.pageY) {
			_left = e.pageX;
			_top = e.pageY;
		}
		else if (e.clientX || e.clientY) {
			_left = e.clientX + document.body.scrollLeft;
			_top = e.clientY + document.body.scrollTop;
						
		}

				//_top = (e.pageY+10)+"px";
				//_left = (e.pageX+10)+"px";
				_src = ($(t).attr("xlink"));
				
				$("#popdiv").html("<img src="+ _src +" />");
				$("#popdiv").css( { 'display':'block', 'top': _top, 'left': _left});
				//alert($("#popdiv").css());
	};
	
	movePop = function(e)
	{
				
		if (e.pageX || e.pageY) {
			_left = e.pageX;
			_top = e.pageY;
		}
		else if (e.clientX || e.clientY) {
			_left = e.clientX + document.body.scrollLeft;
			_top = e.clientY + document.body.scrollTop;
						
		}				//_top = e.pageY;
				//_left = e.pageX;
				//$("#popdiv").html("<img src="+ _src +" />");
				$("#popdiv").css( { 'top': _top, 'left': _left});
				//alert($("#popdiv").css());
	}
	
	hidePop = function()
	{
			$("#popdiv").css( { 'display':'none'});
	}
});


