//PAGE PARAMETERS
var IMAGE_WIDTH = 502;		//Width of images (plus margin)


// Globals (DO NOT EDIT)
var xIndex = 0;
var NUMBER_OF_IMAGES = 0;

function slideNext() {
	var contentDiv = document.getElementById('boxwindowcontent');
	if (xIndex != 0 && xIndex / (IMAGE_WIDTH * -1) >= NUMBER_OF_IMAGES) {
		contentDiv.style.left = "0px";
		xIndex = 0;
	}
	xIndex = xIndex - IMAGE_WIDTH;
	moveElement("boxwindowcontent",xIndex,0,10);
}

function initBoxslider() {
	if (!document.getElementById("boxwindowframe")) return false;
	var imagesArray = new Array();

//  ********************************************************************************************
//  **  Add images and links to the scrolling ads thing here.  There must be TWO OR MORE ads
//  **  for this to work at all.  They will appear in the order in which they are defined here.
//  ********************************************************************************************

	imagesArray.push(new Array("/art/index-box-catalog.png", "https://www.sherry-lehmann.com/secure/catalog_request.asp"));
	imagesArray.push(new Array("/art/index-box-faiveley.jpg", "wines.asp?category=78"));
	imagesArray.push(new Array("/art/index-box-veuve-clicquot.jpg", "promo.asp?p=1358+1356+0784+1368"));
	imagesArray.push(new Array("/art/index-box-lucas-carton.jpg", "wines.asp?productid=3199"));

//  ********************************************************************************************
//                  DO  NOT  EDIT  BEYOND  THIS POINT
//  ********************************************************************************************

	if (imagesArray.length > 0) {
		imagesArray.push(imagesArray[0]);
		imagesArray.push(imagesArray[1]);
	}
	var frameDiv = document.getElementById('boxwindowframe');
	var contentDiv = document.createElement("div");
	contentDiv.setAttribute('id', 'boxwindowcontent');
	contentDiv.style.left = "570px";
	for (var n=0; n<imagesArray.length; n++) {
		var link = document.createElement("a");
		link.setAttribute("href",imagesArray[n][1]);
		var elem = document.createElement("img");
		elem.setAttribute("src",imagesArray[n][0]);
		//elem.setAttribute("border",0);
		link.appendChild(elem);
		contentDiv.appendChild(link);
	}
	frameDiv.appendChild(contentDiv);

	NUMBER_OF_IMAGES = imagesArray.length;
	contentDiv.style.width = "" + (NUMBER_OF_IMAGES * IMAGE_WIDTH) + "px";
	NUMBER_OF_IMAGES = NUMBER_OF_IMAGES - 2;

	var trigger = document.getElementById('slidetrigger');
	trigger.onclick = slideNext;

	setTimeout("slideFirstImage()", 6000);
}

hideBigBag = function() {
	//document.getElementById('bag').style.display = "none";
	//Effect.Fade("bag", {duration:1, afterFinish:slideFirstImage});
	Effect.Fade("bag", {duration:0.5});
}

showLittleBag = function() {
	//Effect.Appear("bag-mini", {duration:0.4, afterFinish:slideFirstImage});
	Effect.Appear("bag-mini", {duration:0.4,afterFinish:makeSmallBagClickable});
}

makeSmallBagClickable = function() {
	if (document.all&&document.getElementById) {
		if (!document.getElementById("bag-mini")) return false;
		var miniBag = document.getElementById("bag-mini");
		miniBag.onclick = function() {
			//window.location.href = "http://sherry.nettheory.com/wine-categories.asp";
			var currentLocation = window.location.href;
			var newLocation = currentLocation + "wine-categories.asp";
			window.location.href = newLocation;
			//var temp = new Array();
			//temp = currentLocation.split('/');
			//for (i=0; i<temp.length; i++) {
			//	alert(temp[i]);
			//}
		}
	}
}

slideFirstImage = function() {
	moveElement("boxwindowcontent",0,0,20);
	setTimeout("hideBigBag()", 200);
	showLittleBag();
	var trigger = document.getElementById('slidetrigger');
	var nextLine = document.getElementById("next");
	trigger.style.display = "block";
	nextLine.style.display = "block";
	//setTimeout("hideBigBag()", 2000);
}


addLoadEvent(initBoxslider);

function moveElement(elementID,final_x,final_y,interval) {
	if (!document.getElementById) return false;
	if (!document.getElementById(elementID)) return false;

	var elem = document.getElementById(elementID);
	// check to see if the function is already attached to the element
	// if it is, stop it before doing any of this
	if (elem.movement) {
		clearTimeout(elem.movement);
	}

//alert("moveElement("+elementID+","+final_x+","+final_y+","+interval+") "+elem.style.left+","+elem.style.top);

	// make sure the position is set, and if it's not, set it
	if (!elem.style.left) {
		elem.style.left = "0px";
	}
	if (!elem.style.top) {
		elem.style.top = "0px";
	}

	var xpos = parseFloat(elem.style.left);
	var ypos = parseFloat(elem.style.top);

	if ((xpos == final_x) && (ypos == final_y)) {
		return true;
	}
	if (xpos < final_x) {
		// move 1/10 of whatever distance is remaining
		var dist = Math.ceil((final_x - xpos)/10); 			// Math.ceil rounds up
		xpos = xpos + dist;
	}
	if (xpos > final_x) {
		var dist = Math.ceil((xpos - final_x)/10)
		xpos = xpos - dist;
	}
	if (ypos < final_y) {
		var dist = Math.ceil((final_y - ypos)/10)
		ypos = ypos + dist;
	}
	if (ypos > final_y) {
		var dist = Math.ceil((ypos - final_y)/10)
		ypos = ypos - dist;
	}
	elem.style.left = xpos + "px";
	elem.style.top = ypos + "px";

	var repeat = "moveElement('" + elementID + "'," + final_x + "," + final_y + "," + interval + ")";

	// attach the function to the element
	elem.movement = setTimeout(repeat,interval);
}