function showExpander(expansionnum,expansionname,expander,numrows) {


	// Are we showing more than one expander?
	if(window.useexpansion2 == 1 && window.usealternateswitcher == 1) {
		// If so, we need to hide any expanders from the "other" expansion
		if (expansionnum == 1) {
			// alert('Hide all the NEW car expanders');
			// Hide all the NEW car expanders
			if(document.getElementById('expansion2-expander1').className == 'selectorLinkHighlighted') {
				// document.getElementById('expansion2-1').style.display = 'none';
	
				// alert('redux 2-1');
				collectionbit = 'collection2-1-';
	
				for(i=1; i<window.expansion2collection1levels; i++) {
					thistrio = i + 1;
					// alert('and hide: ' + collectionbit+'\nthistrio: '+thistrio);
					document.getElementById(collectionbit + thistrio).style.display = 'none';
				}
	
				newh = 97;
				document.getElementById('expansion2-1').style.height = newh + 'px';
	
				// Switch button underneath to say "Show More"
				document.getElementById('showmore2-1').className = 'showmore';
				window.expansion2collection1 = 0;

				/* document.getElementById('expansion2-expander1').className = 'selectorLink';
				document.getElementById('expansion2-expander1-button').className = 'selectorButton'; */
			}
	
			if(document.getElementById('expansion2-expander2').className == 'selectorLinkHighlighted') {
				// alert('redux 2-2');
				collectionbit = 'collection2-2-';
	
				for(i=1; i<window.expansion2collection2levels; i++) {
					thistrio = i + 1;
					// alert('and hide: ' + collectionbit+'\nthistrio: '+thistrio);
					document.getElementById(collectionbit + thistrio).style.display = 'none';
				}
	
				newh = 97;
				document.getElementById('expansion2-2').style.height = newh + 'px';
	

				// alert(typeof(document.getElementById('showmore2-2')));
				// if(typeof(document.getElementById('showmore2-2'))!=null) {
				if(document.getElementById('showmore2-2')!=null) {
					// Switch button underneath to say "Show More"
					document.getElementById('showmore2-2').className = 'showmore';
				}
				window.expansion2collection2 = 0;

				/* document.getElementById('expansion2-expander2').className = 'selectorLink';
				document.getElementById('expansion2-expander2-button').className = 'selectorButton'; */
			}
	
			if(document.getElementById('expansion2-expander3').className == 'selectorLinkHighlighted') {
				// alert('redux 2-3');
				collectionbit = 'collection2-3-';
	
				for(i=1; i<window.expansion2collection3levels; i++) {
					thistrio = i + 1;
					// alert('and hide: ' + collectionbit+'\nthistrio: '+thistrio);
					document.getElementById(collectionbit + thistrio).style.display = 'none';
				}
	
				newh = 97;
				document.getElementById('expansion2-3').style.height = newh + 'px';
	
				// Switch button underneath to say "Show More"
				document.getElementById('showmore2-3').className = 'showmore';
				window.expansion2collection3 = 0;

				/* document.getElementById('expansion2-expander3').className = 'selectorLink';
				document.getElementById('expansion2-expander3-button').className = 'selectorButton'; */
			}
		}
	
		if (expansionnum == 2) {
			// Hide all the USED car expanders
			if(document.getElementById('expansion1-expander1').className == 'selectorLinkHighlighted') {
				// alert('redux 1-1');
				collectionbit = 'collection1-1-';
	
				for(i=1; i<window.expansion1collection1levels; i++) {
					thistrio = i + 1;
					// alert('and hide: ' + collectionbit+'\nthistrio: '+thistrio);
					document.getElementById(collectionbit + thistrio).style.display = 'none';
				}
	
				newh = 97;
				document.getElementById('expansion1-1').style.height = newh + 'px';
	
				// Switch button underneath to say "Show More"
				document.getElementById('showmore1-1').className = 'showmore';
				window.expansion1collection1 = 0;

				/* document.getElementById('expansion1-expander1').className = 'selectorLink';
				document.getElementById('expansion1-expander1-button').className = 'selectorButton'; */
			}
	
			if(document.getElementById('expansion1-expander2').className == 'selectorLinkHighlighted') {
				// alert('redux 1-2');
				collectionbit = 'collection1-2-';
	
				for(i=1; i<window.expansion1collection2levels; i++) {
					thistrio = i + 1;
					// alert('and hide: ' + collectionbit+'\nthistrio: '+thistrio);
					document.getElementById(collectionbit + thistrio).style.display = 'none';
				}
	
				newh = 97;
				document.getElementById('expansion1-2').style.height = newh + 'px';
	
				// alert(typeof(document.getElementById('showmore1-2')));
				// if(typeof(document.getElementById('showmore1-2'))!=null) {
				if(document.getElementById('showmore1-2')!=null) {
					// Switch button underneath to say "Show More"
					document.getElementById('showmore1-2').className = 'showmore';
				}
				window.expansion1collection2 = 0;

				/* document.getElementById('expansion1-expander2').className = 'selectorLink';
				document.getElementById('expansion1-expander2-button').className = 'selectorButton'; */
			}
	
			if(document.getElementById('expansion1-expander3').className == 'selectorLinkHighlighted') {
				// alert('redux 1-3');
				collectionbit = 'collection1-3-';
	
				for(i=1; i<window.expansion1collection3levels; i++) {
					thistrio = i + 1;
					// alert('and hide: ' + collectionbit+'\nthistrio: '+thistrio);
					document.getElementById(collectionbit + thistrio).style.display = 'none';
				}
	
				newh = 97;
				document.getElementById('expansion1-3').style.height = newh + 'px';
	
				// Switch button underneath to say "Show More"
				document.getElementById('showmore1-3').className = 'showmore';
				window.expansion1collection3 = 0;

				/* document.getElementById('expansion1-expander3').className = 'selectorLink';
				document.getElementById('expansion1-expander3-button').className = 'selectorButton'; */
			}
		}

	} // End of if window.useexpansion2 AND window.usealternateswitcher are in use (meaning we have two expansions on show AND want to cross switch).




	// alert('expansionname: '+expansionname+'\nexpander: '+expander)
	// document.getElementById('debug1').innerHTML = '<p>expansionname: '+expansionname+'<br />expander: '+expander+'</p>';

	fullid = expansionname + '-';
	expanderid = fullid + 'expander';

	if(expander=='1'){
		window['currexpander'+expansionnum] = 1;
		document.getElementById(expanderid+'1').className = 'selectorLinkHighlighted';
		document.getElementById(expanderid+'2').className = 'selectorLink';
		document.getElementById(expanderid+'3').className = 'selectorLink';
		document.getElementById(expanderid+'1-button').className = 'selectorButtonHighlighted';
		document.getElementById(expanderid+'2-button').className = 'selectorButton';
		document.getElementById(expanderid+'3-button').className = 'selectorButton';
		document.getElementById(fullid+'1').style.display = 'block';
		document.getElementById(fullid+'2').style.display = 'none';
		document.getElementById(fullid+'3').style.display = 'none';
	}

	if(expander=='2'){
		window['currexpander'+expansionnum] = 2;
		document.getElementById(expanderid+'1').className = 'selectorLink';
		document.getElementById(expanderid+'2').className = 'selectorLinkHighlighted';
		document.getElementById(expanderid+'3').className = 'selectorLink';
		document.getElementById(expanderid+'1-button').className = 'selectorButton';
		document.getElementById(expanderid+'2-button').className = 'selectorButtonHighlighted';
		document.getElementById(expanderid+'3-button').className = 'selectorButton';
		document.getElementById(fullid+'1').style.display = 'none';
		document.getElementById(fullid+'2').style.display = 'block';
		document.getElementById(fullid+'3').style.display = 'none';
	}

	if(expander=='3'){
		window['currexpander'+expansionnum] = 3;
		document.getElementById(expanderid+'1').className = 'selectorLink';
		document.getElementById(expanderid+'2').className = 'selectorLink';
		document.getElementById(expanderid+'3').className = 'selectorLinkHighlighted';
		document.getElementById(expanderid+'1-button').className = 'selectorButton';
		document.getElementById(expanderid+'2-button').className = 'selectorButton';
		document.getElementById(expanderid+'3-button').className = 'selectorButtonHighlighted';
		document.getElementById(fullid+'1').style.display = 'none';
		document.getElementById(fullid+'2').style.display = 'none';
		document.getElementById(fullid+'3').style.display = 'block';
	}


	// Enlarge his sub rows automatically
	// We know that for this one the collectionname will be in the form "collectionN-1" where N is expansionnum
	collectionbit = 'collection' + expansionnum + '-' + expander + '-';

	// alert('collectionbit: '+collectionbit+'\nnumrows: '+numrows)

	// already showing the first one, let's show the rest (from 1 to total-1)
	for(i=1; i<numrows; i++) {
		thistrio = i + 1;
		// alert('also show: ' + collectionbit+'\nthisone: '+thisone);
		document.getElementById(collectionbit + thistrio).style.display = 'block';
	}


	if(expansionnum == 1) {
		if(expander==3){
			// not sure why but one was stupid
			newh = (82 * numrows) + 12;
		}
		else if(expander==2) {
			// When both NEW AND USED cars selectors are present...
			// the inflater is switched off at present
			if(window.inflatesmartholder==1) {
				// ... we need to blow up the inflator for SMART.
				document.getElementById('smartinflater').style.height = '190px';	/* 110px for two rows */

				// extend the bg as well 
				newh = (82 * numrows) + 191;
			}

			else {
				// should be +14 normally
				newh = (82 * numrows) + 15;
			}

		}
		else {
			newh = (82 * numrows) + 11;
		}
	}

	// the second expansion may not always be in use
	if(expansionnum == 2) {
		if(expander==3){
			// not sure why but one was stupid
			newh = (82 * numrows) + 14;
		}
		else if(expander==2) {
			newh = (82 * numrows) + 15;
		}
		else {
			newh = (82 * numrows) + 9;
		}
	}

	thebg = expansionname + '-' + expander;
	document.getElementById(thebg).style.height = newh + 'px';

	// Switch button underneath to say "Show Less" not "Show More"
	thisshowmore = 'showmore' + expansionnum + '-' + expander;

	// because not all of them have a show more/less button
	// alert(typeof(document.getElementById(thisshowmore)))
	// NB: typeof presents problems (it could be string or null anyway)


	// typeof didn't work
	// if(typeof(document.getElementById(thisshowmore))!=null) {
	if(document.getElementById(thisshowmore)!=null) {
		/* if(expansionnum==2&&expander==2){
			alert('switching show more/less button\nthisshowmore: '+thisshowmore+'\nclassName: '+document.getElementById(thisshowmore).className);
		} */
		document.getElementById(thisshowmore).className = 'showless';
	}
	/* else {
		alert('thisshowmore failed, was: '+thisshowmore)
	} */

	// call up function to set toggle for next time - didn't work
	// setToggleForNextTime(expansionnum,expander)

	// Set a reminder of whether that is on or off
	window['expansion' + expansionnum + 'collection' + expander] = 1;
	// alert('show or hide is: '+window['expansion' + expansionnum + 'collection' + expander])

} // End of function showExpander






function hideExpander(expansionnum,expansionname,expander,numrows) {
		// alert('hide expander, numrows:'+numrows);
		selectorlink = 'expansion' + expansionnum + '-expander' + expander;
		selectorbutton = selectorlink + '-button';
		collectionbit = 'collection' + expansionnum + '-' + expander + '-';
		expansionbit = 'expansion' + expansionnum + '-' + expander;
		showmorebit = 'showmore' + expansionnum + '-' + expander;

		for(i=1; i<numrows; i++) {
			thistrio = i + 1;
			// alert('and hide: ' + collectionbit+'\nthistrio: '+thistrio);
			document.getElementById(collectionbit + thistrio).style.display = 'none';
		}


		// When both NEW AND USED cars selectors are present, then on the USED CARS selector
		// we need to let down the inflatable balloon which SMART has.
		if(window.inflatesmartholder==1) {
			if(expansionnum == 1) {
				if(expander==2) {
					// reduce the inflator for smart back to normal spacer size
					document.getElementById('smartinflater').style.height = '14px';
				}
			}
		}

		// Some weirdness for NEW CARS: SMART (or any future one with not many cars), where there is only one row
		if (numrows == 1) {
			newh = 97;
		}
		else {
			newh = 97;
		}
		document.getElementById(expansionbit).style.height = newh + 'px';

		// typeof didn't work
		// if(typeof(document.getElementById(showmorebit))!=null) {
		if(document.getElementById(showmorebit)!=null) {
			// Switch button underneath to say "Show More"
			document.getElementById(showmorebit).className = 'showmore';
		}

		window['expansion' + expansionnum + 'collection' + expander] = 0;

		// Unhighlight the selectorButton
		/* document.getElementById(selectorlink).className = 'selectorLink';
		document.getElementById(selectorbutton).className = 'selectorButton'; */
} // End of function hideExpander









function enlargeExpander(expansionnum,expansionname,expander,collectionname,levels) {
	// Only if there are enough levels for this operation to work
	if(levels>1) {

		// alert('expansionname: '+expansionname+'\nexpander: '+expander)
		// document.getElementById('debug2').innerHTML = '<p>expansionname: '+expansionname+'<br />expander: '+expander+'</p>';

		fullid = expansionname + '-';
		expanderid = fullid + 'expander';
		collectionid = collectionname + '-';
	

		thisoneon = window['expansion' + expansionnum + 'collection'+expander];
		thisviewer = 'viewer' + expansionnum + '-' + expander;
		thisshowmore = 'showmore' + expansionnum + '-' + expander;

		// alert('thisoneon: '+thisoneon)

		// toggle the extra divs on/off
		if(thisoneon == 1) {
			// HIDE IT
			// 1) adjust the height of the background layer.
			newh = 97;
			document.getElementById(fullid+expander).style.height = newh + 'px';
			// document.getElementById(thisviewer).className = 'ViewButtonMore';
			document.getElementById(thisshowmore).className = 'showmore';

			// 2) show the extra hidden divs	
			smeg = levels + 1;
			for(i=2;i<smeg;i++) {
				document.getElementById(collectionid+i).style.display = 'none';
			}			
		}
		else {
			// SHOW IT
			// 1) adjust the height of the background layer.

			if(expansionnum == 1) {
				if(expander==3){
					// not sure why but one was stupid
					newh = (82 * levels) + 12;
				}
				else if(expander==2) {
					newh = (82 * levels) + 14;
				}
				else {
					newh = (82 * levels) + 11;
				}
			}

			// the second expansion may not always be in use
			if(expansionnum == 2) {
				if(expander==3){
					// not sure why but one was stupid
					newh = (82 * levels) + 14;
				}
				else if(expander==2) {
					newh = (82 * levels) + 14;
				}
				else {
					newh = (82 * levels) + 9;
				}
			}

			document.getElementById(fullid+expander).style.height = newh + 'px';
			// document.getElementById(thisviewer).className = 'ViewButtonLess';
				document.getElementById(thisshowmore).className = 'showless';
	
			// 2) show the extra hidden divs	
			for(i=2;i<levels+1;i++) {
				document.getElementById(collectionid+i).style.display = 'block';
			}		
		}


		// 3) call up function to set toggle for next time
		setToggleForNextTime(expansionnum,expander)

	}
}







function setToggleForNextTime(expansionnum,expander) {
	
	// alert('setToggleForNextTime called with\nexpansionnum: '+expansionnum+'\nexpander: '+expander);
	
	// FIRST EXPANDER
	if (expansionnum==1&&expander==1){
		if(window.expansion1collection1==0){ window.expansion1collection1 = 1; }
		else { window.expansion1collection1 = 0; }
	}
	
	if (expansionnum==1&&expander==2){
		if(window.expansion1collection2==0){ window.expansion1collection2 = 1; }
		else { window.expansion1collection2 = 0; }
	}
	
	if (expansionnum==1&&expander==3){
		if(window.expansion1collection3==0){ window.expansion1collection3 = 1; }
		else { window.expansion1collection3 = 0; }
	}
	
	// SECOND EXPANDER
	if (expansionnum==2&&expander==1){
		if(window.expansion2collection1==0){ window.expansion2collection1 = 1; }
		else { window.expansion2collection1 = 0; }
	}
	
	if (expansionnum==2&&expander==2){
		if(window.expansion2collection2==0){ window.expansion2collection2 = 1; }
		else { window.expansion2collection2 = 0; }
	}
	
	if (expansionnum==2&&expander==3){
		if(window.expansion2collection3==0){ window.expansion2collection3 = 1; }
		else { window.expansion2collection3 = 0; }
	}

}





// The next function assigns the latest choices to hidden fields and submits a hidden form
function setSelectorSearch(themake,themodelid) {
	document.getElementById('selector_secret_car_make_chosen').value = themake;
	document.getElementById('selector_secret_car_model_chosen').value = themodelid;
	document.getElementById('selectorsecretform').submit();
	// alert('the assigned make is: '+document.getElementById('secret_car_make_chosen').value)
}


