﻿/*

	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://www.jasonalden.com/site/wp-content/uploads/2010/02/folio_jalden001.jpg','http://www.jasonalden.com/site/wp-content/uploads/2010/02/folio_jalden002.jpg','http://www.jasonalden.com/site/wp-content/uploads/2010/02/folio_jalden023.jpg','img/4.jpg'];

// how many times should the photo change per page load
var maxChanges = myImages.length * 10;

// 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 = true;

// number of seconds between photo changes
var seconds_between_photos = 6;

// name of DIV to load photos into
var div_name = "loader";


*/

//<script type="text/javascript">

// Flexible Image Slideshow- By JavaScriptKit.com (http://www.javascriptkit.com)
// For this and over 400+ free scripts, visit JavaScript Kit- http://www.javascriptkit.com/
// This notice must stay intact for use

var ultimateshow=new Array()

//ultimateshow[x]=["path to image", "OPTIONAL link for image", "OPTIONAL link target"]

ultimateshow[0]=['http://www.jasonalden.com/site/wp-content/uploads/2010/02/folio_jalden001.jpg', 'http://www.jasonalden.com/site/index.php/gallery/', '_new']
ultimateshow[1]=['http://www.jasonalden.com/site/wp-content/uploads/2010/02/folio_jalden002.jpg', 'http://www.jasonalden.com/site/index.php/gallery/', '_new']
ultimateshow[2]=['http://www.jasonalden.com/site/wp-content/uploads/2010/02/folio_jalden023.jpg', 'http://www.jasonalden.com/site/index.php/gallery/', '_new']

//configure the below 3 variables to set the dimension/background color of the slideshow

var slidewidth="900px" //set to width of LARGEST image in your slideshow
var slideheight="576px" //set to height of LARGEST iamge in your slideshow
var slidecycles="25" //number of cycles before slideshow stops (ie: "2" or "continous")
var randomorder="yes" //randomize the order in which images are displayed? "yes" or "no"
var preloadimages="no" //preload images? "yes" or "no"

//configure the below variable to determine the delay between image rotations (in miliseconds)
var slidedelay=3000

////Do not edit pass this line////////////////

var ie=document.all
var dom=document.getElementById
var curcycle=0

if (preloadimages=="yes"){
for (i=0;i<ultimateshow.length;i++){
var cacheimage=new Image()
cacheimage.src=ultimateshow[i][0]
}
}

var currentslide=0

function randomize(targetarray){
ultimateshowCopy=new Array()
var the_one
var z=0
while (z<targetarray.length){
the_one=Math.floor(Math.random()*targetarray.length)
if (targetarray[the_one]!="_selected!"){
ultimateshowCopy[z]=targetarray[the_one]
targetarray[the_one]="_selected!"
z++
}
}
}

if (randomorder=="yes")
randomize(ultimateshow)
else
ultimateshowCopy=ultimateshow

function rotateimages(){
curcycle=(currentslide==0)? curcycle+1 : curcycle
ultcontainer='<center>'
if (ultimateshowCopy[currentslide][1]!="")
ultcontainer+='<a href="'+ultimateshowCopy[currentslide][1]+'" target="'+ultimateshowCopy[currentslide][2]+'">'
ultcontainer+='<img src="'+ultimateshowCopy[currentslide][0]+'" border="0">'
if (ultimateshowCopy[currentslide][1]!="")
ultcontainer+='</a>'
ultcontainer+='</center>'
if (ie||dom)
crossrotateobj.innerHTML=ultcontainer
if (currentslide==ultimateshow.length-1) currentslide=0
else currentslide++
if (curcycle==parseInt(slidecycles) && currentslide==0)
return
setTimeout("rotateimages()",slidedelay)
}

if (ie||dom)
document.write('<div id="slidedom" style="width:'+slidewidth+';height:'+slideheight+'; background-color:'+slidebgcolor+'"></div>')

function start_slider(){
crossrotateobj=dom? document.getElementById("slidedom") : document.all.slidedom
rotateimages()
}

if (ie||dom)
window.onload=start_slider

</script>

<p style="font: normal 11px Arial">This free script provided by<br />
<a href="http://www.javascriptkit.com">JavaScript Kit</a></p>







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); 



