function updateBtn() {
	document.cartForm.action = "cart.php";
	document.cartForm.submit();
	return true;
}

var x = 0; //image fading out
var y = 1; //image fading in
var i = -1; //index of clicked image
var play = true;
var halt = 0;
var timer = 0;
var pause = 0;
var outFF = 0.95;
var outIE = 95;
var inFF = 0.05;
var inIE = 5;
var prevImage;
var images = ["MarshmallowLarge","KrispieHarvest","CaramelBox","PeppermintBark","CaramelPretzels","TrufflePopCoconut","AlmoundPoundCake","Pecans","PeanutClusters","TrufflePopHarvest"];

//start image fade in 2 seconds
function start() {
	timer = setInterval("imageFade()", 50);
}

function imageFade() {
	document.getElementById(images[x]).style.opacity = outFF;
	document.getElementById(images[x]).style.filter = "alpha(opacity = "+outIE+")";
	document.getElementById(images[y]).style.opacity = inFF;
	document.getElementById(images[y]).style.filter = "alpha(opacity = "+inIE+")";
	
	//check where fade is
	if (outFF <= 0) { //at the end, reset
		clearInterval(timer); //stop looping
		//reset full opacity values
		document.getElementById(images[x]).style.opacity = 0;
		document.getElementById(images[x]).style.filter = "alpha(opacity = 0)";
		document.getElementById(images[y]).style.opacity = 1;
		document.getElementById(images[y]).style.filter = "alpha(opacity = 100)";
		outFF = 0.95;
		outIE = 95;
		inFF = 0.05;
		inIE = 5;
		updateIndex();
		halt = setTimeout("start()", 2000); //start again in 2 seconds	
	} else { //continue
		outFF -= 0.05;
		outIE -= 5;
		inFF += 0.05;
		inIE += 5;
	}
}

function updateIndex() {
	//check if x is last or second to last
	//if last, x = 0 -- if second to last y = 0
	if (y == images.length-1) { //x is last
		x ++;
		y = 0;
	} else if (x == images.length-1) { //y is last
		x = 0;
		y ++;
	} else {
		x ++;
		y ++;
	}
}

function imgPlay() {
	prevImage = null;
	if (i == -1) {
		//starting from clicking pause
		
	} else {
		//starting from clicking image
		x = i;
		if (x == images.length-1) {
			y = 0;
		} else {
			y = i+1;
		}
		//reset initial values
		outFF = 0.95;
		outIE = 95;
		inFF = 0.05;
		inIE = 5;
	}
	//switch button
	document.getElementById("playPause").innerHTML="<img src='images/pause.gif' alt='pause' onclick='imgPause()'>";
	start();
}

function imgPause() {
	clearInterval(timer);
	clearTimeout(halt);
	document.getElementById("playPause").innerHTML="<img src='images/play.gif' alt='play' onclick='imgPlay()'>";
	i = -1;
	//switch image to play
}

//when smaller image is clicked
function displayImage(imgIndex) {
	clearInterval(timer); //stop looping
	clearTimeout(halt);
	document.getElementById("playPause").innerHTML="<img src='images/play.gif' alt='play' onclick='imgPlay()'>";
	i = imgIndex;
	if (prevImage == null) {
		//starting from play
		prevImage = images[x];
		document.getElementById(images[y]).style.opacity = 0;
		document.getElementById(images[y]).style.filter = "alpha(opacity = 0)";
	} 
	//starting from image click
	document.getElementById(prevImage).style.opacity = 0;
	document.getElementById(prevImage).style.filter = "alpha(opacity = 0)";
	//display image
	document.getElementById(images[i]).style.opacity = 1;
	document.getElementById(images[i]).style.filter = "alpha(opacity = 100)";
	prevImage = images[i];
}

function mail(text, name, domain) {
	if (domain == null) {
		domain = "sweetsallways.com";
	}
	if (text == null) {
		text = name+"@"+domain;
	}
	address="<a href='mailto:"+name+"@"+domain+"' class='defaultLink'>"+text+"</a>";
	document.write(address);
}
