$(function() {
	// Floatbox
	$("#webshop p.title, .productimg").click(function () {
		var thisURL = "system/getProductInfo2.php?product="+this.id;
		getAXAH2(thisURL,'boxcontent');
	//	jQuery.get( thisURL, thisURL3, setPosition(data), "html" )
		//var windowWidth=$(window).width();
		var boxWidth=$("#floatbox").width();
		var boxMLeft = "-" + (boxWidth/2) + "px";
		//var boxHeight=$("#floatbox").height();
		//var boxMTop = "-" + (boxHeight/2) + "px";
		
		$("#floatbox").css({'marginLeft' : boxMLeft});
		
		
	
	//	$("#floatbox").css({'left' : '100px'});
	//	$("#floatboxbg").css({'left' : '0'});
	});
	
	$("#closeFB").click(function () {
		$("#floatbox").hide();
		$("#floatboxbg").hide();
		//$("#floatbox").fadeOut("fast");
		//$("#floatboxbg").fadeOut("fast");
	});
	$("#floatboxbg").click(function () {
		$("#floatbox").hide();
		$("#floatboxbg").hide();
		//$("#floatbox").fadeOut("fast");
		//$("#floatboxbg").fadeOut("fast");
	});
	
});

function setPosition() {
	//$("#boxcontent").html(data);
	var boxHeight=$("#floatbox").height();
	var boxMTop = "-" + (boxHeight/2) + "px";
	$("#floatbox").css({'marginTop' : boxMTop});
	
	$("#floatbox").show();
	$("#floatboxbg").show();
	//$("#floatbox").fadeIn("fast");
	//$("#floatboxbg").fadeIn("fast");
}

function getAXAH2(url,elementContainer){
	//document.getElementById(elementContainer).innerHTML = '<img src=\"/loading.gif\" alt=\"Laddar\">';
	var theHttpRequest = getNewHttpObject();
	theHttpRequest.onreadystatechange = function() {processAXAH(elementContainer);};
	theHttpRequest.open("GET", url);
	theHttpRequest.send(false);

		function processAXAH(elementContainer){
		   if (theHttpRequest.readyState == 4) {
			   if (theHttpRequest.status == 200) {
				   document.getElementById(elementContainer).innerHTML = theHttpRequest.responseText;
				   setPosition();
			   } else {
				   document.getElementById(elementContainer).innerHTML="error";
			   }
		   }
		}

}
