//var strSelected="";
var lastElement = "";

function addPalette(partID,objId,fabricName,rollWidth,fabricPrice,patternRepeat,groupName,groupPart,groupId,liningColour,leadtime){
	
	/*remove the currently selected item*/
	$("#swatch"+strSelected).attr('class','');
	$("#swatchTitleText"+strSelected).attr('class','');
	$("#fabricFamilyTotalPrice"+$("#fabric_groupId").val()).attr('class','calculated_price');

	/* this is a pipe delimited list of the current fabric details. easier to post through to other pages */
	joinedItems = partID + "|" + objId + "|" + fabricName + "|" + rollWidth + "|" + fabricPrice + "|" + patternRepeat + "|" + groupName + "|" + groupPart + "|" + groupId + "|" + liningColour + "|" + leadtime;

	/* change selected choice string */
	currentFabric = fabricName;
	
	/* change price */
	usePrice = parseFloat($('#swatchPrice'+objId).text());
	if(right(usePrice.toFixed(2),2) != "00"){
		usePrice = usePrice.toFixed(2);
	}
	$('#priceInt').text(usePrice);
	$('#totalPrice').val('\u00A3'+usePrice);
	
	if(currentHeading != null){
		/* curtains */
		if(quantityType == "pair"){
			quantityTypeText = "curtains";	
		} else {
			quantityTypeText = "curtain";
		}
		
		/* change right pane description */
		$('#productSummary').text('Your ' + currentLining + ' ' + currentHeading + ' ' + quantityTypeText + ' in ' + currentFabric + ' will be:');
		$('#enlargeLink').attr('title','Your ' + currentLining + ' ' + currentHeading + ' ' + quantityTypeText + ' in ' + currentFabric + ' will be: &pound;' + usePrice);
		
		/* change lytebox link */ 
		
		$.get("/_assets/imageCheck.cfm", { imagepath: '/productimages/lifestyle/curtains/large/' + groupPart + '-' + partID + '-' + currentHeadingPart + '.jpg'},
		  function(data){
			if(data == 'TRUE'){
				$('#enlargeLink').attr('href','/productimages/lifestyle/curtains/large/' + groupPart + '-' + partID + '-' + currentHeadingPart + '.jpg');
			} else {
				$('#enlargeLink').attr('href','/productimages/lifestyle/curtains/large/' + partID + '.jpg');
			}
		});
		
		/* change preview image */

		$.get("/_assets/imageCheck.cfm", { imagepath: '/productimages/lifestyle/curtains/preview/' + groupPart + '-' + partID + '-' + currentHeadingPart + '.jpg' },
		  function(data){
			if(data == 'TRUE'){
				$('#lifestyleImg').attr('src','/productimages/lifestyle/curtains/preview/' + groupPart + '-' + partID + '-' + currentHeadingPart + '.jpg');
			} else {
				$('#lifestyleImg').attr('src','/productimages/lifestyle/curtains/preview/' + partID + '.jpg');
			}
		});

	} else {
				
		/* blinds */
		$('#productSummary').text('Your ' + currentLining + ' blind in ' + currentFabric + ' will be:');
		$('#enlargeLink').attr('title','Your ' + currentLining + ' blind in ' + currentFabric + ' will be: &pound;' + usePrice);
	
	
	
		/* change lytebox link */ 
		
		$.get("/_assets/imageCheck.cfm", { imagepath: '/productimages/lifestyle/blinds/large/' + groupPart + '-' + partID + '.jpg'},
		  function(data){
			if(data == 'TRUE'){
				$('#enlargeLink').attr('href','/productimages/lifestyle/blinds/large/' + groupPart + '-' + partID + '.jpg');
			} else {
				$('#enlargeLink').attr('href','/productimages/lifestyle/blinds/large/' + partID + '.jpg');
			}
		});
		
		/* change preview image */

		$.get("/_assets/imageCheck.cfm", { imagepath: '/productimages/lifestyle/blinds/preview/' + groupPart + '-' + partID + '.jpg' },
		  function(data){
			if(data == 'TRUE'){
				$('#lifestyleImg').attr('src','/productimages/lifestyle/blinds/preview/' + groupPart + '-' + partID + '.jpg');
			} else {
				$('#lifestyleImg').attr('src','/productimages/lifestyle/blinds/preview/' + partID + '.jpg');
			}
		});
	

	}
	
	
	/* change swatch preview*/
	$('#swatchTitle').text(fabricName);
	$('#swatchPreview').attr('src','/productimages/fabrics/thumbs/' + partID + '.jpg');
	$('#swatchPreview').attr('alt',fabricName);

	/*remember selected item*/
	strSelected = objId;
	
	/* set selected "tick" */
	$("#swatch"+strSelected).attr('class','selected_swatch');
	$("#swatchTitleText"+strSelected).attr('class','fabric_selected');
	$("#fabricFamilyTotalPrice"+groupId).attr('class','calculated_price_selected');


	/* set various vars */
	$("#fabric_partCode").val(partID);
	$("#fabric_id").val(objId);
	$("#fabric_name").val(fabricName);
	$("#fabric_fabricRollWidth").val(rollWidth);
	$("#fabric_fabricItemPrice").val(fabricPrice);
	$("#fabric_patternRepeat").val(patternRepeat);
	$("#fabric_groupName").val(groupName);
	$("#fabric_groupPartCode").val(groupPart);
	$("#fabric_groupId").val(groupId);
	$("#fabric_liningColour").val(liningColour);
	$("#fabric_leadtime").val(leadtime);

}