var coatLayerName       	= "&$coat=AlsFormalWear/AFW_";
var pantsLayerName      	= "&$pants=AlsFormalWear/AFW_";
var cummerbundLayerName		= "&$cummerbund=AlsFormalWear/AFW_";
var shirtLayerName      	= "&$shirt=AlsFormalWear/AFW_";
var tieLayerName        	= "&$tie=AlsFormalWear/AFW_";
var bowtieLayerName        	= "&$bowtie=AlsFormalWear/AFW_";
var vestLayerName        	= "&$vest=AlsFormalWear/AFW_";
var collarLayerName        	= "&$collar=AlsFormalWear/AFW_";
var accessoriesLayerName        = "&$accessories=AlsFormalWear/";
var chainLayerName        	= "&$chain=AlsFormalWear/AFW_";
var shoesLayerName        	= "&$shoes=AlsFormalWear/";


function switchSelectors(sel1, sel2)
{
	if (sel1.disabled === true) {
		sel1.disabled = false;
		sel2.disabled = true;
	} else {
		sel1.disabled = true;
		sel2.disabled = false;
	}
		
}



function afwURL(width,
		height,
		coat,
		vestcummerbund,
		shirt,
		tie,
		accessories,
		shoes)
     
{

	var url = baseUrl;
	url = url.replace(/wid=\d+/, "wid=" + width);
	url = url.replace(/hei=\d+/, "hei=" + height);
	
	url += coatLayerName + coat;

	var pants = lookupTableValue(coatTable, coat, 1);
	url += pantsLayerName + pants;

	// handle vest or cummerbund layer
	var vctype = lookupTableValue(vestcummerbundTable, vestcummerbund, 1);
	var rgbvalue = lookupTableValue(vestcummerbundTable, vestcummerbund, 2);
	
	if (rgbvalue == "0,0,0")
		rgbvalue = "255,255,255";
	
	if (vctype == "vest") {

		url += vestLayerName + vestcummerbund;
		url += cummerbundLayerName + "0";
	
	} else if (vctype == "cummerbund") {
	
		url += vestLayerName + "0";
		url += cummerbundLayerName + vestcummerbund;	
	
	} else {

		url += vestLayerName + "0";
		url += cummerbundLayerName + "0";	
	
	}
	
	var hanky = lookupTableValue(coatTable, coat, 2);

	if (vestcummerbund != "0" && hanky == "hanky")
	{
	
		url += "&layer=15&src=AlsFormalWear/AFW_" + coat + "h&pos=300,500&size=600,1000&op_colorize=" + rgbvalue;
	}


	url += shirtLayerName + shirt;
	
	var shirtType = lookupTableValue(shirtTable, shirt, 1);
	
	var tietype = lookupTableValue(tieTable, tie, 1);
	
	if (tie == "0") {
	
		url += tieLayerName + "0";
		url += bowtieLayerName + "0";
		url += collarLayerName + "0";

	
	} else if (tietype == "necktie") {
	
		url += collarLayerName + shirt + "c";		
		url += tieLayerName + tie;
		url += bowtieLayerName + "0";
	} else if (tietype == "bowtie") {
	
		url += collarLayerName + "0";

		if (shirtType == "standard")
			url += bowtieLayerName + tie + "nn";
		else
			url += bowtieLayerName + tie;
		
		url += tieLayerName + "0";		
	
	} if (tietype == "buttoncover") {
	
		url += collarLayerName + "0";

		if (shirtType == "standard")
			url += bowtieLayerName + tie;
		else
			url += bowtieLayerName + tie;
		
		url += tieLayerName + "0";		
	
	}
	
	if (shirt == "0")
		url += collarLayerName + "0";		
		
	
	if (coat == "xxxx") { // zoot suit?
		url += chainLayerName + "chain";		
	} else {
		url += chainLayerName + "0";			
	}
	
	
	if (accessories == 0)
		accessories = "AFW_0";	
	
	url += accessoriesLayerName + accessories;

	if (shoes == 0)
		shoes = "AFW_0";	

	url += shoesLayerName + shoes;
	
	// crop out extra border
	url += "&crop=2,2,596,997";
	
					
	return url;
}

