///////////////////////////////////////////////////////////////////////
//     This swipe library was designed by Erik Arvidsson for WebFX   //
//                                                                   //
//     For more info and examples see: http://webfx.eae.net          //
//     or contact Erik at http://webfx.eae.net/contact.html#erik     //
//                                                                   //
//     Feel free to use this code as long as this disclaimer is      //
//     intact.                                                       //
//                                                                   //
//     Last updated: 2000-11-22                                      //
///////////////////////////////////////////////////////////////////////

window.status = "Loading swipe package...";

//////////////////////////////////////////////////////////////////////////////////////////
// The following lines makes the animation of the menus.
//////////////////////////////////////////////////////////////////////////////////////////

var swipeSteps = 4;
var swipemsec = 25;

var swipeArray = new Array();	// Needed to keep track of wich elements are animating

//////////////////////////////////////////////////////////////////////////////////////////
// the dir parameter is the direction read from the NumPad on your keyboard

function swipe(el, dir, steps, msec) {

	if (steps == null) steps = swipeSteps;
	if (msec == null) msec = swipemsec;

	if (el.swipeIndex == null)
		el.swipeIndex = swipeArray.length;
	if (el.swipeTimer != null)
		window.clearTimeout(el.swipeTimer);
		
	swipeArray[el.swipeIndex] = el;

	el.style.clip = getClip(-99999, -999999, 99999, 99999);

	if (el.swipeCounter == null) {		// No animation yet!
		el.orgLeft  = el.offsetLeft;
		el.orgTop  = el.offsetTop;
		el.orgWidth = el.offsetWidth;
		el.orgHeight  = el.offsetHeight;
	}
	else if (el.swipeCounter == 0) {	// The Animation has stopped! It's now safe to update the position.
		el.orgLeft  = el.offsetLeft;
		el.orgTop  = el.offsetTop;
		el.orgWidth = el.offsetWidth;
		el.orgHeight  = el.offsetHeight;
	}
	
	el.style.left = el.orgLeft;
	el.style.top  = el.orgTop;
	
	el.swipeCounter = steps;
	el.style.clip = getClip(0,0,0,0);
			
	window.setTimeout("repeat(" + dir + "," + el.swipeIndex + "," + steps + "," + msec + ")", msec);
}


function repeat(dir, index, steps, msec) {
	el = swipeArray[index];
	var left   = el.orgLeft;
	var top    = el.orgTop;
	var width  = el.orgWidth;
	var height = el.orgHeight;
	
	if (el.swipeCounter == 0) {
		el.style.clip = getClip(-99999, -99999, 99999, 99999);
		return;
	}
	else {
		el.swipeCounter--;
		el.style.visibility = "visible";
		switch (dir) {
			case 2:		//down (see the numpad)
				// getClip(left, top, width, height);
				el.style.clip = getClip(0, height * el.swipeCounter / steps, width, height);
				el.style.top  = top - height * el.swipeCounter / steps + "px";
				break;
			case 8:
				el.style.clip = getClip(0, 0, width, height * (steps - el.swipeCounter) / steps);
				el.style.top  = top + height * el.swipeCounter / steps + "px";
				break;
			case 6:
				el.style.clip = getClip(width * el.swipeCounter / steps, 0, width, height);
				el.style.left  = left - width * el.swipeCounter / steps + "px";
				break;
			case 4:
				el.style.clip = getClip(0, 0, width * (steps - el.swipeCounter) / steps, height);
				el.style.left  = left + width * el.swipeCounter / steps + "px";
				break;
			case 3:
				el.style.clip = getClip(width * el.swipeCounter / steps, height * el.swipeCounter / steps, width, height);
				el.style.left  = left - width * el.swipeCounter / steps + "px";
				el.style.top  = top - height * el.swipeCounter / steps + "px";
				break;
			case 1:
				el.style.clip = getClip(0, height * el.swipeCounter / steps, width * (steps - el.swipeCounter) / steps, height);
				el.style.left  = left + width * el.swipeCounter / steps + "px";
				el.style.top  = top - height * el.swipeCounter / steps + "px";
				break;
			case 7:
				el.style.clip = getClip(0, 0, width * (steps - el.swipeCounter) / steps, height * (steps - el.swipeCounter) / steps);
				el.style.left  = left + width * el.swipeCounter / steps + "px";
				el.style.top  = top + height * el.swipeCounter / steps + "px";
				break;
			case 9:
				el.style.clip = getClip(width * el.swipeCounter / steps, 0, width, height * (steps - el.swipeCounter) / steps);
				el.style.left  = left - width * el.swipeCounter / steps + "px";
				el.style.top  = top + height * el.swipeCounter / steps + "px";
			}
		
		el.swipeTimer = window.setTimeout("repeat(" + dir + "," + index + "," + steps + "," + msec + ")", msec);
	}
}

function hideSwipe(el) {
	window.clearTimeout(el.swipeTimer);
	el.style.visibility = "hidden";
	el.style.clip = getClip(-99999, -99999, 99999, 99999);
	el.swipeCounter = 0;
}

function getClip(left, top, width, height) {
	if (document.all)	// ugly browser test
		return "rect(" + top + "," + width + "," + height + "," + left + ")";
	else if (document.getElementById)
		return "rect(" + top + "px," + left + "px," + height + "px," + width + "px)";
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

window.status = "";
