
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  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 MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function loadImage(strFile, strText)
{
	document.getElementById('productLargeImage').src = strFile;
	document.getElementById('ProdName').innerHTML = strText;
}

var currentPhoto = 0;
function selectPhoto ()
{
	currentPhoto += 1;
	if (currentPhoto >= myPhotos.length)
	{
		currentPhoto = 0;
	}
	dualTransitionEffect('smallGalleryImage', 'smallGalleryImage', 'opacity', 0, 1, 20, 0.1, 500);
	setTimeout("document.getElementById('smallGalleryImage').src = myPhotos[currentPhoto].src", 500);
}

/*
 * @description Fade an element based on opacity.
 * @param strId id of the element to be manipulated.
 * @param strAction the action to take place. i.e. if fading an element, specify 'in' or 'out'.
 * @param intOrigin starting point.
 * @param intDestination stop point.
 * @param intSpeed the timeout interval.
 * @param intIncrement the offset size of each increment.
 * @returns null.
 */
function transitionEffect(strId, strEffect, intOrigin, intDestination, intSpeed, intIncrement)
{
	if (document.getElementById(strId))
	{
		if (intOrigin > intDestination)
		{
			// Decrement value.
			intOrigin -= intIncrement;
			if (intOrigin < intDestination)
			{
				intOrigin = intDestination;
				handleIDStyle(strId, 'visibility', 'hidden');
			}
		}
		else
		{
			// Increment value.
			intOrigin += intIncrement;
			handleIDStyle(strId, 'visibility', 'visible');
			if (intOrigin > intDestination)
			{
				intOrigin = intDestination;
			}
		}
		// Set new effect style.
		handleIDStyle(strId, strEffect, intOrigin);
		// Stop when destination is reached.
		if (intOrigin != intDestination)
		{
			setTimeout('transitionEffect(\'' + strId + '\', \'' + strEffect + '\', ' + intOrigin + ', ' + intDestination + ', ' + intSpeed + ', ' + intIncrement + ')', intSpeed);
		}
	}
}

function dualTransitionEffect(strId1, strId2, strEffect, intOrigin, intDestination, intSpeed, intIncrement, intDelay)
{
	transitionEffect(strId1, strEffect, intDestination, intOrigin, intSpeed, intIncrement);
	setTimeout('transitionEffect(\'' + strId2 + '\', \'' + strEffect + '\', ' + intOrigin + ', ' + intDestination + ', ' + intSpeed + ', ' + intIncrement + ')', intDelay);
}

/*
 * @description Determine wether to set or get the value of a css style for an element.
 * @param strId id of the element to be manipulated.
 * @param strAttribute a css attribute such as display or visibility.
 * @param strValue the value of the element to be set.
 * @returns null or the element value.
 */
function handleIDStyle(strId, strAttribute, strValue)
{
	var el = document.getElementById(strId);
	switch (strAttribute)
	{
		case 'display':
			if (strValue !== undefined)
			{
				el.style.display = strValue;
			}
			else 
			{
				return el.style.display;
			}
			break;
		case 'visibility':
			if (strValue !== undefined)
			{
				el.style.visibility = strValue;
			}
			else
			{
				return el.style.visibility;
			}
			break;
		case 'opacity':
			var intValue = strValue;
			if (strValue !== undefined)
			{
				if (intValue >= 0 && intValue <= 1)
				{
					el.style.opacity = intValue;
					//el.style.MozOpacity = intValue;
					//el.style.filter = 'alpha(opacity=' + (intValue * 100) + ')';
					//el.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(Opacity=' + intValue + ')';
				}
			}
			else 
			{
				return el.style.opacity;
			}
			break;
		default:
			alert('handleIDStyle: ' + strAttribute + ' not found.');
			break;
	}
	return false;
}
