
function MM_preloadImages() { 
	var d=document; 
	if(d.images){ 
		if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 
		for(i=0; i<a.length; i++){
			if (a[i].indexOf("#")!=0){
				d.MM_p[j]=new Image; 
				d.MM_p[j++].src=a[i];
			}
		}
	}
}

function gFlipper(thisID,flipperObjID1,flipperObjID2,flipperPause,fadeBy,arFlippers){
	this.id = thisID;
	this.flipperObjID1 = flipperObjID1;
	this.flipperObjID2 = flipperObjID2;
	this.flipperPause = flipperPause;
	this.fadeBy = fadeBy;
	this.arFlippers = arFlippers;
	this.nextFlipper = '';
}

function startFlipperRotation (objID) {
	var obj = eval(objID);
	var currentPic = obj.arFlippers.shift();
	obj.arFlippers.push(currentPic);
	nextFlipper = getNextFlipperDiv(obj);
	removeChildrenRecursively(nextFlipper);
	var objImage = new Image();
	nextFlipper.appendChild(objImage);
	objImage.onload = function() { fadeFlipperIn(obj.id,nextFlipper.id,0,obj.fadeBy,obj.flipperPause); };
	objImage.src = currentPic;
}

function getNextFlipperDiv (obj) {
	var f1 = document.getElementById(obj.flipperObjID1);
	var f2 = document.getElementById(obj.flipperObjID2);
	if (f1.style.zIndex > f2.style.zIndex){
		if(f2.filters) f2.style.filter='alpha(opacity=0)';
		else f2.style.opacity=0;
		f1.style.zIndex = 100;
		f2.style.zIndex = 101;
		return f2;
	}else{
		if(f1.filters) f1.style.filter='alpha(opacity=0)';
		else f1.style.opacity=0;
		f1.style.zIndex = 101;
		f2.style.zIndex = 100;
		return f1;
	}
}

function fadeFlipperIn (flipperObjID,objID,setTo,stepBy,pauseFor) {
	var objDiv = document.getElementById(objID);
	var currentValue = setTo;
	var nextValue = setTo + stepBy;
	if (nextValue > 100) nextValue = 100;
	if (objDiv.style.display == 'none') objDiv.style.display = '';
	if(objDiv.filters) objDiv.style.filter='alpha(opacity='+currentValue+')';
	else objDiv.style.opacity=currentValue/100;
	
	if (currentValue < 100){
		setTimeout('fadeFlipperIn("'+flipperObjID+'","'+objID+'",'+nextValue+','+stepBy+','+pauseFor+')');
	}else{
		setTimeout('startFlipperRotation("'+flipperObjID+'")',pauseFor);
	}
}

function removeChildrenRecursively (node) {
	if (!node) return;
	while (node.hasChildNodes()) {
		removeChildrenRecursively(node.firstChild);
		node.removeChild(node.firstChild);
	}
}
