﻿/*

	Started on June 6, 2008 with code from

		Jeffrey Jordan Way, a Web Developer from Nashville, TN
			detacheddesigns.com in a post called " Why Aren't You Using jQuery: PART 3"

		http://www.detacheddesigns.com/blog/blogSpecific.aspx?BlogId=62
		http://www.detacheddesigns.com/blog/files/jQueryImageGallery.zip
		http://www.detacheddesigns.com/blog/samples/jQueryImageGallery/gallery.htm

	This revision by David Van Vickle - http://www.davidvanvickle.com
		
		Added
			Randomness
			Shuffling
			Automatic transitions
		Removed
			Thumbnails
	
*/

// change these paths for your images
var myImages = ['http://mediafiles.thedms.co.uk/publication/nn/headers/header-img0.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img1.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img2.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img3.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img4.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img5.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img6.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img7.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img8.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img9.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img10.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img11.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img12.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img13.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img14.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img15.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img16.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img17.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img18.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img19.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img20.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img21.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img22.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img23.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img24.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img25.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img26.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img27.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img28.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img29.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img28.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img31.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img30.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img33.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img32.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img35.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img34.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img37.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img36.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img39.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img38.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img41.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img40.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img43.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img42.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img45.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img44.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img47.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img46.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img49.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img48.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img51.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img50.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img53.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img52.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img55.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img54.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img57.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img56.jpg', 'http://mediafiles.thedms.co.uk/publication/nn/headers/header-img59.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img66.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img67.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img68.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img69.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img70.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img71.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img72.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img73.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img74.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img75.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img76.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img77.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img78.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img79.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img80.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img81.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img82.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img83.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img84.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img85.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img86.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img87.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img88.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img89.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img90.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img91.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img92.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img93.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img94.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img95.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img96.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img97.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img98.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img99.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img101.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img102.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img103.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img104.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img105.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img106.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img107.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img108.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img109.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img110.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img111.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img112.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img113.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img114.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img115.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img116.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img117.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img118.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img119.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img120.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img121.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img122.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img123.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img124.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img125.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img126.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img127.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img128.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img129.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img130.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img131.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img132.jpg','http://mediafiles.thedms.co.uk/publication/nn/headers/header-img133.jpg'];

// how many times should the photo change per page load
var maxChanges = myImages.length * 2;

// shuffle images so each time page loads, the photos show in different order
var do_shuffle = true;

// use simple randomness instead of shuffling (tends to repeat images too often)
var do_randomly = false;

// number of seconds between photo changes
var seconds_between_photos = 5;

// name of DIV to load photos into
var div_name = "loader";








var changes = 0;
var timer;
var thisImg = myImages.length - 1;

//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/array/shuffle [v1.0]

shuffle = function(o){ //v1.0
	for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
	return o;
};




// shuffling is better than random because of less potential repetition
if (do_shuffle) {
	myImages = shuffle(myImages);	
}



function nextImage () {
	
	var low = 0;
	var high = myImages.length - 1;
	var rand_no = Math.floor((high-(low - 1))*Math.random()) + low;
	
	thisImg++;
	changes++;
	if (thisImg==myImages.length) {
		thisImg = 0;
	}
	if (changes==maxChanges) {
		clearInterval(timer);
	}
	if (do_randomly) {
		thisImg = rand_no;
		return myImages[rand_no];
	} else {
		return myImages[thisImg];
	}
}

function changeImage () {
	
	var t = myImages[thisImg];
	var n = nextImage();
	
	if (t != n) {
		$("#"+div_name).addClass("loading");
		showImage(n);
	} else { 
		changeImage();
	}
}

function showImage(src)
{
	$("#"+div_name+" img").fadeOut("normal").remove();
	var largeImage = new Image();
	$(largeImage).load(function()
                        {
							$(this).hide();
                        	$("#"+div_name).append(this).removeClass("loading");
                                             
                       		$(this).fadeIn("slow");              
                        });    
	$(largeImage).attr("src", src);                                                                               
}

function checkForLoaded () {
	if (document.getElementById(div_name) != null) {
		//alert("loaded");
		clearInterval(timer);
		changeImage();
		timer = setInterval(changeImage, (seconds_between_photos * 1000));
	}
}

// check every second to see if DIV exists, when it does, start photo changing timer
timer = setInterval(checkForLoaded, 500); 


