var transitionStart = true;
var browser = navigator.userAgent;
var player, playerFlv;
var xCoord, yCoord, videoFixed, videoHolder, typeFixed, lengthFixed, typeMod, lengthMod, quantityMod, cookies, cookie, basketQuantity, basketDetailsMetric, basketDetailsImperial, basketTemp, basketArrayMetric, basketArrayImperial, basketCheckoutTemp, basketCheckout, basketCounter, equals, typeFound, atFound, slashFound, dash1Found, dash2Found, quantityTemp, quantityFinal, dragQuantityHolder, dragBasketDetailsHolder, updateDetails, email, ref1, ref2, ref3, ref4, vPos, hPos, contentCheck, confirmation, quantityCheck, dash, slash, fractionFixed, fractionFixedTemp, fractionCounter, fractionCounter2, numeratorCounter, numeratorArray, numerator, denominatorCounter, denominatorArray, denominator, dot, compare, firstChar, restChar, gcd;

$(window).load(function() {
	numeratorArray = [];
	denominatorArray = [];
						
	$("#bar2").css("visibility", "visible");
	if (browser.indexOf("Firefox") != -1 || browser.indexOf("Opera") != -1) {		
		$("#Body").css("width", "333px");
	}
	
    cookies = document.cookie.split(/[; ]+/);
    for (var i = 0; i < cookies.length; i++) {
        cookie = cookies[i].substring(0,cookies[i].indexOf('='));
        if (cookie == "basketQuantity") {
			basketQuantity = cookies[i];
			equals = basketQuantity.lastIndexOf("=");
			basketQuantity = basketQuantity.substring(equals+1, basketQuantity.length);
        }
		if (cookie == "basketDetailsMetric") {
			basketDetailsMetric = cookies[i];
			equals = basketDetailsMetric.lastIndexOf("=");
			basketDetailsMetric = basketDetailsMetric.substring(equals+1, basketDetailsMetric.length);
        }
		if (cookie == "basketDetailsImperial") {
			basketDetailsImperial = cookies[i];
			equals = basketDetailsImperial.lastIndexOf("=");
			basketDetailsImperial = basketDetailsImperial.substring(equals+1, basketDetailsImperial.length);
        }
		if (cookie == "email") {
			email = cookies[i];
			equals = email.lastIndexOf("=");
			email = email.substring(equals+1, email.length);
        }
    }
	if (basketQuantity == null) {
		basketQuantity = 0;
		basketDetailsMetric = "";
		basketDetailsImperial = "";
	}
	$("#basketQuantity").val(basketQuantity);
	
	interval();
	
	quantityCheck = false;
	contentCheck = false;
	
	if (browser.indexOf("Firefox") != -1 || browser.indexOf("Opera") != -1) {	
		document.captureEvents(Event.MOUSEMOVE);
	}
	document.onmousemove = getMouseXY;
	
	updateDetails = false;
});

function getMouseXY(m){
	if (contentCheck == true) {
		if (browser.indexOf("Firefox") == -1 && browser.indexOf("Opera") == -1) {	
			xCoord = event.clientX;
			yCoord = event.clientY;
		}	
		else {
			xCoord = m.clientX;
			yCoord = m.clientY;
		}  
		if (!document.body.scrollTop) {
			xCoord += document.documentElement.scrollLeft;	
			yCoord += document.documentElement.scrollTop;
		}
		else {
			xCoord += document.body.scrollLeft;	
			yCoord += document.body.scrollTop;	
		}  	
	}
}

function frameSwitch() {	
    var $active = $('#bar2 IMG.active');

    if ( $active.length == 0 ) $active = $('#bar2 IMG:last');

    // use this to pull the images in the order they appear in the markup
    var $next =  $active.next().length ? $active.next()
        : $('#bar2 IMG:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 4000, function() {
            $active.removeClass('active last-active');
	});
	interval();
}

function interval() {
	if (transitionStart == true) {
		transitionStart = false;		
		setTimeout( "frameSwitch()", 3000 );
	}
	else {
    	setTimeout( "frameSwitch()", 7000 );
	}
}

$(function() {  
	$("#midContent2").mouseover(function() {
		contentCheck = true;
	});
	$("#midContent2").mouseout(function() {
		contentCheck = false;
	});
	$("#subOver").mouseover(function() {
		$("#subMenu").css("visibility", "visible");
	});
	$("#subOver").mouseout(function() {
		$("#subMenu").css("visibility", "hidden");
	});
	$("#subMenu").mouseover(function() {
		$("#subMenu").css("visibility", "visible");
	});
	$("#subMenu").mouseout(function() {
		$("#subMenu").css("visibility", "hidden");
	});
	
	$("#popupContact #emailSubmit").click(function() {
		var to, from, subject, body, data, ajaxRequest;
	
		to = $("#to").val();
		from = $("#from").val();
		subject = $("#subject").val();
		body = $("#body").val();

		if (from.indexOf("@") != -1 && from.indexOf(".") != -1) {	
			$("#popupContact input").attr("disabled", "disabled");
			$("#popupContact textarea").attr("disabled", "disabled");
			$("#innerBar #emailSubmit").attr("disabled", "disabled");
		
			while (body.indexOf("\n") != -1) {
				body = body.replace("\n", "<br />");		
			}			
			to = to.replace(/ /g, "__");
			from = from.replace(/ /g, "__");
			subject = subject.replace(/ /g, "__");			
			body = body.replace(/ /g, "__");			
			
			data = "?to="+to+"&from="+from+"&subject="+subject+"&body="+body;
		
			ajaxRequest = new XMLHttpRequest();	
			
			ajaxRequest.open("GET", "contacts.php"+data);
			
			ajaxRequest.onreadystatechange = function() {
				if (ajaxRequest.readyState == 4) {
					alert(ajaxRequest.responseText);
					
					$("#popupContact input").removeAttr("disabled");
					$("#popupContact textarea").removeAttr("disabled");
					$("#innerBar #emailSubmit").removeAttr("disabled");
					
					$("#to").val($("#to").attr("defaultValue"));
					$("#from").val($("#from").attr("defaultValue"));
					$("#subject").val($("#subject").attr("defaultValue"));
					$("#body").val($("#body").attr("defaultValue"));
				}
			}	
			ajaxRequest.send(null);		
		}
		else {
			alert("The email address entered is invalid!");
		}
	});
	
	$("#basketQuantityHolder").mouseover(function() {											
		$("#basketClick").css("color","#1BAACC");
	});
	$("#basketQuantityHolder").mouseout(function() {
		$("#basketClick").css("color","#666");
	});
	$("#basketQuantity").mouseover(function() {											
		$(this).css("cursor","pointer"); 
		$(this).css("cursor","hand"); 
		$("#basketClick").css("color","#1BAACC");
	});
	$("#basketQuantity").mouseout(function() {
		$("#basketClick").css("color","#666");
	});
	$("#basketQuantity").focus(function() {
		$(this).blur();
	});
	$("#basket").mouseover(function() {											
		$("#basketClick").css("color","#1BAACC");
	});
	$("#basket").mouseout(function() {
		$("#basketClick").css("color","#666");
	});
	$("#basket-a").mouseup(function() {
		if (basketQuantity != 0) {
			if ($("#basketDetailsHolder").css("visibility") == "hidden") {
				$("#basketDetailsHolder").css("margin-top", document.getElementById("midContent1").offsetTop);
				$("#basketDetailsHolder").css("margin-left", document.getElementById("midContent1").offsetLeft+30);
				$("#basketDetailsHolder").css("visibility","visible");		
			}
			showDetails();
		}
		else {
			alert("The query basket is empty!");
		}
	});
	$("#basketDetailsHolder").mouseover(function() {
		contentCheck = true;
	});
	$("#basketDetailsHolder").mouseout(function() {
		contentCheck = false;
	});
	$("#email").focus(function() {
		$(this).select();
	});
	$("#email").keyup(function() {
		email = $(this).val();
		document.cookie = "email=" + email;
	});
	$("#checkoutSubmit").mouseup(function() {
		if ($("#email").val().indexOf("@") != -1 && $("#email").val().indexOf(".") != -1) {
			data = "?to=iain@clydefasteners.com&from="+$("#email").val()+"&subject=Tee Slot Bolts Query&metric="+basketDetailsMetric+"&imperial="+basketDetailsImperial;			
			
			ajaxRequest = new XMLHttpRequest();	
			
			ajaxRequest.open("GET", "query.php"+data);
			
			ajaxRequest.onreadystatechange = function() {
				if (ajaxRequest.readyState == 4) {
					if (ajaxRequest.responseText == "Message Sent Successfully!") {
						$("#basketDetailsHolder").css("visibility","hidden");
						
						document.cookie = "basketQuantity='' ;expires=Thu, 01-Jan-1970 00:00:01 GMT";
						document.cookie = "basketDetailsMetric='' ;expires=Thu, 01-Jan-1970 00:00:01 GMT";
						document.cookie = "basketDetailsImperial='' ;expires=Thu, 01-Jan-1970 00:00:01 GMT";
						document.cookie = "email='' ;expires=Thu, 01-Jan-1970 00:00:01 GMT";
						
						$("#basketQuantity").val(0);
						basketQuantity = 0;
						basketDetailsMetric = "";
						basketDetailsImperial = "";
						email = "Enter your email address here...";
					}
					alert(ajaxRequest.responseText);
				}
			}	
			ajaxRequest.send(null);	
		}
		else {
			alert("Please enter a valid email address!");
		}
	});
	
	$("#username").bind("keypress", function(e) { 
        if(e.keyCode == 13){ 
			login();
        } 
	});
	$("#password").bind("keypress", function(e) { 
        if(e.keyCode == 13){ 
			login();
        } 
	});
	$("#login").mouseup(function() {
		login();
	});
});

function login() {
	if ($("#username").val() == "") {
		alert("Please enter a username!");
	}
	if ($("#password").val() == "") {
		alert("Please enter a password!");
	}
	if ($("#username").val() != "" && $("#password").val() != "") {
		data = "?username="+$("#username").val()+"&password="+$("#password").val();
		
		ajaxRequest = new XMLHttpRequest();
		
		ajaxRequest.open("GET", "login.aspx"+data);
		
		ajaxRequest.onreadystatechange = function() {
			if (ajaxRequest.readyState == 4) {
				if (ajaxRequest.responseText == "found") {
					document.cookie = "loggedIn=true";
					window.location = "adminMetric.aspx";
				}
				else {
					alert("Incorrect login details!");
				}
			}
		}	
		ajaxRequest.send(null);	
	}
}

function videos(video) {
	if ($("#video").css("visibility") == "hidden") {
		$("#video").css("margin-top", document.getElementById("midContent2").offsetTop-180);
		$("#video").css("margin-left", document.getElementById("midContent2").offsetLeft+30);
		$("#video").css("visibility","visible");		
	}
	
	$("#video").css("visibility", "visible");
	
	videoFixed = video;
	while(videoFixed.indexOf("__") != -1) {
		videoFixed = videoFixed.replace("__", " ");
	}
	
	$("#videoTitle").html(videoFixed);
	
	playerFlv = new SWFObject("player.swf", "myplayer", "500px", "400px", "9");
	playerFlv.addVariable("screencolor", "white");
	playerFlv.addParam("allowfullscreen","true");
	playerFlv.addVariable("file", "videos/"+videoFixed+"&skin=flash/clydefast.swf");
	playerFlv.write("videoInt");

	player = document.getElementById("myplayer");
	
	videoHolder = DragHandler;
	videoHolder.attach(document.getElementById("video"));
	
	setTimeout("listeners()", 1000);
}

function listeners() {	
	player.sendEvent("PLAY","true");
}

function videoClose() {
	$("#videoInt").html("");
	$("#video").css("visibility", "hidden");
}

function resizeContent(cols, rows) {
	$("#contentsInt").css("width", (cols*106)+(cols*8)+(cols*2)+"px");
	$("#contentsInt").css("height", (rows*16)+(rows*4)+(rows*2)+"px");
	
	if (browser.indexOf("Firefox") != -1 || browser.indexOf("Opera") != -1 || browser.indexOf("Safari") != -1) {
		ref1=document.getElementById('titles2');
		ref2=document.getElementById('contents');
		vPos=ref2.scrollTop;
		
		ref3=document.getElementById('titles');
		ref4=document.getElementById('contents');
		hPos=ref4.scrollLeft;
		
		scrollTa();
	}
	else {
		addScrollSynchronization(document.getElementById("titles2"), document.getElementById("contents"), "vertical");
		addScrollSynchronization(document.getElementById("titles"), document.getElementById("contents"), "horizontal");
	}
}

// This is a function that returns a function that is used in the event listener
function getOnScrollFunction(oElement) {
	return function () {
		if (oElement._scrollSyncDirection == "horizontal" || oElement._scrollSyncDirection == "both")
			oElement.scrollLeft = event.srcElement.scrollLeft;
		if (oElement._scrollSyncDirection == "vertical" || oElement._scrollSyncDirection == "both")
			oElement.scrollTop = event.srcElement.scrollTop;
	};
}

// This function adds scroll syncronization for the fromElement to the toElement
// this means that the fromElement will be updated when the toElement is scrolled
function addScrollSynchronization(fromElement, toElement, direction) {
	removeScrollSynchronization(fromElement);	
	fromElement._syncScroll = getOnScrollFunction(fromElement);
	fromElement._scrollSyncDirection = direction;
	fromElement._syncTo = toElement;
	toElement.attachEvent("onscroll", fromElement._syncScroll);
}

// removes the scroll synchronization for an element
function removeScrollSynchronization(fromElement) {
	if (fromElement._syncTo != null)
		fromElement._syncTo.detachEvent("onscroll", fromElement._syncScroll);

	fromElement._syncTo = null;;
	fromElement._syncScroll = null;
	fromElement._scrollSyncDirection = null;
}

function scrollTa() {	
	if(ref2.scrollTop!=vPos) {
		vPos=ref1.scrollTop=ref2.scrollTop;
	}
	if(ref4.scrollLeft!=hPos) {
		hPos=ref3.scrollLeft=ref4.scrollLeft;
	}
	setTimeout("scrollTa()", 1);
}

function quantityShow(length, type, superType) {
	typeFixed = type.replace("__", " / ");
	typeFixed = typeFixed.replace("_point_", ".");
	lengthFixed = length;
	if (superType == "Imperial") {
		typeFixed = toFract(typeFixed, "type");
		lengthFixed = toFract(lengthFixed, "length");
	}

	$("#quantityHolder").css("margin-top", (yCoord-100)+"px");
	$("#quantityHolder").css("margin-left", (xCoord)+"px");
	
	$("#quantityHolder").html("<button id='quantityClose' onmouseover='quantityOver()' onmouseout='quantityOut()' onmouseup='quantityClose()' hidefocus='true'></button><span style='font-size:11px;'>How many of the <span style='font-weight:bold;'>" + typeFixed + " - " + lengthFixed + "</span> Tee Slot<br />Bolts do you wish to add to the query basket?</span><br /><input id='quantity' style='margin-top:7px;' type='text' value='Enter quantity here...' onmouseover='quantityOver()' onmouseout='quantityOut()' />&nbsp;<button onmouseover='quantityOver()' onmouseout='quantityOut()' onmouseup=quantityUpdate('"+length+"','"+type+"',null,'"+superType+"')>Add to Basket</button>");
	$("#quantityHolder").css("visibility", "visible");
	$("#quantity").focus();
	$("#quantity").select();
	
	dragQuantityHolder = DragHandler;		
	dragQuantityHolder.attach(document.getElementById("quantityHolder"));
}

function quantityShowMod(length, type, quantity, superType) {
	typeFixed = type.replace("__", " / ");
	typeFixed = typeFixed.replace("_point_", ".");
	lengthFixed = length;
	if (superType == "Imperial") {
		typeFixed = toFract(typeFixed, "type");
		lengthFixed = toFract(lengthFixed, "length");
	}

	$("#quantityHolder").css("margin-top", (yCoord-100)+"px");
	$("#quantityHolder").css("margin-left", (xCoord)+"px");
	
	$("#quantityHolder").html("<button id='quantityClose' onmouseover='quantityOver()' onmouseout='quantityOut()' onmouseup='quantityClose()' hidefocus='true'></button><span style='font-size:11px;'>Enter the desired quantity of <span style='font-weight:bold;'>" + typeFixed + " - " + lengthFixed + "</span><br />Tee Slot Bolts for the query basket?</span><br /><input id='quantity' style='margin-top:7px;' type='text' value='"+quantity+"' onmouseover='quantityOver()' onmouseout='quantityOut()' />&nbsp;<button onmouseover='quantityOver()' onmouseout='quantityOut()' onmouseup=quantityUpdate('"+length+"','"+type+"','"+quantity+"','"+superType+"')>Modify Basket</button>");
	$("#quantityHolder").css("visibility", "visible");
	$("#quantity").focus();
	$("#quantity").select();
	
	updateDetails = true;
	
	dragQuantityHolder = DragHandler;	
	dragQuantityHolder.attach(document.getElementById("quantityHolder"));
}

function toFract(fraction, superType) {	
	fractionFixed = fraction;	
	fractionFixedTemp = fractionFixed;

	if (fractionFixed.indexOf(".") != -1) {
		if (superType == "type") {
			slash = fractionFixed.indexOf(" / ");
			fractionFixedTemp = fractionFixed.substring(0, slash-1);	
		}
		
		dot = fractionFixedTemp.indexOf(".");			
		compare = true;		
		
		if (fractionFixedTemp.substring(dot+1, fractionFixedTemp.length).length > 1) {	
			dot += 1;
			firstChar = fractionFixedTemp.substring(dot, dot+1);
			dot += 1;								
			while (dot < fractionFixedTemp.length) {
				restChar = fractionFixedTemp.substring(dot, dot+1);
				if (firstChar != restChar) {
					compare = false;
				}
				dot += 1;
			}	
		}	
		
		dot = fractionFixedTemp.indexOf(".");
	
		if (compare == true && fractionFixedTemp.substring(dot+1, fractionFixedTemp.length).length > 1) {	
			numerator = 10 * ("0." + fractionFixedTemp.substring(dot+1, fractionFixedTemp.length).length);
			denominator = 1 * ("0." + fractionFixedTemp.substring(dot+1, fractionFixedTemp.length).length);
			
			numerator = Math.round(numerator - denominator);
			denominator = 9;
		}	
		else {
			numerator = fractionFixedTemp.substring(dot+1, fractionFixedTemp.length);
			
			denominator = "1";
			fractionCounter = 1;
			while(fractionCounter <= numerator.length) {
				denominator += "0";
				fractionCounter += 1;
			}
		}
		
		numeratorCounter = 0;
		fractionCounter = numerator;
		while (fractionCounter > 0) {
			if (numerator % fractionCounter == 0) {
				numeratorArray[numeratorCounter] = numerator / fractionCounter;
				numeratorCounter += 1;
			}
			fractionCounter -= 1;
		}
		
		denominatorCounter = 0;
		fractionCounter = denominator;
		while (fractionCounter > 0) {
			if (denominator % fractionCounter == 0) {
				denominatorArray[denominatorCounter] = denominator / fractionCounter;
				denominatorCounter += 1;
			}
			fractionCounter -= 1;
		}
		
		gcd = 1;
			
		fractionCounter = 0;
		while (fractionCounter < numeratorCounter) {
			fractionCounter2 = 0;
			while (fractionCounter2 < denominatorCounter) {
				if ((denominatorArray[fractionCounter2] == numeratorArray[fractionCounter]) && numeratorArray[fractionCounter] > gcd) {
					gcd = numeratorArray[fractionCounter];
				}
				fractionCounter2 += 1;	
			}		
			fractionCounter += 1;		
		}
		
		numerator = numerator / gcd;
		denominator = denominator / gcd;
		
		if (superType == "type") {
			if (fractionFixed.substring(0, dot) > 0) {
				fractionFixed = fractionFixed.substring(0, dot) + "-" + numerator + "/" + denominator + fractionFixed.substring(slash-1, fractionFixed.length);
			}
			else {
				fractionFixed = numerator + "/" + denominator + fractionFixed.substring(slash-1, fractionFixed.length);
			}
		}
		else {
			if (fractionFixed.substring(0, dot) > 0) {
				fractionFixed = fractionFixed.substring(0, dot) + "-" + numerator + "/" + denominator;
			}
			else {
				fractionFixed = numerator + "/" + denominator;
			}
		}
		
		numeratorArray = [];
		denominatorArray = [];
	}	
	
	if (superType == "length") {
		fractionFixed += '"';
	}

	return fractionFixed;	
}

function quantityOver() {
	quantityCheck = true;
}

function quantityOut() {
	quantityCheck = false;
}

function quantityUpdate(length, type, quantity, superType) {
	if (isNaN($("#quantity").val()) == false) {
		confirmation = true;
		if (quantity != null) {
			confirmation = confirm("Are you sure you wish to modify this item?");
		}
		if (confirmation) {
			quantityTemp = quantity;
			
			if (updateDetails == true) {
				if (quantityTemp > parseInt($("#quantity").val())) {
					basketQuantity = parseInt(basketQuantity) - (quantityTemp - parseInt($("#quantity").val()));
				}
				else {
					basketQuantity = parseInt(basketQuantity) + (parseInt($("#quantity").val()) - quantityTemp);
				}
			}
			else {
				basketQuantity = parseInt(basketQuantity) + parseInt($("#quantity").val());
			}
		
			if (superType == "Metric") {
				if (basketDetailsMetric == null) {
					basketDetailsMetric = "";
				}
				if (basketDetailsMetric.indexOf(type + "-" + length) != -1) {
					typeFound = basketDetailsMetric.indexOf(type + "-" + length);
					atFound = basketDetailsMetric.indexOf("-@-", typeFound);
					slashFound = basketDetailsMetric.indexOf("-/-", atFound);
					
					quantityTemp = basketDetailsMetric.substring(atFound+3, slashFound);
					if (updateDetails == true) {
						quantityFinal = parseInt($("#quantity").val());
					}
					else {
						quantityFinal = parseInt(quantityTemp) + parseInt($("#quantity").val());
					}
					basketDetailsMetric = basketDetailsMetric.replace(type + "-" + length + "-@-" + quantityTemp, type + "-" + length + "-@-" + quantityFinal);
				}
				else {		
					basketDetailsMetric += "-/-" + type + "-" + length + "-@-" + parseInt($("#quantity").val()) + "-/-";	
				}
				document.cookie = "basketDetailsMetric=" + basketDetailsMetric;
			}
			else if (superType == "Imperial") {
				if (basketDetailsImperial == null) {
					basketDetailsImperial = "";
				}
				if (basketDetailsImperial.indexOf(type + "-" + length) != -1) {
					typeFound = basketDetailsImperial.indexOf(type + "-" + length);
					atFound = basketDetailsImperial.indexOf("-@-", typeFound);
					slashFound = basketDetailsImperial.indexOf("-/-", atFound);
					
					quantityTemp = basketDetailsImperial.substring(atFound+3, slashFound);
					if (updateDetails == true) {
						quantityFinal = parseInt($("#quantity").val());
					}
					else {
						quantityFinal = parseInt(quantityTemp) + parseInt($("#quantity").val());
					}
					basketDetailsImperial = basketDetailsImperial.replace(type + "-" + length + "-@-" + quantityTemp, type + "-" + length + "-@-" + quantityFinal);
				}
				else {		
					basketDetailsImperial += "-/-" + type + "-" + length + "-@-" + parseInt($("#quantity").val()) + "-/-";	
				}
				document.cookie = "basketDetailsImperial=" + basketDetailsImperial;
			}
			
			document.cookie = "basketQuantity=" + basketQuantity;
			
			$("#basketQuantity").val(basketQuantity);
			$("#quantityHolder").css("visibility", "hidden");
			
			if (updateDetails == true) {
				updateDetails = false;
				showDetails();
			}
		}
	}
	else {
		alert("You have not entered a valid quantity!");
	}
}

function quantityRemove(length, type, quantity, superType) {
	confirmation = confirm("Are you sure you wish to remove this item?");
	if (confirmation) {
		if (superType == "Metric") {
			basketDetailsMetric = basketDetailsMetric.replace("-/-" + type + "-" + length + "-@-" + quantity + "-/-", "");
			document.cookie = "basketDetailsMetric=" + basketDetailsMetric;
		}
		else if (superType == "Imperial") {
			basketDetailsImperial = basketDetailsImperial.replace("-/-" + type + "-" + length + "-@-" + quantity + "-/-", "");
			document.cookie = "basketDetailsImperial=" + basketDetailsImperial;
		}
		basketQuantity -= quantity;
		$("#basketQuantity").val(basketQuantity);
		document.cookie = "basketQuantity=" + basketQuantity;	
		
		if (basketQuantity == 0) {
			document.cookie = "basketQuantity='' ;expires=Thu, 01-Jan-1970 00:00:01 GMT";
			$("#basketDetailsHolder").css("visibility","hidden");
			alert("The query basket is empty!");
		}
		else {
			showDetails();
		}
	}
}

function quantityClose() {
	$("#quantityHolder").html("");
	$("#quantityHolder").css("visibility", "hidden");
	if (dragQuantityHolder != null) {
		dragQuantityHolder.detach(document.getElementById("quantityHolder"));
	}
}

function basketClose() {
	quantityClose();
	$("#basketDetailsInt").html("");
	$("#basketDetailsHolder").css("visibility", "hidden");
	dragBasketDetailsHolder.detach(document.getElementById("basketDetailsHolder"));
}

function showDetails() {	
	basketCheckout = "";
	basketCheckoutEmail = "";
	if (basketDetailsMetric == null) {
		basketDetailsMetric = "";
	}
	if (basketDetailsMetric != "") {
		basketTemp = basketDetailsMetric.substring(3, basketDetailsMetric.length-3);
		basketArrayMetric = basketTemp.split("-/--/-");
		basketCheckout = "<span style='font-size:14px; font-weight:bold; color:#1BAACC;'>Metric</span><br /><br /><table style='width:470px;'><tr align='center' style='font-weight:bold; background-color:#4C95A4;'><td>Type</td><td>Length</td><td>Quantity</td><td>Modify</td><td>Remove</td></tr>";
		basketCounter = 0;
		while (basketCounter < basketArrayMetric.length) {
			basketCheckout += "<tr align='center' style='color:#FFF; background-color:#333;'><td>";
			basketCheckoutTemp = basketArrayMetric[basketCounter].replace("-@-", "</td><td>");
			basketCheckoutTemp = basketCheckoutTemp.replace("-", "</td><td>");
			basketCheckoutTemp = basketCheckoutTemp.replace("__", " / ");	
			basketCheckoutTemp = basketCheckoutTemp.replace("_point_", ".");
			
			dash1Found = basketArrayMetric[basketCounter].indexOf("-");
			dash2Found = basketArrayMetric[basketCounter].indexOf("-@-", dash1Found+1);
			
			typeMod = basketArrayMetric[basketCounter].substring(0, dash1Found);
			lengthMod = basketArrayMetric[basketCounter].substring(dash1Found+1, dash2Found);
			quantityMod = basketArrayMetric[basketCounter].substring(dash2Found+3, basketArrayMetric[basketCounter].length);
			
			basketCheckout += basketCheckoutTemp + "</td><td><button style='font-size:10px;1' onmouseover='quantityOver()' onmouseout='quantityOut()' onmouseup=quantityShowMod('"+lengthMod+"','"+typeMod+"','"+quantityMod+"','Metric')>Modify</button></td><td><button style='font-size:10px;' onmouseover='quantityOver()' onmouseout='quantityOut()' onmouseup=quantityRemove('"+lengthMod+"','"+typeMod+"','"+quantityMod+"','Metric')>Remove</button></td></tr>";
			basketCounter ++;
		}
		basketCheckout += "</table><br /><br />";
	}		
	if (basketDetailsImperial == null) {
		basketDetailsImperial = "";
	}
	if (basketDetailsImperial != "") {
		basketTemp = basketDetailsImperial.substring(3, basketDetailsImperial.length-3);
		basketArrayImperial = basketTemp.split("-/--/-");
		
		basketCheckout += "<span style='font-size:14px; font-weight:bold; color:#1BAACC;'>Imperial</span><br /><br /><table style='width:470px;'><tr align='center' style='font-weight:bold; background-color:#4C95A4;'><td>Type</td><td>Length</td><td>Quantity</td><td>Modify</td><td>Remove</td></tr>";
		basketCounter = 0;
		while (basketCounter < basketArrayImperial.length) {
			basketCheckout += "<tr align='center' style='color:#FFF; background-color:#333;'><td>";
			
			basketCheckoutTemp = basketArrayImperial[basketCounter].replace("__", " / ");
			basketCheckoutTemp = basketCheckoutTemp.replace("_point_", ".");
			
			dash1Found = basketCheckoutTemp.indexOf("-");
			dash2Found = basketCheckoutTemp.indexOf("-@-", dash1Found+1);
			
			typeMod = basketCheckoutTemp.substring(0, dash1Found);
			lengthMod = basketCheckoutTemp.substring(dash1Found+1, dash2Found);
			
			typeFixed = toFract(typeMod, "type");
			lengthFixed = toFract(lengthMod, "length");
			
			basketCheckoutTemp = basketCheckoutTemp.replace(typeMod+"-", typeFixed+"</td><td>");
			basketCheckoutTemp = basketCheckoutTemp.replace(lengthMod, lengthFixed);
			
			basketCheckoutTemp = basketCheckoutTemp.replace("-@-", "</td><td>");		
			
			dash1Found = basketArrayImperial[basketCounter].indexOf("-");
			dash2Found = basketArrayImperial[basketCounter].indexOf("-@-", dash1Found+1);
			
			typeMod = basketArrayImperial[basketCounter].substring(0, dash1Found);
			lengthMod = basketArrayImperial[basketCounter].substring(dash1Found+1, dash2Found);
			quantityMod = basketArrayImperial[basketCounter].substring(dash2Found+3, basketArrayImperial[basketCounter].length);
			
			basketCheckout += basketCheckoutTemp + "</td><td><button style='font-size:10px;1' onmouseover='quantityOver()' onmouseout='quantityOut()' onmouseup=quantityShowMod('"+lengthMod+"','"+typeMod+"','"+quantityMod+"','Imperial')>Modify</button></td><td><button style='font-size:10px;' onmouseover='quantityOver()' onmouseout='quantityOut()' onmouseup=quantityRemove('"+lengthMod+"','"+typeMod+"','"+quantityMod+"','Imperial')>Remove</button></td></tr>";
			basketCounter ++;
		}
		basketCheckout += "</table>";
	}
	$("#basketDetailsInt").html(basketCheckout);
	if (email == null) {
		$("#email").val("Enter your email address here...");
	}
	else {
		$("#email").val(email);
	}
	
	dragBasketDetailsHolder = DragHandler;
	dragBasketDetailsHolder.attach(document.getElementById("basketDetailsHolder"));
}
