var photoCache= new Array();
var zoomedPhotoCache= new Array();
var photoShown= new Array();
var intCurLeft = 0;
var intCurRight = 1;
var curZoomState = 0;
var curButtonsDivTop = 0;
var curButtonsDivLeft = 0;
var curSpreadDivTop = 0;
var curSpreadDivLeft = 0;
var buttonsDiv = null;
var zoomDiv = null;
var preLoadPhotos = 4;
var preLoadZoomedPhotos = 2;
var curDiv = 0;
var isCoverPage = 1;

var imgLoading = "images/loading.gif";
var imgBlank = "images/covershadow.jpg";
var imgError = "images/error_loading.gif";
var imgCoverSheet = "images/coversheet.gif";
var imgDummy = "images/0x0.jpg";


// Disable landing page
var timer = null;
var bDHTML = (document.getElementById || document.all || document.layers);
var currentAlbumType = null;
var webViewType;
GFALBUM = 1;
LALBUM = 2;
ORDERWEBVIEW = 1;

function getTransition()
{
	return (chk.getOS() == "Macintosh") ? 50 : 500;
}

function setCurrentAlbumType()
{
	currentAlbumType = (document.getElementById("photo")) ? GFALBUM : LALBUM;
	webViewType = (document.getElementById("maskPage") && getParameter('leftMaskURL') != '') ? ORDERWEBVIEW : 0;

}

function isNotRealPicture(objectClicked)
{
	return (objectClicked.indexOf(imgBlank) != -1 || objectClicked.indexOf(imgLoading) != -1 || objectClicked.indexOf(imgCoverSheet) != -1) ? 1 : 0; 

}
function showDiv(type)
{
   //Zoom
   if(WhichBrowser != "IE")
   { 
       if(screen.width == 1280)
       {
        document.getElementById("zoomPhoto").style.left = "240";
       }
       else if(screen.width == 1024)
       {
        document.getElementById("zoomPhoto").style.left = "100";
       }
       else if(screen.width == 800)
       {
          document.getElementById("zoomPhoto").style.left = "0";
       }
   }
	     
  if (type == curDiv) return;
  curDiv = type;
  if (type == 3) {
		if (document.getElementById("marketingPage")) document.getElementById("marketingPage").style.visibility="visible";
		if (document.getElementById("logo")) document.getElementById("logo").style.visibility="hidden"; // visible
		if (document.getElementById("logoline")) document.getElementById("logoline").style.visibility="hidden"; // visible
		if (document.getElementById("buttons")) document.getElementById("buttons").style.visibility="hidden";
		if (document.getElementById("footerPage")) document.getElementById("footerPage").style.visibility="hidden";
		if (document.getElementById("owner")) document.getElementById("owner").style.visibility="hidden";
		if (document.getElementById("bannerPage")) document.getElementById("bannerPage").style.visibility="hidden";
		if (document.getElementById("spreadPage")) document.getElementById("spreadPage").style.visibility="hidden";
		if (document.getElementById("shadowPage")) document.getElementById("shadowPage").style.visibility="hidden";
		if (document.getElementById("maskPage")) document.getElementById("maskPage").style.visibility="hidden";		
		if (document.getElementById("marketingCoverPhoto")) document.getElementById("marketingCoverPhoto").style.visibility="hidden";
		if (document.getElementById("marketingCoverPage")) document.getElementById("marketingCoverPage").style.visibility="hidden";
		if (document.getElementById("marketingCoverShadowPage")) document.getElementById("marketingCoverShadowPage").style.visibility="hidden";
  } else {
    //Last Page
	if (type == 4) {
		if (document.getElementById("spreadPage")) document.getElementById("spreadPage").style.visibility="hidden";
		if (document.getElementById("shadowPage")) document.getElementById("shadowPage").style.visibility="hidden";
		if (document.getElementById("maskPage")) document.getElementById("maskPage").style.visibility="hidden";		
		//if (document.getElementById("backgroundInnerPage")) document.getElementById("backgroundInnerPage").innerHTML = "<IMG alt=\"\" src=\"" + backgroundFinish + "\" useMap=\"#mapfinish\" border=\"0\" name=\"background\">";
		if (document.getElementById("logo") && (getParameter('showHeader') != 0 || !getParameter('showHeader'))) document.getElementById("logo").style.visibility = "visible";
		if (document.getElementById("pageNumbers")) document.getElementById("pageNumbers").style.visibility="hidden";
		//vhp
		if (document.getElementById("clickToZoomDiv")) document.getElementById("clickToZoomDiv").style.visibility="hidden";
		if (document.getElementById("ButtonView")) document.getElementById("ButtonView").style.visibility="hidden";
	    if (document.getElementById("IframeCoupon")) document.getElementById("IframeCoupon").style.visibility="hidden";
	    if (document.getElementById("BuyBook")) document.getElementById("BuyBook").style.visibility="hidden";
	
		
		if (document.getElementById("marketingCoverPhoto"))	document.getElementById("marketingCoverPhoto").style.visibility="visible";
		if (document.getElementById("marketingCoverPage")) document.getElementById("marketingCoverPage").style.visibility="visible";
		//if (document.getElementById("marketingCoverShadowPage")) document.getElementById("marketingCoverShadowPage").style.visibility="visible";
		//if (document.getElementById("footerPage")) document.getElementById("footerPage").style.visibility="hidden";
	    
	    if (document.getElementById("MarketingIframeCreateBook")) document.getElementById("MarketingIframeCreateBook").style.visibility="visible";
	    if (document.getElementById("IframeCreateBook")) document.getElementById("IframeCreateBook").style.visibility="hidden";
	    
	    //Title and owner
	    if(screen.width < 1280)
	    {
	      if (document.getElementById("MainOwner"))document.getElementById("MainOwner").style.top = "-65px";
	      if (document.getElementById("footerPage"))document.getElementById("footerPage").style.top = "400px";
	      if (document.getElementById("ButtonView"))document.getElementById("ButtonView").style.top = "325px";
	    }
	    else
	    {
	      if (document.getElementById("MainOwner"))document.getElementById("MainOwner").style.top = "-70px";
	      if (document.getElementById("footerPage"))document.getElementById("footerPage").style.top = "370px";
	      if (document.getElementById("ButtonView"))document.getElementById("ButtonView").style.top = "325px";
	    }
	    
	    if (document.getElementById("ViewPageOwner")) document.getElementById("ViewPageOwner").style.visibility= "hidden";
	   	if (document.getElementById("MainOwner")) document.getElementById("MainOwner").style.visibility="visible";
	   
	    if(WhichBrowser != "IE")
	    {
	       if(screen.width < 1280)
	       {
	       // if (document.getElementById("MainOwner"))document.getElementById("MainOwner").style.top = "10px";
	          if (document.getElementById("zoomPhoto"))document.getElementById("zoomPhoto").style.left = "115px";
	     
	       }
	       else
	       {
	        if (document.getElementById("MainOwner"))document.getElementById("MainOwner").style.top = "-55px";
	       }
	    }
    
	} else {
		if (document.getElementById("marketingPage")) document.getElementById("marketingPage").style.visibility="hidden";
		if (document.getElementById("logo") && getParameter('showHeader') != 0) document.getElementById("logo").style.visibility= (currentAlbumType == GFALBUM) ? "hidden" : "visible";
		if (webViewType == ORDERWEBVIEW) {
			document.getElementById("maskPage").style.visibility=	"visible";
		    if (document.getElementById('maskLeft')) document.getElementById('maskLeft').src = getParameter('leftMaskURL');
		    if (document.getElementById('maskRight')) document.getElementById('maskRight').src = getParameter('rightMaskURL');
		    if (document.getElementById("shadowPage")) document.getElementById("shadowPage").style.visibility= "hidden";
		} else {
		    if (document.getElementById("shadowPage")) document.getElementById("shadowPage").style.visibility= "visible";
			if (document.getElementById("footerPage")) document.getElementById("footerPage").style.visibility="visible";
		}

		if (document.getElementById("logoline")) document.getElementById("logoline").style.visibility="hidden";
		if (document.getElementById("buttons")) document.getElementById("buttons").style.visibility="visible";
		if (document.getElementById("bannerPage")) document.getElementById("bannerPage").style.visibility="visible";
		if (document.getElementById("spreadPage")) document.getElementById("spreadPage").style.visibility="visible";
		if (document.getElementById("pageNumbers")) document.getElementById("pageNumbers").style.visibility="visible";
		//if (document.getElementById("backgroundInnerPage"))	document.getElementById("backgroundInnerPage").innerHTML = "<IMG alt=\"\" src=\"" + backgroundAlbum + "\" useMap=\"#mapbkg\" border=\"0\" name=\"background\">";
		if (document.getElementById("marketingCoverPhoto")) document.getElementById("marketingCoverPhoto").style.visibility="hidden";
		if (document.getElementById("marketingCoverPage")) document.getElementById("marketingCoverPage").style.visibility="hidden";
		if (document.getElementById("marketingCoverShadowPage")) document.getElementById("marketingCoverShadowPage").style.visibility="hidden";
		if (document.getElementById("shadowAlbumInnerPage")) document.getElementById("shadowAlbumInnerPage").innerHTML = "<IMG alt=\"\" src=\"" + shadowAlbum + "\" border=\"0\" width=\"" + shadowWidth + "px\" height=\"" + shadowHeight + "px\" title=\"shadowAlbum\" name=\"shadowAlbum\">";
        
        //Cover Page
        if (document.getElementById("mainCoverPage")) document.getElementById("mainCoverPage").style.visibility="hidden";
	    if (document.getElementById("coverPage")) document.getElementById("coverPage").style.visibility="hidden";

        //vhp
		if (document.getElementById("clickToZoomDiv")) document.getElementById("clickToZoomDiv").style.visibility="visible";
		if (document.getElementById("ButtonView")) document.getElementById("ButtonView").style.visibility="visible";
	    if (document.getElementById("IframeCoupon")) document.getElementById("IframeCoupon").style.visibility="visible";
	    if (document.getElementById("BuyBook")) document.getElementById("BuyBook").style.visibility="visible";
	    
	    if (document.getElementById("ViewPageOwner")) document.getElementById("ViewPageOwner").style.visibility= "visible";
	   	if (document.getElementById("MainOwner")) document.getElementById("MainOwner").style.visibility="hidden";
       
        if (document.getElementById("IframeCreateBook")) document.getElementById("IframeCreateBook").style.visibility= "visible";
	    if (document.getElementById("MarketingIframeCreateBook")) document.getElementById("MarketingIframeCreateBook").style.visibility= "hidden";
	  
	    if(WhichBrowser != "IE")
	    { 
	        if(screen.width < 1280)
	        {
                 if (document.getElementById("ButtonView"))document.getElementById("ButtonView").style.top = "370px";
                 if (document.getElementById("ButtonView"))document.getElementById("ButtonView").style.left = "2px";
                 if (document.getElementById("IframeCreateBook"))document.getElementById("IframeCreateBook").style.top = "380px";
                 if (document.getElementById("footerPage"))document.getElementById("footerPage").style.top = "360px";
               
            }
            else
            {
                if (document.getElementById("ButtonView"))document.getElementById("ButtonView").style.top = "380px";
                if (document.getElementById("ButtonView"))document.getElementById("ButtonView").style.left = "2px";
                if (document.getElementById("IframeCreateBook"))document.getElementById("IframeCreateBook").style.top = "400px";
                if (document.getElementById("footerPage"))document.getElementById("footerPage").style.top = "400px";
            }
        }
        else
        {
            if(screen.width < 1280)
	        { 
                if (document.getElementById("ButtonView"))document.getElementById("ButtonView").style.top = "340px";
                if (document.getElementById("ButtonView"))document.getElementById("ButtonView").style.left = "2px";
                if (document.getElementById("IframeCreateBook"))document.getElementById("IframeCreateBook").style.top = "360px";
                if (document.getElementById("footerPage"))document.getElementById("footerPage").style.top = "350px";
            }
            else
            {
                
                if (document.getElementById("ButtonView"))document.getElementById("ButtonView").style.top = "340px";
                if (document.getElementById("ButtonView"))document.getElementById("ButtonView").style.left = "2px";
                if (document.getElementById("IframeCreateBook"))document.getElementById("IframeCreateBook").style.top = "360px";
            } 
        }
        
	   }
    }
}

function hideZoom()
{
	zoomDiv.style.visibility = "hidden";
}

function zoomPicture(objectClicked)
{
	if (isNotRealPicture(objectClicked.src) == 1) return;

	zoomDiv = document.getElementById("zoomPhoto");
	var zoomInnerDiv = document.getElementById("zoomInnerDiv");

	if (zoomDiv) {
		if (curZoomState == 0) {
			curZoomState = 1;
			zoomDiv.style.visibility = "visible";
			zoomInnerDiv.innerHTML= "<IMG id=\"zoomedPhoto\" name=\"zoomedPhoto\" onclick=\"zoomPicture(this); return false;\" border=\"0\" width=\"" + zoomWidthJS + "\" height=\"" + zoomHeightJS + "\" src=\"" + imgDummy + "\">";
			ApplyTransition("zoomedPhoto", zoomedPhotoList[objectClicked.photoIndex], getTransition())
		} else {
			curZoomState = 0;
			setTimeout('hideZoom()', getTransition());
			fadeImage("zoomedPhoto", getTransition())
		}
	}
}

function toggleZoom(object)
{
var spreadDiv = null;
	
	spreadDiv = document.getElementById("spreadPage");
	curSpreadDivTop = spreadDiv.offsetTop;
	curSpreadDivLeft = spreadDiv.offsetLeft;

    if (buttonsDiv == null) {
		buttonsDiv = document.getElementById("buttons");
		curButtonsDivTop = buttonsDiv.style.top;
		curButtonsDivLeft = buttonsDiv.style.left;
	}

	if (curZoomState == 0) {
		curZoomState = 1;
		JSFX.zoomIn(object, 20, 200, spreadDiv, JSFX.ALL);
		if (buttonsDiv) {
			buttonsDiv.style.top = curButtonsDivTop + 475;
			buttonsDiv.style.left = curButtonsDivLeft + 200;
		}
	} else {
		JSFX.zoomOut(object);
		curZoomState = 0;
		if (buttonsDiv) {
			buttonsDiv.style.top = curButtonsDivTop;
			buttonsDiv.style.left = curButtonsDivLeft;
		}
	}
}

function alterCursor(object, mode)
{
	if (isNotRealPicture(object.src) == 1) return;

	if (mode == 0) {
		object.style.cursor='default'
	} else {
	    if (chk.getBrowser() == "Internet Explorer" && chk.getOS() != "Macintosh") {
			if (curZoomState == 0) {
				object.style.cursor='images/zoomin.cur'
			} else {
				object.style.cursor='images/zoomout.cur'
			}
		} else {
			object.style.cursor='se-resize'
		}
	}
}

//function preLoad()
//{
//	var i;
//	photoCache.length = albumCount + 1;
//	for (i = 0; i < albumCount; i++){
//			getPhoto(i);
//	}
//}

function getCover()
{
  
	setCurrentAlbumType();
	getPhoto(0, preLoadPhotos);
	if (currentAlbumType != GFALBUM) getZoomedPhoto(0, preLoadZoomedPhotos);
	showPhoto(0);
}

function getFooter(url)
{
   document.getElementById("footerPage").ajaxHandle = "";
   var a = new AJAXRequest("GET", url, null, function( AJAX ) {
		if (AJAX.readyState == 4) {
			if (AJAX.status == 200) {
				var htmlText  = "<TABLE id=\"FooterTable\" align=\"center\" width=552 height=34 background=\"images/webview-footer.jpg\" cellSpacing=\"0\" cellPadding=\"0\" border=\"0\">";
				htmlText += "<TR><TD width=100% align=center >" + AJAX.responseText + "</TD></TR></TABLE>";
				document.getElementById("footerPage").innerHTML = htmlText;
			}
		}
    });
}

function getPhoto(ind, preLoad)
{
  if (ind<0 || ind >= albumCount || preLoad < 0)
	return;
	
  if( !photoCache[ind] || photoCache[ind].src == imgError)	{
	document.getElementById("spreadPage").ajaxHandle = "";
	var a = new AJAXRequest("GET", photoList[ind], null, function( AJAX ) {
		if (AJAX.readyState == 4) {
			if (AJAX.status == 200) {
				photoCache[ind]= new Image();
				photoCache[ind].src = photoList[ind];
			} else {
				photoCache[ind]= new Image();
				photoCache[ind].src = imgError;
			}
			showPhoto(ind);
		}
    });
  }  
  getPhoto(ind+1, preLoad-1);
}

function getZoomedPhoto(ind, preLoad)
{
  if (ind<0 || ind >= albumCount || preLoad < 0)
	return;

  if( !zoomedPhotoCache[ind])	{
	var a = new AJAXRequest("GET", zoomedPhotoList[ind], null, function( AJAX ) {
		if (AJAX.readyState == 4) {
			if (AJAX.status == 200) {
				zoomedPhotoCache[ind]= new Image();
				zoomedPhotoCache[ind].src = zoomedPhotoList[ind];
			}
		}
    });
	getZoomedPhoto(ind+1, preLoad-1);
  }  
}

function showPhoto(curPhoto)
{
 
	if (currentAlbumType == GFALBUM) {
		showSinglePhoto(curPhoto, "photo", "pageNumber");
	} else {
		if (curPhoto % 2 == 0) {
			showSinglePhoto(curPhoto, "photoLeft", "pageNumberLeft");
			showSinglePhoto(curPhoto+1, "photoRight", "pageNumberRight");
		} else {
			showSinglePhoto(curPhoto, "photoRight", "pageNumberRight");
		}
	}
	if (currentAlbumType != GFALBUM && chk.getBrowser() == "Internet Explorer"  && chk.getOS() != "Macintosh" ) {
		correctPNG();
	}
}

function showPageNumber(pageNumberName, curPhoto)
{    
    var nPageNumber = curPhoto;

    if (currentAlbumType == GFALBUM) nPageNumber++;
	document.getElementById(pageNumberName).innerHTML= "<FONT face=\"Arial\" size=3 color=\"gray\"><STRONG>" + ((nPageNumber == 0 || curPhoto >= albumCount) ? " " : nPageNumber) + "</strong></font>";
	showDiv(2);
}

function showSinglePhoto(curPhoto, imgName, pageNumberName)
{

	if (curPhoto != intCurLeft && (intCurRight != curPhoto || currentAlbumType == GFALBUM)) return;

	if (currentAlbumType == GFALBUM) coverPage.style.visibility= (curPhoto == 0) ? "visible" : "hidden";

    // Get photo img element from html 
    var olObject = document.getElementById(imgName);

	if (!photoCache[curPhoto] && curPhoto < albumCount) {
		showPageNumber(pageNumberName, curPhoto);
		olObject.src = imgLoading;
		return;
	}

	if (photoCache[curPhoto] && photoCache[curPhoto].src.slice(-1*imgError.length) == imgError) {
		showPageNumber(pageNumberName, curPhoto);
		olObject.src = photoCache[curPhoto].src;
		return;
	}

	if (photoShown[curPhoto] == 1 && olObject.src == photoList[curPhoto] && photoList[curPhoto] != imgDummy) return;

	// alert(curPhoto + " " + photoShown[curPhoto] + " " + olObject.src + " " + photoList[curPhoto]);
//	if (olObject.src != imgLoading && olObject.src == photoList[curPhoto]) return;
	photoShown[curPhoto] = 1;

    olObject.photoIndex = curPhoto;

	showPageNumber(pageNumberName, curPhoto);

    var photoToShow;
    if (curPhoto >= albumCount) {
		photoToShow = imgBlank;
	} else {
		if (photoCache[curPhoto]) {
			photoToShow = photoList[curPhoto];
		}  
		else {
			photoToShow = imgLoading;
		}
	}

	if (photoToShow != imgLoading) ApplyTransition(imgName, photoToShow, getTransition());
}

function ApplyTransition2(imgName, photoToShow, speed)
{
    var olObject = document.getElementById(imgName);
	swapfade(imgName, photoToShow, '1', 'Album page')
}

function ApplyTransition(imgName, photoToShow, speed)
{
    var olObject = document.getElementById(imgName);

	olObject.style.filter="blendTrans(duration=1.0)";
	
    if (chk.getBrowser() == "Internet Explorer" && chk.getOS() != "Macintosh" && olObject.filters.blendTrans) {
		olObject.filters.blendTrans.Apply();
		olObject.src = photoToShow;
		olObject.filters.blendTrans.Play();
		olObject.focus();
    } else
		blendImage(imgName, photoToShow, speed);
}

function playAlbum()
{
    curPhoto = -1;
	timer = setInterval("nextPhoto();", 3000);
}
function SetNextPhoto()
{
  if(isCoverPage == 1)
   {
     isCoverPage = 0;
     getPhoto(0, preLoadPhotos);
	 if (currentAlbumType != GFALBUM) getZoomedPhoto(0, preLoadZoomedPhotos);
	 showPhoto(0);
   }else{
      nextPhoto();
   } 
   
}

function ViewAgain()
{
  
     getPhoto(0, preLoadPhotos);
	 if (currentAlbumType != GFALBUM) getZoomedPhoto(0, preLoadZoomedPhotos);
	 showPhoto(0);
  
}

function CoverNextPhoto()
{
	photoShown[intCurLeft] = 0;
	photoShown[intCurRight] = 0;

	//intCurLeft += (currentAlbumType == GFALBUM) ? 1 : 2;
	//intCurRight = intCurLeft + 1;
	intCurLeft += (currentAlbumType == GFALBUM) ? 1 : 2;
	intCurRight = intCurLeft + 1;

	getPhoto(intCurLeft, preLoadPhotos);
	if (currentAlbumType != GFALBUM) getZoomedPhoto(intCurLeft, preLoadZoomedPhotos);

	if (intCurLeft >= albumCount) {
		intCurLeft = 0;
		intCurRight = 1;
		if (currentAlbumType == GFALBUM) {
			lGeneric('previewMarketing');
			showDiv(3);
			return;
		} else {
			lGeneric('LAST_PAGE');
			if (webViewType == ORDERWEBVIEW) {
				showPhoto(0);
			} else {
				showDiv(4);
			}
			return;
		}
	}

//	if (intCurLeft > albumCount) {
//		intCurLeft= 0;
//	}

	//showPhoto(intCurLeft);

	lPreview(originalInstanceGUID, instanceVersionGUID, 1);
	cookiePreview.lastPage = intCurLeft;
	cookiePreview.store();	
}
function nextPhoto()
{
   
	photoShown[intCurLeft] = 0;
	photoShown[intCurRight] = 0;

	intCurLeft += (currentAlbumType == GFALBUM) ? 1 : 2;
	intCurRight = intCurLeft + 1;
	getPhoto(intCurLeft, preLoadPhotos);
	if (currentAlbumType != GFALBUM) getZoomedPhoto(intCurLeft, preLoadZoomedPhotos);
    
   
	if (intCurLeft >= albumCount) {
		intCurLeft = 0;
		intCurRight = 1;
		if (currentAlbumType == GFALBUM) {
			lGeneric('previewMarketing');
			showDiv(3);
			return;
		} else {
			lGeneric('LAST_PAGE');
			if (webViewType == ORDERWEBVIEW) {
				showPhoto(0);
			} else {
				showDiv(4);
			}
			return;
		}
	}

//	if (intCurLeft > albumCount) {
//		intCurLeft= 0;
//	}

	showPhoto(intCurLeft);

	lPreview(originalInstanceGUID, instanceVersionGUID, 1);
	cookiePreview.lastPage = intCurLeft;
	cookiePreview.store();	
}

function prevPhoto()
{
	photoShown[intCurLeft] = 0;
	photoShown[intCurRight] = 0;

	intCurLeft -= (currentAlbumType == GFALBUM) ? 1 : 2;
	
	if (intCurLeft< 0) intCurLeft = albumCount-((currentAlbumType == GFALBUM) ? 1 : ((albumCount % 2 == 0) ? 2 : 1));
    
    //the first page, hit enter previous, it will go back to the cover page
    
        intCurRight = intCurLeft + 1;
	    getPhoto(intCurLeft, preLoadPhotos);

	    showPhoto(intCurLeft);

	    lPreview(originalInstanceGUID, instanceVersionGUID, -1);
	    cookiePreview.lastPage = intCurLeft;
	    cookiePreview.store();	
	
}

function flipPage(evt)
{
	evt = (evt) ? evt : ((window.event) ? window.event : "");
	var x = (evt.pageX) ? evt.pageX : ((evt.x) ? evt.x : 228);
	if (x > 227) {
		nextPhoto();
	} else {
		prevPhoto();
	}
}

function changeButtonAppearance(button, imgName)
{
	button.src= imgName;
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id);
    
    if (object == null)
		return;
	
	object = object.style;
    
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

function blendImage(imageid, imagefile, millisec)
{
    var speed = Math.round(millisec / 500);
    var timer = 0;

    //make image transparent
    changeOpac(0, imageid);
    
    //make new image
//    document.getElementById(imageid).src = imagefile;
   var speed = Math.round(millisec / 500);

   setTimeout("doFade('" + imageid +  "', '" + imagefile + "', " +  speed + ")",speed);

}

function doFade(imageid, imagefile, speed)
{
	document.getElementById(imageid).src = imagefile;
    //fade in image
    for(i = 0; i <= 100; i++) {
        setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
        timer++;
    }
}

function fadeImage(imageid, millisec)
{
    var speed = Math.round(millisec / 500);
    var timer = 0;

     //fade out image
    for(i = 100; i > 0; i--) {
        setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
        timer++;
    }
//	if (imageDiv) imageDiv.style.visibility = "hidden";
    
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

// ISF1.11 :: Image swap-fade 
// *****************************************************
// DOM scripting by brothercake -- http://www.brothercake.com/
//******************************************************
//global object
var isf = { 'clock' : null, 'fade' : true, 'count' : 1 }
var isf1 = { 'clock' : null, 'fade' : true, 'count' : 1 }

var swapIsf = new Array();
swapIsf[0] = isf;
swapIsf[1] = isf1;

//swapfade setup function
function swapfade()
{
    var olObject = document.getElementById(arguments[0]);
    // alert(olObject.src + "==" + arguments[1]);
    if (olObject.src == arguments[1]) return;

	var visf = null;
	var pisf = 0;
	//if the timer is not already going
	if(isf.clock == null) {
		visf = isf;
		pisf = 0;
	} else if(isf1.clock == null) {
		visf = isf1;
		pisf = 1;
	} 
	else {
		olObject.src = arguments[1];
		return;
	}

	//copy the image object 
	visf.obj = arguments[0];

	//copy the image src argument 
	visf.src = arguments[1];

	//store the supported form of opacity
	if(typeof olObject.style.opacity != 'undefined')
	{
		visf.type = 'w3c';
	}
	else if(typeof olObject.style.MozOpacity != 'undefined')
	{
		visf.type = 'moz';
	}
	else if(typeof olObject.style.KhtmlOpacity != 'undefined')
	{
		visf.type = 'khtml';
	}
	else if(typeof olObject.filters == 'object')
	{
		//weed out win/ie5.0 by testing the length of the filters collection (where filters is an object with no data)
		//then weed out mac/ie5 by testing first the existence of the alpha object (to prevent errors in win/ie5.0)
		//then the returned value type, which should be a number, but in mac/ie5 is an empty string
		olObject.style.filter="alpha(duration=1.0)";
		visf.type = (olObject.filters.length > 0 && typeof olObject.filters.alpha == 'object' && typeof olObject.filters.alpha.opacity == 'number') ? 'ie' : 'none';
	}
	else
	{
		visf.type = 'none';
	}
	
	//change the image alt text if defined
	if(typeof arguments[3] != 'undefined' && arguments[3] != '')
	{
		olObject.alt = arguments[3];
	}
	
	//if any kind of opacity is supported
	if(visf.type != 'none')
	{
		//copy and convert fade duration argument 
		//the duration specifies the whole transition
		//but the swapfade is two distinct transitions
		visf.length = parseInt(arguments[2], 10) * 500;
		
		//create fade resolution argument as 20 steps per transition
		//again, split for the two distrinct transitions
		visf.resolution = parseInt(arguments[2], 10) * 10;
		
		//start the timer
		visf.clock = setInterval('isf.swapfade('+pisf+')', visf.length/visf.resolution);
	}
		
	//otherwise if opacity is not supported
	else
	{
		//just do the image swap
		olObject.src = visf.src;
	}
};


//swapfade timer function
isf.swapfade = function(pisf)
{
	var visf = swapIsf[pisf];
    var olObject = document.getElementById(visf.obj);

	
	//increase or reduce the counter on an exponential scale
	visf.count = (visf.fade) ? visf.count * 0.9 : (visf.count * (1/0.9)); 
	
	//if the counter has reached the bottom
	if(visf.count < (1 / visf.resolution))
	{
		//clear the timer
		clearInterval(visf.clock);
		visf.clock = null;

		//do the image swap
		olObject.src = visf.src;

		//reverse the fade direction flag
		visf.fade = false;
		
		//restart the timer
		visf.clock = setInterval('isf.swapfade('+pisf+')', visf.length/visf.resolution);

	}
	
	//if the counter has reached the top
	if(visf.count > (1 - (1 / visf.resolution)))
	{
		//clear the timer
		clearInterval(visf.clock);
		visf.clock = null;

		//reset the fade direction flag
		visf.fade = true;
		
		//reset the counter
		visf.count = 1;

	}

	//set new opacity value on element
	//using whatever method is supported
	switch(visf.type)
	{
		case 'ie' :
			olObject.filters.alpha.opacity = visf.count * 100;
			break;
			
		case 'khtml' :
			olObject.style.KhtmlOpacity = visf.count;
			break;
			
		case 'moz' : 
			//restrict max opacity to prevent a visual popping effect in firefox
			olObject.style.MozOpacity = (visf.count == 1 ? 0.9999999 : visf.count);
			break;
			
		default : 
			//restrict max opacity to prevent a visual popping effect in firefox
			olObject.style.opacity = (visf.count == 1 ? 0.9999999 : visf.count);
	}
};

