//categories
// general = 1
// lawnmowers = 2
// ride-ons = 3
// vacs-blowers = 4
// brushcutters = 5
// hedgetrimmers = 6
// chainsaws = 7
// tillers-cultivators = 8
// chippers-shredders = 9
// other-garden-machinery = 10

// JavaScript Document
	var theImages = new Array(); // do not change this
	var theBaURLs = new Array();
	var used = new Array();
	var theCatego = new Array();
	var theTitleA = new Array();
	theImages[0] = '/adverts/ad1.gif';
	theBaURLs[0] = 'http://www.mowdirect.co.uk/acatalog/NEW__MTD_PETROL_LAWNMOWER_RANGE_.html';
	theCatego[0] = 2;
	theTitleA[0] = 'Lower imissions great performance. Fantastic Prices';
	
	theImages[1] = '/adverts/ad2.gif';
	theBaURLs[1] = 'http://www.mowdirect.co.uk/acatalog/GARDENA_HEDGETRIMMERS.html';
	theCatego[1] = 6;
	theTitleA[1] = 'Reach the heights - telescopic trimmer only £139';
	
	theImages[2] = '/adverts/ad3.gif';
	theBaURLs[2] = 'http://www.mowdirect.co.uk/acatalog/HAYTER_SPIRIT_LAWNMOWERS.html';
	theCatego[2] = 2;
	theTitleA[2] = 'Hayter Spirit Lawnmowers';
	
	theImages[3] = '/adverts/ad4.gif';
	theBaURLs[3] = 'http://www.mowdirect.co.uk/acatalog/HONDA_LAWNMOWERS.html';
	theCatego[3] = 2;
	theTitleA[3] = 'Honda HRX Range, This changes everything.';
	
	theImages[4] = '/adverts/ad31.gif';
	theBaURLs[4] = 'http://www.mowdirect.co.uk/acatalog/ALKO_LAWNMOWERS__PETROL_ROTARY_.html#a2858';
	theCatego[4] = 2;
	theTitleA[4] = "Garden's World Winner - 460B classic Best for big gardens.";
	
	theImages[5] = '/adverts/ad6.gif';
	theBaURLs[5] = 'http://www.mowdirect.co.uk/acatalog/MowDIRECT_SALE_BEGINS_NOW__444.html';
	theCatego[5] = 1;
	theTitleA[5] = 'Spring Super Sale save ££££s';

	theImages[6] = '/adverts/ad7.gif';
	theBaURLs[6] = 'http://www.mowdirect.co.uk/acatalog/RE.MOW_BATTERY_POWERED_CORDLESS_LAWN_MOWER.html';
	theCatego[6] = 2;
	theTitleA[6] = 'Re.Mow mow mow mow with this cordless mower';

	theImages[7] = '/adverts/ad8.gif';
	theBaURLs[7] = 'http://www.mowdirect.co.uk/acatalog/MowDIRECT_MTD_LAWNFLITE_LAWN_TRACTORS_93.html';
	theCatego[7] = 3;
	theTitleA[7] = 'LawnFlite The UKs most popular tractors';

	theImages[8] = '/adverts/ad9.gif';
	theBaURLs[8] = 'http://www.mowdirect.co.uk/acatalog/MOUNTFIELD_RIDE_ON_TRACTOR_MOWERS.html';
	theCatego[8] = 3;
	theTitleA[8] = 'A Huge cut, a bigger discount £300off';

	theImages[9] = '/adverts/ad10.gif';
	theBaURLs[9] = 'http://www.mowdirect.co.uk/acatalog/ELIET_PETROL_CHIPPER_SHREDDERS.html';
	theCatego[9] = 9;
	theTitleA[9] = 'Its All about technique, the Eliet Chopper experience';

	theImages[10] = '/adverts/ad11.gif';
	theBaURLs[10] = 'http://www.mowdirect.co.uk/acatalog/BILLY_GOAT.html';
	theCatego[10] = 4;
	theTitleA[10] = 'Nothing is too much for a Billy Goat';

	theImages[11] = '/adverts/ad12.gif';
	theBaURLs[11] = 'http://www.mowdirect.co.uk/acatalog/LAWNMOWERS_HAYTER_CRAZY.html';
	theCatego[11] = 2;
	theTitleA[11] = 'Just when you thought it was safe to go back in the garden! Hayter lawnmowers have fins to improve the cut';

	theImages[12] = '/adverts/ad13.gif';
	theBaURLs[12] = 'http://www.mowdirect.co.uk/acatalog/EFCO_BRUSHCUTTERS_GRASS_TRIMMERS.html';
	theCatego[12] = 5;
	theTitleA[12] = 'Professional Quality Brushcutters safe upto £150';

	theImages[13] = '/adverts/ad14.gif';
	theBaURLs[13] = 'http://www.mowdirect.co.uk/acatalog/WHEELED_TRIMMER_MOWERS.html';
	theCatego[13] = 10;
	theTitleA[13] = 'Dr - the original trimmer mower';

	theImages[14] = '/adverts/ad15.gif';
	theBaURLs[14] = 'http://www.mowdirect.co.uk/acatalog/LAWNMOWERS_MOUNTFIELD.html';
	theCatego[14] = 2;
	theTitleA[14] = 'Britains favourite mower No 1';

	theImages[15] = '/adverts/ad16.gif';
	theBaURLs[15] = 'http://www.mowdirect.co.uk/acatalog/MowDIRECT_TANAKA_PETROL_HEDGECUTTERS_1088.html';
	theCatego[15] = 6;
	theTitleA[15] = 'Tanaka the original lightweight trimmers';

	theImages[16] = '/adverts/ad17.gif';
	theBaURLs[16] = 'http://www.mowdirect.co.uk/acatalog/MANTIS_TILLERS_CULTIVATOR_.html';
	theCatego[16] = 8;
	theTitleA[16] = '1 tiller 5 attachments - Mantis makes gardening a breeze';

	theImages[17] = '/adverts/ad18.gif';
	theBaURLs[17] = 'http://www.mowdirect.co.uk/acatalog/MowDIRECT_CORDLESS___BATTERY_POWERED_LAWN_MOWERS_949.html';
	theCatego[17] = 2;
	theTitleA[17] = 'Dedicated to environmentally friendly products - Enviromower';
	
	theImages[18] = '/adverts/ad19.gif';
	theBaURLs[18] = 'http://www.mowdirect.co.uk/acatalog/MowDIRECT_NEW__ATTACHMENTS__RIDE_ON_MOWERS_GARDEN_TRACTORS__15.html';
	theCatego[18] = 3;
	theTitleA[18] = 'Turn your ride-on into a workhorse - Agri-Fab fits all brands of Ride-On';
	
	theImages[19] = '/adverts/ad20.gif';
	theBaURLs[19] = 'http://www.mowdirect.co.uk/acatalog/MowDIRECT_CLEAN_UP_WITH_MowDIRECT_THE_EASY_WAY__914.html';
	theCatego[19] = 1;
	theTitleA[19] = 'Clean up in spring the easy way';
	
	theImages[20] = '/adverts/ad21.gif';
	theBaURLs[20] = 'http://www.mowdirect.co.uk/acatalog/MTD_.html';
	theCatego[20] = 8;
	theTitleA[20] = 'MTD T245 5.5HP Petrol Cultivator only £389';
		
	theImages[21] = '/adverts/ad23.gif';
	theBaURLs[21] = 'http://www.mowdirect.co.uk/acatalog/CYLINDER_LAWNMOWERS_WITH_FREE_SCARIFIER_CASSETTES_.html';
	theCatego[21] = 2;
	theTitleA[21] = 'Atco Cylinder Mowers with Scarifier';
	
	theImages[22] = '/adverts/ad24.gif';
	theBaURLs[22] = 'http://www.mowdirect.co.uk/acatalog/MowDIRECT_MULCHING__IT_S_A_NEW_APPROACH_TO_LAWNCARE__1154.html';
	theCatego[22] = 3;
	theTitleA[22] = 'Mulching Garden Tractor that Stripes only £2099';
	
	theImages[23] = '/adverts/ad25.gif';
	theBaURLs[23] = 'http://www.mowdirect.co.uk/acatalog/RIDE_ON_MOWERS_ONLY__899_.html';
	theCatego[23] = 3;
	theTitleA[23] = 'Ride-ons Cheapest on the web - guaranteed';
	
	theImages[24] = '/adverts/ad26.gif';
	theBaURLs[24] = 'http://www.mowdirect.co.uk/acatalog/LAWNFLITE_SHANKS_PROFESSIONAL_LAWNMOWERS.html';
	theCatego[24] = 2;
	theTitleA[24] = 'Lawnflite Pro 1yrs professional Guarantee';
		
	theImages[25] = '/adverts/ad27.gif';
	theBaURLs[25] = 'http://www.mowdirect.co.uk/acatalog/RIDE_ON_TRACTORS_KAWASAKI_ENGINES.html';
	theCatego[25] = 3;
	theTitleA[25] = 'Cub Cadet Garden Tractors - All the power you need and more.';
	
	theImages[26] = '/adverts/ad30.gif';
	theBaURLs[26] = 'http://www.mowdirect.co.uk/acatalog/VICTUS_PETROL_CHAINSAWS.html';
	theCatego[26] = 7;
	theTitleA[26] = 'Victus Petrol Chainsaw with Free attachements';
	
	theImages[27] = '/adverts/ad32.jpg';
	theBaURLs[27] = 'http://www.mowdirect.co.uk/acatalog/RYOBI_RBC30SES-AQTT_PETROL_BRUSHCUTTER_MINI_CULTIVATOR_COMBI_TOOL_EXCLUSIVE_SPECIAL_OFFER.html';
	theCatego[27] = 5;
	theTitleA[27] = 'Combi Tool - Powerful Petrol Brushcutter - Mini Petrol Cultivator only £179.95';
	
	theImages[28] = '/adverts/ad33.gif';
	theBaURLs[28] = 'http://www.mowdirect.co.uk/acatalog/MowDIRECT_EFCO_PETROL_CHAINSAWS_1036.html';
	theCatego[28] = 7;
	theTitleA[28] = 'Professional Chainsaws * 3 Year Guarantee * Low emission engines * Prices from under £200!';
		
	theImages[29] = '/adverts/ad34.gif';
	theBaURLs[29] = 'http://www.mowdirect.co.uk/acatalog/VICTUS-VB260-STRAIGHT-SHAFT-PETROL-BRUSH-CUTTER---TRIPLE-BONUS-OFFER.html';
	theCatego[29] = 5;
	theTitleA[29] = 'Bonus Offer * 3 times longer life * 3 year guarantee * 3 free accessories Just £149.95!';
	
	theImages[30] = '/adverts/ad35.gif';
	theBaURLs[30] = 'http://www.mowdirect.co.uk/acatalog/EINHELL_RBK-4645_PETROL_CHAIN_SAW___18__GUIDE_BAR.html';
	theCatego[30] = 7;
	theTitleA[30] = 'Powerful Petrol Chainsaw * 46 cc engine * 18” Guide Bar * Just £139.95';
	
	theImages[31] = '/adverts/ad36.gif';
	theBaURLs[31] = 'http://www.mowdirect.co.uk/acatalog/EINHELL_CULTIVATORS_TILLERS_ROTAVATORS.html';
	theCatego[31] = 8;
	theTitleA[31] = 'Exclusive Deals on Cultivators! * Mini Electric - £79.95 * Mini Petrol - £229.95 * 6 HP Petrol - £299.95';
	
	theImages[32] = '/adverts/ad37.gif';
	theBaURLs[32] = 'http://www.mowdirect.co.uk/acatalog/ARDISAM_6014V_COMPACT_REAR_TINE_CULTIVATOR.html';
	theCatego[32] = 8;
	theTitleA[32] = 'New Compact Rear Tine Tiller Just £559!';
	
//categories
// general = 1
// lawnmowers = 2
// ride-ons = 3
// vacs-blowers = 4
// brushcutters = 5
// hedgetrimmers = 6
// chainsaws = 7
// tillers-cultivators = 8
// chippers-shredders = 9
// other-garden-machinery = 10

		

	var j = 0
	var p = theImages.length;
	
	var preBuffer = new Array()
	for (i = 0; i < p; i++){
	   preBuffer[i] = new Image();
	   preBuffer[i].src = theImages[i];
	}
	
	function whichBanner()
	{	var myWhichBanner = Math.round(Math.random()*(p-1));
		//has it been used
		done=false;
		while(done==false)
		{	if(used[myWhichBanner]!="used")
			{	used[myWhichBanner]="used";
				done=true;				
				return myWhichBanner;
			}
			else
			{	
				myWhichBanner = Math.round(Math.random()*(p-1));
			}
		}
	}
	var usedCount = 0;
	var theXBaURLs = new Array();
	var theXImages = new Array();
	var theXTitleA = new Array();
	var usedX = new Array();
	var theXCatego = new Array();
	var doneLoop = false;
	var ii = 0;
	
	function whichCatBanner(catID)
	{	//gonna need to find the correct adverts
		if(catID>10)
		{
			catID=1;
		}
		//only loop through on first go
		//create temporary cats
		if(!doneLoop)
		{	
			//right loop through the lot 
			for (i = 0; i < p; i++)
			{
				//copy into new arrays if they are in the right category
				if(theCatego[i]==catID)
				{	theXBaURLs[ii]=theBaURLs[i];
				    theXTitleA[ii] = theTitleA[i];
				    theXImages[ii++]=theImages[i];
					
				}
			}
			doneLoop = true;
		}
		//now we need to do the next bit
		var pp = theXImages.length;

		var myXWhichBanner = Math.round(Math.random()*(pp-1));
		//are there any adverts
		if(pp>0)
		{
			
			if(usedCount<pp)
			{	var doneX=false;
				while(doneX==false)
				{	if(usedX[myXWhichBanner]!="used")
					{	usedX[myXWhichBanner]="used";
						doneX=true;
						usedCount++;
						//count how many useed
						return myXWhichBanner;
					}
					else
					{	
						myXWhichBanner = Math.round(Math.random()*(pp-1));
					}
				}
			}
			else
			{	return -1;
			}
		}
		else
		{	//display the general adverts
			return 10;
		}
		
	}
	function showCategoryImage(MDactiveTab)
	{	//now do a switch to convert to numerical value
		switch(MDactiveTab)
		{
			case 'lawnmowers':
		  		ad = whichCatImage(2);
		  	break;
			case 'lawntractors':
				ad = whichCatImage(3);
		  	break;
			case 'VacsAndBlowers':
				ad = whichCatImage(4);
		  	break;
			case 'brushcutters':
				ad = whichCatImage(5);
		  	break;
			case 'hedgetrimmersAndCutters':
				ad = whichCatImage(6);
		  	break;
			case 'chainsaws':
				ad = whichCatImage(7);
		  	break;
			case 'culivatorsAndTillers':
				ad = whichCatImage(8);
		  	break;
			case 'chippersAndShredders':
				ad = whichCatImage(9);
		  	break;
			case 'otherGardenMachinery':
				ad = whichCatImage(10);
		  	break;				
			default:
		  	 ad = false;
		}
		if (ad){
			document.write(ad);
		}else{
			showDefaultImage();
		}
	}
	function showImage(MDactiveTab){
		if(MDactiveTab==""||MDactiveTab=="home")
		{	tempWhich = whichBanner();
			document.write('<a href="'+theBaURLs[tempWhich]+'"><img src="'+theImages[tempWhich]+'" border=0 title="'+theTitleA[tempWhich]+'" alt="'+theTitleA[tempWhich]+'"></a>');
		}else{
			showCategoryImage(MDactiveTab);
		}
	}
	function showDefaultImage(){
			tempWhich = whichBanner();
			document.write('<a href="'+theBaURLs[tempWhich]+'"><img src="'+theImages[tempWhich]+'" border=0 title="'+theTitleA[tempWhich]+'" alt="'+theTitleA[tempWhich]+'"></a>');
	}
	function whichCatImage(catID)
	{		
	tempWhich = whichCatBanner(catID);
		if(tempWhich>=0)
		{
			var ad = '<a href="'+theXBaURLs[tempWhich]+'"><img src="'+theXImages[tempWhich]+'" border=0 title="'+theXTitleA[tempWhich]+'" alt="'+theXTitleA[tempWhich]+'"></a>';
			return ad;
		}
		else
		{	return false;
		}
	}