imgs =["/images-headers/head5.jpg","/images-headers/sheep.jpg","/images-headers/prize-cow.jpg","/images-headers/prize-sheep.jpg","/images-headers/head7.jpg","/images-headers/sheep-lineup.jpg","/images-headers/goat-eating.jpg","/images-headers/purple-flower.jpg","/images-headers/man-with-horse.jpg","/images-headers/bread-basket.jpg","/images-headers/donkey-kiss.jpg","/images-headers/kids-in-tank.jpg","/images-headers/horse-jumping.jpg","/images-headers/fruit-salads.jpg","/images-headers/head13.jpg","/images-headers/head2.jpg","/images-headers/head6.jpg","/images-headers/garden-in-tent.jpg","/images-headers/head10.jpg","/images-headers/head4.jpg","/images-headers/head8.jpg","/images-headers/head1.jpg","/images-headers/prize-bull-2.jpg","/images-headers/husky.jpg","/images-headers/strawberries.jpg","/images-headers/head9.jpg","/images-headers/head18.jpg","/images-headers/diners.jpg","/images-headers/llamas.jpg","/images-headers/head3.jpg","/images-headers/metal-working.jpg","/images-headers/cow-licking-lips.jpg","/images-headers/rubies.jpg","/images-headers/pig-winning-prize.jpg","/images-headers/fauna.jpg","/images-headers/dog-race.jpg","/images-headers/heavy-horse.jpg","/images-headers/pig.jpg","/images-headers/prize-bull.jpg","/images-headers/rubies-2.jpg","/images-headers/cheeses.jpg","/images-headers/head11.jpg","/images-headers/biker.jpg","/images-headers/pig-trophy.jpg","/images-headers/sheep-truck.jpg","/images-headers/scurry-driving.jpg","/images-headers/child-with-calf.jpg"];




function slideshow(imageArray, divID) {
	var loaded = false;
	var preloader = new Image;
	var imgs = imageArray;
	var div = null;
	var img = null;
	var index = null;
	var pause = null;
	var delay = null;
	var step = null;
	var opacity = null;
	var timer = null;

	this.init = function() {
		div = document.getElementById(divID);
		img = div.getElementsByTagName("img")[0];
		index = 0;
		pause = 2;
		delay = 50;
		step = 0.05;
		opacity = 1; // 0 to 1
		preloader.onload = preloaded;
		preloader.src = imgs[index];
		start();
	}

	// do the initial setup
	var start = function() {
		img.src = imgs[index];
		index++;
		loadNew();
		timer = setTimeout(changeImages, pause*1000);
	}


	// start preloading a new image into the div
	var loadNew = function() {
		loaded = false;
		preloader.src = imgs[index];
	}

	// the new image has finished preloading - load it into the div
	var preloaded  = function() {
		loaded = true;
		div.style.backgroundImage = "url('" + imgs[index] + "')";
	}

	// move the image displaying in the div to the image tag
	var swapImages = function() {
		img.src = imgs[index];

		// increase the opacity now that we've put a new image in
		opacity = 1;
		img.style.opacity = opacity;
		if (window.ActiveXObject) img.style.filter = "alpha (opacity=" + (opacity*100) + ")";

		// increment the index counter and load a new image
		index >= imgs.length-1 ? index = 0 : index++;
		loadNew();
	}

	// fade the top image out
	var fadeOut = function() {
		opacity-=step;
		img.style.opacity = opacity;
		if (window.ActiveXObject) img.style.filter = "alpha (opacity=" + (opacity*100) + ")";
		if (opacity > 0) timer = setTimeout(fadeOut, delay);
		else {
			// the image has faded out - move the div image to the front
			swapImages();
			timer = setTimeout(changeImages, pause*1000);
		}

	}

	var changeImages = function() {

		if (loaded == true) {
			// start fading out top image
			fadeOut();
		} else {
			// new image not yet loaded - check back again soon
			timer = setTimeout(changeImages, pause*1000);
		}
	}


}


var slides = new slideshow(imgs,"slides");