// -------------------------------------------------------------------------------------------------
// COPYRIGHT 2010 Lee McMinn. In The Frame.
// -------------------------------------------------------------------------------------------------
var acrylicSafetyGlazingPrice, nonReflectiveAcrylicGlazingPrice, floatGlassPrice, noGlazing, width, frameDescription, height, newWidth, newHeight, mountStyle, mountWidth, mountVPadding, mountHPadding, bottomMountVPadding, bottomMountHPadding, PHPSessionID, artworkWidth, artworkHeight, framePrice, mountColour, mountBottomColour, mountImageUrl, mountBottomImageUrl, defaultImageUrl, imageServerSessionID, mountID, mountBottomID, mountQty, superClearGlazingPrice, superClearNonReflectivePrice;
var frameID = "415_305_";
var frameCostPrice = 2.53;
var frameWidth = 25;
var imageSrc;
var multiMountEnabled = false;
var multiMountSaveString;
var multiMountSaveStringNew;
var multiMountPrice = 0.00;
var mountID = 8001;
var bottomMountID = 8011;

function setDefaultImageUrl(imageSent) {
	defaultImageUrl = imageSent;
}

function getMountStyle() {
	for (var i = 0; i < document.dataMountStyle.mountStyle.length; i++) {
		if (document.dataMountStyle.mountStyle[i].checked) {
			return document.dataMountStyle.mountStyle[i].value;
		}
	}
}
// FUNCTIONS FOR PRICING UP THE FRAME AS THE USER IS CUSTOMISING -------------------------------------

function getFramePrice() {
	totalLengthNeeded = (width * 2) + (height * 2);
	totalLengthNeeded = totalLengthNeeded / 1000;
	framePrice = totalLengthNeeded * frameCostPrice;	
	
	if(width > 1000)	framePrice += 5.50;
	if(width > 800)		framePrice += 4.50;
	if(width > 600)		framePrice += 4.00;
	if(width > 500)		framePrice += 3.00;
	if(width > 400)		framePrice += 2.00;	
	if(width > 200)		framePrice += 1.00;
	
	if(height > 1000)	framePrice += 5.50;
	if(height > 800)	framePrice += 4.50;	
	if(height > 600)	framePrice += 4.00;
	if(height > 500)	framePrice += 3.00;
	if(height > 400)	framePrice += 2.00;	
	if(height > 200)	framePrice += 1.00;
	
	if(framePrice < 6.95) framePrice += 4.95;
	if(framePrice < 8.95) framePrice += 3.95;
	if(framePrice < 9.95) framePrice += 2.95;
	if(framePrice < 10.95) framePrice += 1.95;
	if(framePrice < 11.95) framePrice += 0.95;
	
	framePrice += 5.00;
	
	return framePrice;
}

function setPHPSessionID(sessionID) {
	PHPSessionID = sessionID;
	positionFrame();
	preLoadContent = "";
	updatePicture();
}

function setImageSessionID(imageSID) {
	imageServerSessionID = imageSID;
}

function showDefaultPicture() {
	document.getElementById("currentImage").style.width = document.getElementById("mainImage").style.width;
	document.getElementById("currentImage").style.height = document.getElementById("mainImage").style.height;
	document.getElementById("currentImage").src = defaultImageUrl;
}

function showPicture() {
	document.getElementById("currentImage").style.width = document.getElementById("mainImage").style.width;
	document.getElementById("currentImage").style.height = document.getElementById("mainImage").style.height;
	document.getElementById("currentImage").style.visibility = "visible";
}

function updatePicture() {
	time = new Date();
	document.getElementById('fullPHPFrame').src = imageSrc + "&autoUpdate=true?" + time;
	document.getElementById('fullPHPFrameLink').href = imageSrc + "&autoUpdate=true?" + time;
	
	// Update Room View Image
	document.getElementById("roomViewFrameImage").src = imageSrc + "&roomView=true?" + time;
	document.getElementById("roomViewFrameImage").width = width / 4.8;
	
	//document.getElementById("silhouette").src = "http://image-3.picture-framing.com/Inc/createFrameImageSILHOUETTE.php?" + time;
}

function getSingleMountPrice() {
	var totalTopMountWidth = parseInt(document.getElementById('topMountLeft').value) + parseInt(document.getElementById('topMountRight').value);
	var totalTopMountHeight = parseInt(document.getElementById('topMountTop').value) + parseInt(document.getElementById('topMountBottom').value);	
	
	mountAreaCM2 = (parseInt(totalTopMountWidth) * parseInt(totalTopMountHeight)) / 100;
	mountPrice = mountAreaCM2 * 0.05;
	return mountPrice;
}

function getDoubleMountPrice() {
	var totalTopMountWidth = parseInt(document.getElementById('topMountLeft').value) + parseInt(document.getElementById('topMountRight').value);
	var totalTopMountHeight = parseInt(document.getElementById('topMountTop').value) + parseInt(document.getElementById('topMountBottom').value);		
	var totalBottomMountWidth = parseInt(document.getElementById('bottomMountLeft').value) + parseInt(document.getElementById('bottomMountRight').value) + totalTopMountWidth;
	var totalBottomMountHeight = parseInt(document.getElementById('bottomMountTop').value) + parseInt(document.getElementById('bottomMountBottom').value) + totalTopMountHeight;
	
	var totalMountWidth = parseInt(totalTopMountWidth) + parseInt(totalBottomMountWidth);
	var totalMountHeight = parseInt(totalTopMountHeight) + parseInt(totalBottomMountHeight);
	
	mountAreaCM2 = (parseInt(totalMountWidth) * parseInt(totalMountHeight)) / 100;
	mountPrice = mountAreaCM2 * 0.025;
	
	return mountPrice;
}

function getMountPrice() {
	if(multiMountEnabled == false)
	{
		if (getMountStyle() == "Single Mount") {
			
			var totalTopMountWidth = parseInt(document.getElementById('topMountLeft').value) + parseInt(document.getElementById('topMountRight').value);
			var totalTopMountHeight = parseInt(document.getElementById('topMountTop').value) + parseInt(document.getElementById('topMountBottom').value);	
			
			mountAreaCM2 = (parseInt(totalTopMountWidth) * parseInt(totalTopMountHeight)) / 100;
			mountPrice = mountAreaCM2 * 0.05;
			return mountPrice;
		}
		else if (getMountStyle() == "Double Mount") {
			
			var totalTopMountWidth = parseInt(document.getElementById('topMountLeft').value) + parseInt(document.getElementById('topMountRight').value);
			var totalTopMountHeight = parseInt(document.getElementById('topMountTop').value) + parseInt(document.getElementById('topMountBottom').value);		
			var totalBottomMountWidth = parseInt(document.getElementById('bottomMountLeft').value) + parseInt(document.getElementById('bottomMountRight').value) + totalTopMountWidth;
			var totalBottomMountHeight = parseInt(document.getElementById('bottomMountTop').value) + parseInt(document.getElementById('bottomMountBottom').value) + totalTopMountHeight;
			
			var totalMountWidth = parseInt(totalTopMountWidth) + parseInt(totalBottomMountWidth);
			var totalMountHeight = parseInt(totalTopMountHeight) + parseInt(totalBottomMountHeight);
			
			mountAreaCM2 = (parseInt(totalMountWidth) * parseInt(totalMountHeight)) / 100;
			mountPrice = mountAreaCM2 * 0.025;
			
			return mountPrice;		
		}
		else {
			return null;
		}
	}
	else
	{
		return parseInt(multiMountPrice);
	}
}

function getTotalPrice() {
	FramePrice = getFramePrice() * 0.95;		// Make alterations for global prices
	
	if(multiMountEnabled == true) {
		MountPrice = getMountPrice();			// Do not make global alterations to multi mount prices as price is shown previously for mount in mount designer
	}
	else {
		MountPrice = getMountPrice() * 0.95;	// Make alterations for global prices
	}
	
	GlazingPrice = getGlazingPrice();
	ExtrasPrice = getExtrasPrice();
	
	totalPrice = FramePrice + GlazingPrice + ExtrasPrice;
	
	if (MountPrice != null) {
		totalPrice = FramePrice + GlazingPrice + MountPrice + ExtrasPrice;
	}
	
	return totalPrice.toFixed(2);
}

function getTotalPriceMinusDiscount()
{
	return (getTotalPrice() - (getTotalPrice() * 0.2)).toFixed(2);
}
// ---------------------------------------------------------------------------------------------------

function selectMountColour(mountName, mountURL, newMountID) {
	mountColour = mountName;
	mountImageUrl = mountURL;
	mountID = newMountID;
	
	if(multiMountEnabled == true) {
		multiMountSaveStringNew = multiMountSaveString + "&topMount=" + mountID;
	 	multiMountSaveStringNew += "&bottomMount=" + mountBottomID;
	}
}

function rollOverMount(mountName, mountURL, newMountID) {
}

function selectBottomMountColour(mountBottomName, mountBottomURL, newMountBottomID) {
	mountBottomColour = mountBottomName;
	mountBottomImageUrl = mountBottomURL;
	mountBottomID = newMountBottomID;
	
	if(multiMountEnabled == true) {
		multiMountSaveStringNew = multiMountSaveString + "&topMount=" + mountID;
	 	multiMountSaveStringNew += "&bottomMount=" + mountBottomID;
	}
}

function selectFrame(newFrameID, newFrameCostPrice, newWidth, update, newDescription) {
	frameID = newFrameID;
	frameCostPrice = newFrameCostPrice;
	frameWidth = newWidth;
	frameDescription = newDescription;
/*
	var imageURL = "/Inc/frame_image.php?frame=" + newFrameID + "&width=" + width + "&frameWidth=" + newWidth + "&height=" + height;
	var topLeftURL = imageURL + "&pos=top-left";
	var topRightURL = imageURL + "&pos=top-right";
	var bottomLeftURL = imageURL + "&pos=bottom-left";
	var bottomRightURL = imageURL + "&pos=bottom-right";
	var bottomURL = imageURL + "&pos=bottom";
	var leftURL = imageURL + "&pos=left";
	var topURL = imageURL + "&pos=top";
	var rightURL = imageURL + "&pos=right";
	
	preLoadContent += '<img src="' + topLeftURL + '" />';
	preLoadContent += '<img src="' + topRightURL + '" />';
	preLoadContent += '<img src="' + bottomLeftURL + '" />';
	preLoadContent += '<img src="' + bottomRightURL + '" />';
	preLoadContent += '<img src="' + bottomURL + '" />';
	preLoadContent += '<img src="' + leftURL + '" />';
	preLoadContent += '<img src="' + topURL + '" />';
	preLoadContent += '<img src="' + rightURL + '" />';
	
	document.getElementById('preLoadContentBox').innerHTML = preLoadContent;
	
	// CORNERS ----------------------------------------------------------------------------------------
	document.getElementById('topLeft').style.backgroundImage = 'url("' + topLeftURL + '")';	
	document.getElementById('topRight').style.backgroundImage = 'url("' + topRightURL + '")';	
	document.getElementById('bottomLeft').style.backgroundImage = 'url("' + bottomLeftURL + '")';	
	document.getElementById('bottomRight').style.backgroundImage = 'url("' + bottomRightURL + '")';
	
	// SIDES ------------------------------------------------------------------------------------------
	document.getElementById('bottom').style.backgroundImage = 'url("' + bottomURL + '")';	
	document.getElementById('top').style.backgroundImage = 'url("' + topURL + '")';	
	document.getElementById('left').style.backgroundImage = 'url("' + leftURL + '")';	
	document.getElementById('right').style.backgroundImage = 'url("' + rightURL + '")';	
	
	*/
	if (update == true) {} else {
		autoUpdate();
	}
}

function positionFrame() {
	document.getElementById('right').style.backgroundPosition = "left";
	document.getElementById('right').style.backgroundRepeat = "repeat-y";
	document.getElementById('left').style.backgroundPosition = "right";
	document.getElementById('left').style.backgroundRepeat = "repeat-y";
	document.getElementById('top').style.backgroundPosition = "bottom";
	document.getElementById('top').style.backgroundRepeat = "repeat-x";
	document.getElementById('bottom').style.backgroundPosition = "top";
	document.getElementById('bottom').style.backgroundRepeat = "repeat-x";
	document.getElementById('bottomRight').style.backgroundPosition = "top left";
	document.getElementById('bottomRight').style.backgroundRepeat = "no-repeat";
	document.getElementById('bottomLeft').style.backgroundPosition = "top right";
	document.getElementById('bottomLeft').style.backgroundRepeat = "no-repeat";
	document.getElementById('topRight').style.backgroundPosition = "bottom left";
	document.getElementById('topRight').style.backgroundRepeat = "no-repeat";
	document.getElementById('topLeft').style.backgroundPosition = "bottom right";
	document.getElementById('topLeft').style.backgroundRepeat = "no-repeat";
}

function updateImage() {
	var percentage;
	if (parseInt(width) > parseInt(height)) {
		percentage = (parseInt(height) / parseInt(width)) * 100;
		newWidth = 360;
		newHeight = (percentage / 100) * newWidth;
		artworkHeight = newHeight;
	}
	else {
		percentage = (parseInt(width) / parseInt(height)) * 100;
		newHeight = 360;
		newWidth = (percentage / 100) * newHeight;
		artworkWidth = newWidth;
	}
	if (newWidth != 0 || newHeight != 0) {
		document.getElementById('mainImage').style.width = newWidth + "px";
		document.getElementById('mainImage').style.height = newHeight + "px";
	}
}

function removeBottomMount() {
	document.getElementById('mainImageBottomMount').style.paddingTop = "0px";
	document.getElementById('mainImageBottomMount').style.paddingBottom = "0px";
	document.getElementById('mainImageBottomMount').style.paddingLeft = "0px";
	document.getElementById('mainImageBottomMount').style.paddingRight = "0px";
	document.getElementById('mainImageBottomMount').style.backgroundImage = '';
	document.getElementById('mainImageBottomMount').style.backgroundRepeat = "repeat";
	document.getElementById('mainImageBottomMount').style.backgroundPosition = "left";
	document.getElementById('mainImageBottomMount').style.border = "";
}

function removeTopMount() {
	document.getElementById('mainImageMount').style.paddingTop = "0px";
	document.getElementById('mainImageMount').style.paddingBottom = "0px";
	document.getElementById('mainImageMount').style.paddingLeft = "0px";
	document.getElementById('mainImageMount').style.paddingRight = "0px";
	document.getElementById('mainImageMount').style.backgroundImage = '';
	document.getElementById('mainImageMount').style.backgroundRepeat = "repeat";
	document.getElementById('mainImageMount').style.backgroundPosition = "left";
	document.getElementById('mainImageMount').style.border = "";
}

function addBottomMount() {
	if (width > height) {
		document.getElementById('mainImageBottomMount').style.paddingTop = ((document.getElementById("bottomMountTop").value / width) * 100) * 3.6 + "px";
		document.getElementById('mainImageBottomMount').style.paddingBottom = ((document.getElementById("bottomMountBottom").value / width) * 100) * 3.6 + "px";
		document.getElementById('mainImageBottomMount').style.paddingLeft = ((document.getElementById("bottomMountLeft").value / width) * 100) * 3.6 + "px";
		document.getElementById('mainImageBottomMount').style.paddingRight = ((document.getElementById("bottomMountRight").value / width) * 100) * 3.6 + "px";
	}
	else {
		document.getElementById('mainImageBottomMount').style.paddingTop = ((document.getElementById("bottomMountTop").value / height) * 100) * 3.6 + "px";
		document.getElementById('mainImageBottomMount').style.paddingBottom = ((document.getElementById("bottomMountBottom").value / height) * 100) * 3.6 + "px";
		document.getElementById('mainImageBottomMount').style.paddingLeft = ((document.getElementById("bottomMountLeft").value / height) * 100) * 3.6 + "px";
		document.getElementById('mainImageBottomMount').style.paddingRight = ((document.getElementById("bottomMountRight").value / height) * 100) * 3.6 + "px";
	}
	document.getElementById('mainImageBottomMount').style.backgroundImage = 'url(' + mountBottomImageUrl + ')';
	document.getElementById('mainImageBottomMount').style.backgroundRepeat = "repeat";
	document.getElementById('mainImageBottomMount').style.backgroundPosition = "left";
}

function addTopMount() {
	if (mountVPadding > mountHPadding) {
		mountHPadding = mountVPadding;
	}
	else {
		mountVPadding = mountHPadding;
	}
	if (width > height) {
		document.getElementById('mainImageMount').style.paddingTop = ((document.getElementById("topMountTop").value / width) * 50) * 3.6 + "px";
		document.getElementById('mainImageMount').style.paddingBottom = ((document.getElementById("topMountBottom").value / width) * 50) * 3.6 + "px";
		document.getElementById('mainImageMount').style.paddingLeft = ((document.getElementById("topMountLeft").value / width) * 50) * 3.6 + "px";
		document.getElementById('mainImageMount').style.paddingRight = ((document.getElementById("topMountRight").value / width) * 50) * 3.6 + "px";
	}
	else {
		document.getElementById('mainImageMount').style.paddingTop = ((document.getElementById("topMountTop").value / height) * 50) * 3.6 + "px";
		document.getElementById('mainImageMount').style.paddingBottom = ((document.getElementById("topMountBottom").value / height) * 50) * 3.6 + "px";
		document.getElementById('mainImageMount').style.paddingLeft = ((document.getElementById("topMountLeft").value / height) * 50) * 3.6 + "px";
		document.getElementById('mainImageMount').style.paddingRight = ((document.getElementById("topMountRight").value / height) * 50) * 3.6 + "px";
	}
	document.getElementById('mainImageMount').style.backgroundImage = 'url(' + mountImageUrl + ')';
	document.getElementById('mainImageMount').style.backgroundRepeat = "repeat";
	document.getElementById('mainImageMount').style.backgroundPosition = "left";
	document.getElementById('mainImageMount').style.border = "1px solid #666666";
}

function updateMount() {
	switch (getMountStyle()) {
	case "No Mount":
		removeTopMount();
		removeBottomMount();
		document.getElementById("mountSizes").style.visibility = "hidden";
		document.getElementById("bottomMountSizes").style.visibility = "hidden";
		document.getElementById("mountSizesContainer").style.height = "0px";
		document.getElementById("bottomMountSizesContainer").style.height = "0px";
		mountQty = 0;
		break;
	case "Single Mount":
		addTopMount();
		removeBottomMount();
		document.getElementById("mountSizes").style.visibility = "visible";
		document.getElementById("bottomMountSizes").style.visibility = "hidden";
		document.getElementById("bottomMountSizesContainer").style.height = "0px";
		document.getElementById("mountSizesContainer").style.height = "100px";
		mountQty = 1;
		break;
	case "Double Mount":
		addTopMount();
		addBottomMount();
		document.getElementById("mountSizes").style.visibility = "visible";
		document.getElementById("bottomMountSizes").style.visibility = "visible";
		document.getElementById("mountSizesContainer").style.height = "100px";
		document.getElementById("bottomMountSizesContainer").style.height = "100px";
		mountQty = 2;
		break;
	}
}

function updateGlazingPrices() {
	var area = (width / 1000) * (height / 1000);
	
	superClearGlazingPrice = 3.95;
	superClearNonReflectivePrice = 4.95;
	
	acrylicSafetyGlazingPrice = 1.95;
	
	 if(width > 1220 && height > 1220)
	{
		acrylicSafetyGlazingPrice += area * 21.61;
		superClearGlazingPrice += acrylicSafetyGlazingPrice;
		superClearNonReflectivePrice += acrylicSafetyGlazingPrice;
	}
	else if(width > 1220 || height > 1220)
	{
		acrylicSafetyGlazingPrice += area * 41.61;
		superClearGlazingPrice += acrylicSafetyGlazingPrice;
		superClearNonReflectivePrice += acrylicSafetyGlazingPrice;
	}
	else if(width > 900 || height > 900)
	{
		acrylicSafetyGlazingPrice += 5.00;
		superClearGlazingPrice += acrylicSafetyGlazingPrice;
		superClearNonReflectivePrice += acrylicSafetyGlazingPrice;
	}
	
	nonReflectiveAcrylicGlazingPrice = acrylicSafetyGlazingPrice + 1.00;
	
	
	
	document.getElementById("acrylicSafetyGlazingPrice").innerHTML = acrylicSafetyGlazingPrice.toFixed(2);
	document.getElementById("nonReflectiveAcrylicGlazingPrice").innerHTML = nonReflectiveAcrylicGlazingPrice.toFixed(2);
	document.getElementById("noGlazingPrice").innerHTML = "0.00";
	
	document.getElementById("superClearGlazingPrice").innerHTML = superClearGlazingPrice.toFixed(2);
	document.getElementById("superClearNonReflectivePrice").innerHTML = superClearNonReflectivePrice.toFixed(2);
}

function getGlazingPrice() {
	updateGlazingPrices();
	if (getGlazingStyle() == "Acrylic Safety Glazing") {
		return acrylicSafetyGlazingPrice;
	}
	else if (getGlazingStyle() == "Non Reflective Acrylic Glazing") {
		return nonReflectiveAcrylicGlazingPrice;
	}
	else if (getGlazingStyle() == "2mm Float Glass") {
		return floatGlassPrice;
	}
	else if (getGlazingStyle() == "Super Clear Premium Package") {
		return superClearGlazingPrice;
	}
	else if (getGlazingStyle() == "Non Reflective Premium Package") {
		return superClearNonReflectivePrice;
	}
	else {
		return null;
	}
}

function getGlazingStyle() {
	for (var i = 0; i < document.dataGlazing.glazingStyle.length; i++) {
		if (document.dataGlazing.glazingStyle[i].checked) {
			return document.dataGlazing.glazingStyle[i].value;
		}
	}
}

function updateSummary() {
	document.getElementById('summaryWidth').innerHTML = width;
	document.getElementById('summaryHeight').innerHTML = height;
	document.getElementById('summaryWidth2').innerHTML = width;
	document.getElementById('summaryHeight2').innerHTML = height;
	document.getElementById('summaryMountStyle').innerHTML = getMountStyle();
	document.getElementById('summaryTopMountColour').innerHTML = mountColour;
	document.getElementById('summaryBottomMountColour').innerHTML = mountBottomColour;
	document.getElementById('runningPrice').innerHTML = (getTotalPrice() * 1.20).toFixed(2); // Show price including VAT
	document.getElementById('runningPriceMinusDiscount').innerHTML = (getTotalPriceMinusDiscount() * 1.20).toFixed(2); // Show price including VAT
	document.getElementById('summaryGlazing').innerHTML = getGlazingStyle();
	document.getElementById('summaryFrameStyle').innerHTML = frameDescription;
	document.getElementById('summaryTotalPrice').innerHTML = (getTotalPriceMinusDiscount() * 1.20).toFixed(2) // Show price including VAT;
	//document.getElementById('summaryExtras').innerHTML = getExtras();
	//document.getElementById('singleMountPrice').innerHTML = getSingleMountPrice();
	//document.getElementById('doubleMountPrice').innerHTML = getDoubleMountPrice();
	
	if(getMountStyle() == 'No Mount')
	{
		document.getElementById('summaryExternalWidth').innerHTML = (parseInt(width) + parseInt(frameWidth) + parseInt(frameWidth)) - 10;
	
		document.getElementById('summaryExternalHeight').innerHTML = (parseInt(height) + parseInt(frameWidth) + parseInt(frameWidth)) - 10;
	}
	else if(getMountStyle() == 'Single Mount')
	{
		document.getElementById('summaryExternalWidth').innerHTML = parseInt(width) + parseInt(document.getElementById('topMountLeft').value) + parseInt(document.getElementById('topMountRight').value) + parseInt(frameWidth) + parseInt(frameWidth) - 10;
	
		document.getElementById('summaryExternalHeight').innerHTML = parseInt(height) + parseInt(document.getElementById('topMountTop').value) + parseInt(document.getElementById('topMountBottom').value) + parseInt(frameWidth) + parseInt(frameWidth) - 10;
	}
	else
	{
		document.getElementById('summaryExternalWidth').innerHTML = parseInt(width) + parseInt(document.getElementById('topMountLeft').value) + parseInt(document.getElementById('topMountRight').value) + parseInt(document.getElementById('bottomMountLeft').value) + parseInt(document.getElementById('bottomMountRight').value) + parseInt(frameWidth) + parseInt(frameWidth) - 10;
	
		document.getElementById('summaryExternalHeight').innerHTML = parseInt(height) + parseInt(document.getElementById('topMountTop').value) + parseInt(document.getElementById('topMountBottom').value) + parseInt(document.getElementById('bottomMountTop').value) + parseInt(document.getElementById('bottomMountBottom').value) + parseInt(frameWidth) + parseInt(frameWidth) - 10;
	}	
}

function showFrameLoader() {
	document.getElementById("frameLoader").style.top = ((document.getElementById("fullPHPFrame").height / 2) + 25) + "px";
	document.getElementById("frameLoader").style.display = "block";
}

function hideFrameLoader() {
	document.getElementById("frameLoader").style.display = "none";
}

function autoRemoveMount() {
	width = document.dataSizes.width.value;
	height = document.dataSizes.height.value;
	
	actualFrameWidth = parseInt(document.getElementById("topMountLeft").value) + parseInt(document.getElementById("topMountRight").value) + parseInt(document.getElementById("bottomMountLeft").value) + parseInt(document.getElementById("bottomMountRight").value) + parseInt(width);
	actualFrameHeight = parseInt(document.getElementById("topMountTop").value) + parseInt(document.getElementById("topMountBottom").value) + parseInt(document.getElementById("bottomMountTop").value) + parseInt(document.getElementById("bottomMountBottom").value) + parseInt(height);
	
	if (actualFrameWidth > 815 && actualFrameHeight > 815) {
		$('#mountType_0').attr('checked', true);
	}	
	else if (actualFrameWidth > 1120 || actualFrameHeight > 1120) {
		$('#mountType_0').attr('checked', true);		
	}
}

function autoUpdate() {	

	if(multiMountEnabled == true) $.get('../test/save.php?' + multiMountSaveStringNew);

	//imageSrc = decodeURI("http://image-3.picture-framing.com/Inc/customFrameImageMAIN.php?iframe=true&artworkWidth=" + document.dataSizes.width.value + "\&artworkHeight=" + document.dataSizes.height.value + "\&frameID=" + frameID + "\&topMountID=" + mountColour + "\&bottomMountID=" + mountBottomColour + "\&mountStyle=" + getMountStyle() + "\&imageWidth=500\&imageHeight=500\&topMountLeft=" + document.getElementById('topMountLeft').value + "\&topMountRight=" + document.getElementById('topMountRight').value + "\&topMountTop=" + document.getElementById('topMountTop').value + "\&topMountBottom=" + document.getElementById('topMountBottom').value + "\&bottomMountLeft=" + document.getElementById('bottomMountLeft').value + "\&bottomMountRight=" + document.getElementById('bottomMountRight').value + "\&bottomMountTop=" + document.getElementById('bottomMountTop').value + "\&bottomMountBottom=" + document.getElementById('bottomMountBottom').value + "\&artworkUrl=" + PHPSessionID);
		
	if (getMountStyle() == "No Mount") {
		document.getElementById("topMountColourSelection").style.display = "none";
		document.getElementById("bottomMountColourSelection").style.display = "none";
		document.getElementById("topMountColourSelectionHeading").innerHTML = "You can add a top mount by clicking number 3 ( Mount Style ) above.";
		document.getElementById("bottomMountColourSelectionHeading").innerHTML = "You can add a bottom mount by clicking number 3 ( Mount Style ) above.";
		mountQty = 0;
	}
	else if (getMountStyle() == "Single Mount") {
		document.getElementById("topMountColourSelection").style.display = "";
		document.getElementById("bottomMountColourSelection").style.display = "none";
		document.getElementById("topMountColourSelectionHeading").innerHTML = "<b>Top Mount Colour.</b>";
		document.getElementById("bottomMountColourSelectionHeading").innerHTML = "You can add a bottom mount by clicking number 3 ( Mount Style ) above.";
		mountQty = 1;
	}
	else if (getMountStyle() == "Double Mount") {
		document.getElementById("topMountColourSelection").style.display = "";
		document.getElementById("bottomMountColourSelection").style.display = "";
		document.getElementById("topMountColourSelectionHeading").innerHTML = "<b>Top Mount Colour.</b>";
		document.getElementById("bottomMountColourSelectionHeading").innerHTML = "<b>Bottom Mount Colour.</b>";
		mountQty = 2;
	}
	
	if(multiMountEnabled == true)
	{
		document.getElementById("topMountColourSelection").style.display = "";
		document.getElementById("bottomMountColourSelection").style.display = "";
		document.getElementById("topMountColourSelectionHeading").innerHTML = "<b>Top Mount Colour.</b>";
		document.getElementById("bottomMountColourSelectionHeading").innerHTML = "<b>Bottom Mount Colour.</b>";
	}
	
	width = document.dataSizes.width.value;
	height = document.dataSizes.height.value;
	
	actualFrameWidth = parseInt(document.getElementById("topMountLeft").value) + parseInt(document.getElementById("topMountRight").value) + parseInt(document.getElementById("bottomMountLeft").value) + parseInt(document.getElementById("bottomMountRight").value) + parseInt(width);
	actualFrameHeight = parseInt(document.getElementById("topMountTop").value) + parseInt(document.getElementById("topMountBottom").value) + parseInt(document.getElementById("bottomMountTop").value) + parseInt(document.getElementById("bottomMountBottom").value) + parseInt(height);
	
	sizeAlert = false;
	
	if(mountQty != 0)
	{
		if (actualFrameWidth > 815 && actualFrameHeight > 815) {
			$("#sizeAlertBox").show();
		}	
		else if (actualFrameWidth > 1120 || actualFrameHeight > 1120) {
			$("#sizeAlertBox").show();
		}
		else {		
			$("#sizeAlertBox").hide();
		}
	}
	else {		
		$("#sizeAlertBox").hide();
	}
	
	imageSrc = decodeURI("http://image-3.picture-framing.com/Inc/image.php?aperture0=" + document.dataSizes.width.value + "," + document.dataSizes.height.value + "&mountQTY=" + mountQty + "&frameID=" + frameID + "&mountIDs=" + mountID + "," + mountBottomID + ",8001&topMountBorder=" + document.getElementById('topMountTop').value + "," + document.getElementById('topMountLeft').value + "," + document.getElementById('topMountBottom').value + "," + document.getElementById('topMountRight').value + "&middleMountBorder=" + document.getElementById('bottomMountTop').value + "," + document.getElementById('bottomMountLeft').value + "," + document.getElementById('bottomMountBottom').value + "," + document.getElementById('bottomMountRight').value + "\&artworkUrl=" + PHPSessionID);
	
	selectFrame(frameID, frameCostPrice, frameWidth, true, frameDescription);
	
	updatePicture();
	
	updateImage();
	
	updateGlazingPrices();
	
	updateMount();
	
	updateSummary();
	
	getMultiMountUrl();
}

function autoUpdateInTime(time)
{	
	setTimeout("autoUpdate()", 2500);
	setTimeout("autoUpdate()", time);
}

function getWidth() {
	return width;
}

function getHeight() {
	return height;
}
$(document).ready(function () {
	$("#mainImageBottomMountArrow").fadeOut(1);
	$("#mainImageMountArrow").fadeOut(1);
	$("#showBottomMount").click(function () {
		$("#mainImageBottomMountArrow").slideDown(300).fadeOut(300).fadeIn(300).fadeOut(300).fadeIn(300).fadeOut(300).fadeIn(300).slideUp(300);
	});
	$("#showTopMount").click(function () {
		$("#mainImageMountArrow").slideDown(300).fadeOut(300).fadeIn(300).fadeOut(300).fadeIn(300).fadeOut(300).fadeIn(300).slideUp(300);
	});
});

function hideMenuTips() {
	document.getElementById("menuTips").style.visibility = "hidden";
	document.getElementById("mainPreview").style.opacity = 1;
	document.getElementById("mainPreview").style.MozOpacity = 1;
}

function showMenuTips() {
	document.getElementById("menuTips").style.visibility = "visible";
	document.getElementById("mainPreview").style.opacity = 1;
	document.getElementById("mainPreview").style.MozOpacity = 1;
}

function showAddToBasketLoader() {
	document.getElementById('addToBasketLoader2').style.display = "block";
}

function addToBasket() // Creates the URL containing all the information needed to create an instance of the customFrame object
{
	autoUpdate(); // Double check that everything is up to date and the variables are current.
	createFrameUrl = '/basket/?process=add' + '&FrameID=' + frameID + '&MountStyle=' + getMountStyle() + '&MountWidthLeft=' + document.getElementById("topMountLeft").value + '&MountWidthRight=' + document.getElementById("topMountRight").value + '&MountWidthTop=' + document.getElementById("topMountTop").value + '&MountWidthBottom=' + document.getElementById("topMountBottom").value + '&BottomMountWidthLeft=' + document.getElementById("bottomMountLeft").value + '&BottomMountWidthRight=' + document.getElementById("bottomMountRight").value + '&BottomMountWidthTop=' + document.getElementById("bottomMountTop").value + '&BottomMountWidthBottom=' + document.getElementById("bottomMountBottom").value + '&MountColourTop=' + mountColour + '&MountColourBottom=' + mountBottomColour + '&Glazing=' + getGlazingStyle() + '&ActualArtworkWidth=' + width + '&UnitPrice=' + getTotalPrice() + '&ScreenShot=' + "null" + '&ActualArtworkHeight=' + height + '&Extras=' + getExtras() + '&MultiMountSaveString=' + escape(multiMountSaveStringNew);
	window.location = createFrameUrl;
	return createFrameUrl;
}

function saveToBasket(currentID) // Updates a custom frame that is currently in the basket
{
	autoUpdate(); // Double check that everything is up to date and the variables are current.
	createFrameUrl = '/basket/?process=add' + '&FrameID=' + frameID + '&MountStyle=' + getMountStyle() + '&MountWidthLeft=' + document.getElementById("topMountLeft").value + '&MountWidthRight=' + document.getElementById("topMountRight").value + '&MountWidthTop=' + document.getElementById("topMountTop").value + '&MountWidthBottom=' + document.getElementById("topMountBottom").value + '&BottomMountWidthLeft=' + document.getElementById("bottomMountLeft").value + '&BottomMountWidthRight=' + document.getElementById("bottomMountRight").value + '&BottomMountWidthTop=' + document.getElementById("bottomMountTop").value + '&BottomMountWidthBottom=' + document.getElementById("bottomMountBottom").value + '&MountColourTop=' + mountColour + '&MountColourBottom=' + mountBottomColour + '&Glazing=' + getGlazingStyle() + '&ActualArtworkWidth=' + width + '&UnitPrice=' + getTotalPrice() + '&ScreenShot=' + "null" + '&ActualArtworkHeight=' + height + '&Extras=' + getExtras() + '&MultiMountSaveString=' + escape(multiMountSaveStringNew);
	
	document.getElementById("addToBasketButton").src = 'http://www.picture-framing.com/Images/loading.gif';
	document.getElementById("addToBasketButton").style.width = '30px';
	document.getElementById("addToBasketButton").style.height = '30px';	
	document.getElementById("addToBasketButton").style.margin = '30px 130px 30px 130px';
	
	$.get('http://www.picture-framing.com/basket/?process=fastDelete&ID=' + currentID);
	
	setTimeout('window.location = createFrameUrl;', 3000);
	return createFrameUrl;
}

function roomViewToggle()
{		
	var FADE_TIME = 1000; 
	var showView = $("#roomViewButton").is(':visible');
	
	if($.browser.msie) 
	{ 
		// Show the room with no effects as IE is rubbish
		$("#RV-Exit").toggle();		
		$("#RV-Wallpaper-Cyan").toggle();		
		$("#RV-Floor").toggle("fade");
		$("#RV-Sofa").delay(100).toggle();
		$("#RV-Lamp-Off").delay(100).toggle();
		$("#RV-Lamp-On").delay(showView ? 1500 : 100).toggle();		
		$("#RV-Cat").delay(100).toggle();
		$("#RV-Bookshelf").delay(100).toggle();
		$("#RV-Plant").delay(100).toggle();
	}
	else
	{
		// Fade in room sections wuth lovely effects
		$("#RV-Exit").toggle("fade", "", FADE_TIME);		
		$("#RV-Wallpaper-Cyan").toggle("fade", "", FADE_TIME);		
		$("#RV-Floor").toggle("fade");
		$("#RV-Sofa").delay(100).toggle("fade", "", FADE_TIME);
		$("#RV-Lamp-Off").delay(100).toggle("fade", "", FADE_TIME);
		$("#RV-Lamp-On").delay(showView ? 1500 : 100).toggle("fade", "", FADE_TIME);		
		$("#RV-Cat").delay(100).toggle("fade", "", FADE_TIME);
		$("#RV-Bookshelf").delay(100).toggle("fade", "", FADE_TIME);
		$("#RV-Plant").delay(100).toggle("fade", "", FADE_TIME);
		}
	
	// Get rid of the tabs
	$("#btn1").toggle();		
	$("#btn2").toggle();
	$("#roomViewButton").toggle();	
	
	// Load the resized frame into the room view
	$("#roomViewFrameImage").delay(showView ? 1000 : 100).toggle("fade", "", FADE_TIME);		
}

function toggleDiv(divid){
	if(document.getElementById(divid).style.display == 'none'){
	  document.getElementById(divid).style.display = 'block';
	}else{
	  document.getElementById(divid).style.display = 'none';
	}
  }  

function updateWidthMM()
{
	document.getElementById("width").value = Math.ceil(document.getElementById("widthInch").value * 25.4);
	document.getElementById("widthCm").value = (document.getElementById("widthInch").value * 2.54).toFixed(1);
}

function updateWidthInches()
{
	document.getElementById("widthInch").value = (document.getElementById("width").value / 25.4).toFixed(1);
	document.getElementById("widthCm").value = (document.getElementById("width").value / 10).toFixed(1);
}

function updateHeightMM()
{
	document.getElementById("height").value = Math.ceil(document.getElementById("heightInch").value * 25.4);
	document.getElementById("heightCm").value = (document.getElementById("heightInch").value * 2.54).toFixed(1);
}

function updateHeightInches()
{
	document.getElementById("heightInch").value = (document.getElementById("height").value / 25.4).toFixed(1);
	document.getElementById("heightCm").value = (document.getElementById("height").value / 10).toFixed(1);
}

function updateWidthFromCm()
{
	document.getElementById("widthInch").value = (document.getElementById("widthCm").value / 2.54).toFixed(1);
	document.getElementById("width").value = (document.getElementById("widthCm").value * 10).toFixed(1);
}

function updateHeightFromCm()
{
	document.getElementById("heightInch").value = (document.getElementById("heightCm").value / 2.54).toFixed(1);
	document.getElementById("height").value = (document.getElementById("heightCm").value * 10).toFixed(1);
}

// ------ EXTRAS CODE ----------
// Code for for extras, for example, brown tape, wall fixings etc...

function check(extraId)
{
	if(document.getElementById(extraId).checked)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function getExtras()
{
	extras = "";
	
	if(check("extraWallHangingKit") == true) extras += "Wall Hanging Kit";
	if(check("extraBrownSealingTape") == true) extras += ",Brown Sealing Tape 30mm";
	if(check("extraBrownSealingTapeLarge") == true) extras += ",Brown Sealing Tape 50mm";
	if(check("extraSmallPhotoFrameStand") == true) extras += ",Small Photo Frame Stand";
	if(check("extraLargePhotoFrameStand") == true) extras += ",Large Photo Frame Stand";
	if(check("extraHeavyDutyHanger2Pack") == true) extras += ",Heavy Duty Hanger 2 Pack";
	if(check("extraHeavyDutyWallHook2Pack") == true) extras += ",Heavy Duty Wall Hook 2 Pack";
	if(check("extraSecurityFixings10Pack") == true) extras += ",Security Fixings 10 Pack";
	if(check("priorityService") == true) extras += ",Priority Service";
	if(check("extraFoamBumpers") == true) extras += ",Foam Bumpers 2 Pack";
	
	return extras;
}

function getExtrasPrice()
{
	totalPrice = 0;
	
	if(check("extraWallHangingKit") == true) totalPrice += 0.00;
	if(check("extraBrownSealingTape") == true) totalPrice += 2.45;
	if(check("extraBrownSealingTapeLarge") == true) totalPrice += 4.45;
	if(check("extraSmallPhotoFrameStand") == true) totalPrice += 1.45;
	if(check("extraLargePhotoFrameStand") == true) totalPrice += 1.85;
	if(check("extraHeavyDutyHanger2Pack") == true) totalPrice += 0.85;
	if(check("extraHeavyDutyWallHook2Pack") == true) totalPrice += 0.85;
	if(check("extraSecurityFixings10Pack") == true) totalPrice += 1.65;
	if(check("priorityService") == true) totalPrice += 10.00;
	if(check("extraFoamBumpers") == true) totalPrice += 0.65;
	
	return totalPrice;
}

function showExtrasImage(imageLocation, text)
{
	imageLocation = "/Images/Extras/" + imageLocation;
	
	document.getElementById("extrasImage").src = imageLocation;
	document.getElementById("extrasText").innerHTML = text;
	
	$("#extrasImageContainer").toggle("blind");
	$("#mainView").toggleClass("mainViewExpanded", 1000);
}

// ------ END OF EXTRAS CODE ---

// ------ MULTI MOUNT CODE -----------

function getMultiMountUrl() 
{
	scrt_var = '/test/multi-mount.php?' + multiMountSaveString + '&iframe=true&width=100%&height=100%';	
	document.getElementById("multiMountEnableLink").setAttribute("href", scrt_var);	
	document.getElementById("editMultiMountButton").setAttribute("href", scrt_var);	
}

function multiMountEnable(saveString, price)
{
	multiMountEnabled = true;
	multiMountSaveString = saveString;	
	multiMountSaveStringNew = saveString;
	multiMountPrice = price;
	$("#mountOptions").hide("fade");
	document.getElementById('mountOptions').style.display = "none";
	$("#multiMountRemoveButton").show("fade");
	$("#multiMountEditButton").show("fade");
	getMultiMountUrl();
	autoUpdate();
}

function multiMountDisable()
{
	multiMountEnabled = false;
	multiMountSaveString = '';
	multiMountSaveStringNew = '';
	multiMountPrice = 0;
	$("#mountOptions").show("fade");
	$("#multiMountRemoveButton").hide("fade");		
	$("#multiMountEditButton").hide("fade");
	document.getElementById("mountType_0").checked = false;
	document.getElementById("mountType_1").checked = false;
	document.getElementById("mountType_2").checked = true;
	$.get("http://www.picture-framing.com/Inc/selectDefaultImage.php", { image: "http://picture-framing.com/Images/MainInner.jpg" });
	setTimeout("autoUpdate();", 500);
}

// ------ END OF MULTI MOUNT CODE ---


// jQuery SWFObject v1.1.1 MIT/GPL @jon_neal
// http://jquery.thewikies.com/swfobject
(function(f,h,i){function k(a,c){var b=(a[0]||0)-(c[0]||0);return b>0||!b&&a.length>0&&k(a.slice(1),c.slice(1))}function l(a){if(typeof a!=g)return a;var c=[],b="";for(var d in a){b=typeof a[d]==g?l(a[d]):[d,m?encodeURI(a[d]):a[d]].join("=");c.push(b)}return c.join("&")}function n(a){var c=[];for(var b in a)a[b]&&c.push([b,'="',a[b],'"'].join(""));return c.join(" ")}function o(a){var c=[];for(var b in a)c.push(['<param name="',b,'" value="',l(a[b]),'" />'].join(""));return c.join("")}var g="object",m=true;try{var j=i.description||function(){return(new i("ShockwaveFlash.ShockwaveFlash")).GetVariable("$version")}()}catch(p){j="Unavailable"}var e=j.match(/\d+/g)||[0];f[h]={available:e[0]>0,activeX:i&&!i.name,version:{original:j,array:e,string:e.join("."),major:parseInt(e[0],10)||0,minor:parseInt(e[1],10)||0,release:parseInt(e[2],10)||0},hasVersion:function(a){a=/string|number/.test(typeof a)?a.toString().split("."):/object/.test(typeof a)?[a.major,a.minor]:a||[0,0];return k(e,a)},encodeParams:true,expressInstall:"expressInstall.swf",expressInstallIsActive:false,create:function(a){if(!a.swf||this.expressInstallIsActive||!this.available&&!a.hasVersionFail)return false;if(!this.hasVersion(a.hasVersion||1)){this.expressInstallIsActive=true;if(typeof a.hasVersionFail=="function")if(!a.hasVersionFail.apply(a))return false;a={swf:a.expressInstall||this.expressInstall,height:137,width:214,flashvars:{MMredirectURL:location.href,MMplayerType:this.activeX?"ActiveX":"PlugIn",MMdoctitle:document.title.slice(0,47)+" - Flash Player Installation"}}}attrs={data:a.swf,type:"application/x-shockwave-flash",id:a.id||"flash_"+Math.floor(Math.random()*999999999),width:a.width||320,height:a.height||180,style:a.style||""};m=typeof a.useEncode!=="undefined"?a.useEncode:this.encodeParams;a.movie=a.swf;a.wmode=a.wmode||"opaque";delete a.fallback;delete a.hasVersion;delete a.hasVersionFail;delete a.height;delete a.id;delete a.swf;delete a.useEncode;delete a.width;var c=document.createElement("div");c.innerHTML=["<object ",n(attrs),">",o(a),"</object>"].join("");return c.firstChild}};f.fn[h]=function(a){var c=this.find(g).andSelf().filter(g);/string|object/.test(typeof a)&&this.each(function(){var b=f(this),d;a=typeof a==g?a:{swf:a};a.fallback=this;if(d=f[h].create(a)){b.children().remove();b.html(d)}});typeof a=="function"&&c.each(function(){var b=this;b.jsInteractionTimeoutMs=b.jsInteractionTimeoutMs||0;if(b.jsInteractionTimeoutMs<660)b.clientWidth||b.clientHeight?a.call(b):setTimeout(function(){f(b)[h](a)},b.jsInteractionTimeoutMs+66)});return c}})(jQuery,"flash",navigator.plugins["Shockwave Flash"]||window.ActiveXObject);

