// Main parameters
home_pics = ['louise_douglas_01', 'louise_douglas_02', 'louise_douglas_03', 'louise_douglas_04', 'louise_douglas_05', 'louise_douglas_06', 'louise_douglas_07'];
img_path = 'home_files';
img_ext = '.jpg';
interval = 1000;  // Delay (ms) for displaying home images

font_image_selector = '<font size="3" face="Verdana">';

num_pics = home_pics.length;

// Set up large image objects
if (document.images) {
	images = new Array(num_pics);
	for(n=0; n<num_pics; n++) {
		images[n] = new Image;
		large_image_file = img_path + '/' + home_pics[n] + img_ext;
		if (n==0) {
			// Set initial large image
			document.write('<div id="home_pic">');
			document.write(
				'<a href="collection.html"><img class="home_pic" id="home_img" name="home_img" src="' + large_image_file +
				'" height="500px" border="0" alt="Home image" title="See Louise Douglas collection"></a>');
			document.write('</div>');	

		}
		if (n==1) {
			document.write('<div id="home_pic_bg">');
			document.write(
				'<img class="home_pic_bg" id="home_img_bg" name="home_img_bg" src="' + large_image_file +
				'" height="500px" border="0" alt="Home image">');	
			document.write('</div>');	
		}
		// Large image object
		images[n].src = large_image_file;
	}
	op = 1;
	document.getElementById("home_img").style.opacity = op;
	document.getElementById("home_img_bg").style.opacity = 0;
}

// Image selectors
document.write('<div id="home_pic_select">');
document.write('</div>');
set_image_selectors(0);

// Initialize call to animation function
display_image(0, 1, 1);

var t;

function display_image(n, opacity, animate) {
	interval_hold = 2000;
	interval_transition = 25;
	opacity_step = 0.04;
	n_next = n+1; if(n_next>=num_pics) {n_next=0;}  // next image index
	if (opacity==1) {
		document['home_img'].src = images[n].src;
		document.getElementById("home_img").style.opacity = opacity;
		document['home_img_bg'].src = images[n_next].src;
		document.getElementById("home_img_bg").style.opacity = 0;
		if (animate) {
			opacity -= opacity_step;
			interval = interval_hold;
			animate_next = 1;
		}
	} else {
		if (opacity>=0) {
			document.getElementById("home_img").style.opacity = 1; //opacity;
			//document.getElementById("home_img_bg").style.opacity = 1-opacity;
			if (animate) {
				opacity -= opacity_step;
				interval = interval_transition*opacity_step;
				if (Math.abs(opacity-0.5)<opacity_step) // Half way through transition
					{set_image_selectors(n_next);}
				animate_next = 1;
			} 
		} else {
			n = n_next;
			opacity = 1;
			interval = 0;
			animate_next = (n>0); // don't animate if back to start
		}
	}
	if (animate) {
		t = setTimeout('display_image(' 
			+ n.toString() + ', ' + opacity.toString() + ', ' + animate_next.toString() + ')', interval);
	}
}

function set_image_selectors(m) {
	str = '';
	for (n=0; n<num_pics; n++) {
		if (n==m) 
			{s1='<font color="white">'; s2='</font>'}
		else
			{s1='<font color="#C3C3C0">'; s2='</font>'};
		str += '<a class="plain" style="cursor:pointer" onClick=\'change_image(' + n.toString() + ')\'>' + 
				font_image_selector + s1 + '&#8226 ' + s2;
	}
	document.getElementById("home_pic_select").innerHTML = str;
}

function change_image(n) {
	clearTimeout(t);
	display_image(n, 1, 0);
	set_image_selectors(n);
}

