if (document.images) {
	var pic0 = new Image(460,140);
	pic0.src = "images/IMG_0.jpg";

	var pic1 = new Image(460,140);
	pic1.src = "images/IMG_1.jpg";

	var pic2 = new Image(460,140);
	pic2.src = "images/IMG_2.jpg";

	var pic3 = new Image(460,140);
	pic3.src = "images/IMG_3.jpg";

	var pic4 = new Image(460,140);
	pic4.src = "images/IMG_4.jpg";

	var pic5 = new Image(460,140);
	pic5.src = "images/IMG_5.jpg";
}

var countryList = new Array('canada', 'us', 'england_wales', 'scotland', 'ireland', 'germany');
var selectedThumb = null;

function setOpacity(obj, val) {
	if (obj.nodeName != 'A') {
		obj.style.opacity = val;
		obj.style.filter = 'alpha(opacity=' + val*100 + ')';
	}
	else if (obj != selectedThumb) {
		obj.style.opacity = val;
		obj.style.filter = 'alpha(opacity=' + val*100 + ')';
		obj.style.background = "#D4CCC3";
		obj.style.color = "#000000";
	}
	else {
		obj.style.background = "#efdf9c";
		obj.style.color = "#000000";
	}
}

function getOpacity(obj) {
	if ((obj.style.opacity) && (obj.style.opacity != null)) {
		return +obj.style.opacity;
	}
	else {
		return +obj.style.filter.replace('alpha(opacity=', '').replace(')', '');
	}
}

function fade(obj, start, end, time) {
	var increment = 0;
	var s = start;
	var e = end;
	if (start > end){
		s = end;
		e = start;
	}
	if (e - s == 0) {
		return;
	}
	increment = ((e - s) / time) * 20;
	setOpacity(obj, start);
	var t = setInterval(function(){fader(obj, end, increment);}, 1);
	setTimeout(function(){clearInterval(t);}, time);
	setTimeout(function(){setOpacity(obj, end);}, time);
}

function fader(obj, end, increment) {
	var alpha = getOpacity(obj);
	if (end > alpha) {
		setOpacity(obj, alpha + increment);
	}
	else if (end < alpha) {
		setOpacity(obj, alpha - increment);
	}
}

function displayThumbs() {
	fade(document.getElementById('canada_thumb'), 0, .5, 500);
	setTimeout(function(){fade(document.getElementById('us_thumb'), 0, .5, 500)}, 250);
	setTimeout(function(){fade(document.getElementById('england_wales_thumb'), 0, .5, 500)}, 500);
	setTimeout(function(){fade(document.getElementById('scotland_thumb'), 0, .5, 500)}, 750);
	setTimeout(function(){fade(document.getElementById('ireland_thumb'), 0, .5, 500)}, 1000);
	setTimeout(function(){fade(document.getElementById('germany_thumb'), 0, .5, 500)}, 1250);
}

function displayCountry(country, index) {
	hideAllCountries();
	
	var img = document.getElementById('country_image');
	setOpacity(img, 0);
	img.style.backgroundImage = 'url(images/IMG_' + index + '.jpg)';
	fade(img, 0, 1, 1000);
	
	var txt = document.getElementById('companies');
	setOpacity(txt, 0);
	document.getElementById(country).style.display = 'block';
	//setOpacity(txt, 1);
	fade(txt, 0, 1, 1000);
	selectedThumb = document.getElementById(country + "_thumb");
	fadeThumbs();
}

function hideAllCountries() {
	var i = 0;
	for(i = 0; i < countryList.length; i++) {
		document.getElementById(countryList[i]).style.display = "none";
	}
}

function fadeThumbs() {
	var i = 0;
	var thumb;
	for(i = 0; i < countryList.length; i++) {
		thumb = document.getElementById(countryList[i] + "_thumb");
		setOpacity(thumb, .5);
	}
}

