// general state
var photoShown = new Array();
var photoCache = new Array();
var zoomedPhotoCache = new Array();
var intCurLeft = 0;
var intCurRight = 1;
var shadowPageDiv = "";
var shadowPageInner = "";
var preLoadPhotos = 4;
var preLoadZoomedPhotos = 2;
var curZoomState = 0;
var zoomDiv = null;
var curPageType = "";
var logoButtonLeftFF = "674px";
var logoButtonLeftIE6 = "674px";
var logoButtonLeftMinIE6 = "674px";
var logoButtonTopIE6 = "0px";
var logoButtonTopMinIE6 = "-25px";
FRONT = 0;
INSIDE = 1;
BACK = 2;

// useful images
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";

// books
var bookDivName = "";
var bookCoverSrc = "";
var bookSpreadDiv = "";
var bookSpreadSrc1 = "";
var bookSpreadSrc2 = "";
var bookZoomDiv = "";
var bookZoomInner = "";
var bookZoomWidth = 1;
var bookZoomHeight = 1;
var spineFrontLeft = "48px";
var spineBackLeft = "348px";
var spineZoomFrontLeft = "0px";
var spineZoomBackLeft = "600px";
var clickZoomSpreadLeft = "805px";
var clickZoomLeft = "595px";
var isCoverPage = 1;
STANDARDBOOK = 1;
CUSTOMBOOK = 2;

// cards
var cardDivName = "";
var cardFaceSrc = "";
var cardInsideDiv = "";
var cardInsideSrc1 = "";
var cardInsideSrc2 = "";
var cardZoomDiv = "";
var cardZoomInner = "";
var cardZoomWidth = 1;
var cardZoomHeight = 1;
FLATCARD = 1;
FOLDCARD = 2;

// general functions

function initWindowSize()
{
    var minWidth = (screen.width < 1024) ? 800 : 1024;
    var minHeight = (screen.height < 768) ? 600 : 768;
    var x = getWindowWidth(top);
    var y = getWindowHeight(top);
    if (y > minHeight) minHeight = y;
    if (x < minWidth) top.resizeTo(minWidth, minHeight);
}

// masterpage functions

function setHeadAndFootPosition()
{
    var windowWidth = getWindowWidth(top);
    
    if (chk.getBrowser() == "Internet Explorer")
    {
        if (chk.needsPngFix() && document.getElementById("BuyButtonDiv"))
        {
            document.getElementById("BuyButtonDiv").style.left = "685px";
        }
        
        if (windowWidth < 916)
        {
            if (document.getElementById("headerMaster"))
                document.getElementById("headerMaster").style.left = "3px";
            if (document.getElementById("footerMaster"))
                document.getElementById("footerMaster").style.left = "0px";
        }
        else
        {
            windowWidth = windowWidth / 2;
            if (document.getElementById("headerMaster"))
                document.getElementById("headerMaster").style.left = (windowWidth - 449) + "px";
            if (document.getElementById("footerMaster"))
            {
                if (!chk.needsPngFix())
                {
                    document.getElementById("footerMaster").style.left = (windowWidth - 452) + "px";
                }
                else
                {
                    document.getElementById("footerMaster").style.left = "5px";
                }
            }    
        }
    }
    else  // Firefox
    {
        if (windowWidth < 930)
        {
            if (document.getElementById("headerMaster"))
                document.getElementById("headerMaster").style.left = "3px";
            if (document.getElementById("footerMaster"))
                document.getElementById("footerMaster").style.left = "0px";
        }
        else
        {
            windowWidth = windowWidth / 2;
            if (document.getElementById("headerMaster"))
                document.getElementById("headerMaster").style.left = (windowWidth - 462) + "px";;
            if (document.getElementById("footerMaster"))
                document.getElementById("footerMaster").style.left = (windowWidth - 465) + "px";;
        }
    }
}


// book functions

function getBookPage(ind, preLoad, locDiv, refreshFunction)
{

    if (ind < 0 || ind >= albumCount || preLoad < 0)
    {
        return;
    }
    	
    if (!photoCache[ind] || photoCache[ind].src == imgError)	
    {
        document.getElementById(locDiv).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;
		            }
                            if (typeof refreshFunction != 'undefined') refreshFunction((ind%2==0) ? ind : ind-1);
	            }
            });
    } 
     
    getBookPage(ind+1, preLoad-1, locDiv, refreshFunction);
}

function zoomBookPhoto(objectClicked)
{
	if (isNotRealPicture(objectClicked.src) == 1) return;

	zoomDiv = document.getElementById(bookZoomDiv);

	if (zoomDiv) 
	{
	    var zoomInnerDiv = document.getElementById(bookZoomInner);
	    var zoomTransition = getTransition();
	    
		if (curZoomState == 0) 
		{
			curZoomState = 1;
			zoomDiv.style.visibility = "visible";
			zoomInnerDiv.innerHTML = 
			    "<IMG id=\"zoomedPhoto\" name=\"zoomedPhoto\" onclick=\"zoomBookPhoto(this); return false;\" border=\"0\" width=\"" + bookZoomWidth + "\" height=\"" + bookZoomHeight + "\" src=\"" + imgDummy + "\">";
			document.getElementById("zoomSpineDiv").innerHTML =
			    "<IMG id=\"zoomedSpine\" name=\"zoomedSpine\" border=\"0\" height=\"" + bookZoomHeight + "\" class=\"zoomCustomSpine\" src=\"images/spine_shadow_overlay.png\">";
			ApplyTransition("zoomedPhoto", zoomedPhotoList[objectClicked.photoIndex], zoomTransition)
			
			if (curPageType != INSIDE)
			{
			    document.getElementById("zoomSpineDiv").style.visibility = "visible";
			}
			if (curPageType == BACK)
			{
                document.getElementById("zoomedSpine").src="images/spine_shadow_overlay_back_cover.png";
			    document.getElementById("zoomedSpine").style.left = "715px";
			}
			else
			{
			    document.getElementById("zoomedSpine").style.left = spineZoomFrontLeft;
			}
		} 
		else 
		{
			curZoomState = 0;
			
            if (chk.getBrowser() == "Internet Explorer")
            {
                document.getElementById("customShadow").style.top = "-302px";
            }
            else
            {
                document.getElementById("customShadow").style.top = "-296px";
            }
            
			document.getElementById("zoomSpineDiv").style.visibility = "hidden";
			setTimeout('hideZoom()', zoomTransition);
			fadeImage("zoomedPhoto", zoomTransition);
		}
	
	    if (chk.getBrowser() == "Internet Explorer"  && chk.getOS() != "Macintosh" ) 
	    {
	        if (chk.needsPngFix())
	        {
	            correctPNG();
	        }
        }
	}
}

// card functions
function getCardFace(ind, preLoad, curType)
{
    if (ind < 0 || ind >= albumCount || preLoad < 0 || !cardDivName)
    {
        return;
    }
	
    if (!photoCache[ind] || photoCache[ind].src == imgError)	
    {
        document.getElementById(cardDivName).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;
		            }
	            }
            });
    }  
      
    getCardFace(ind+1, preLoad-1, curType);
}

function nextFlatCardFace()
{
    photoShown[intCurLeft] = 0;
    intCurLeft = intCurLeft == 1 ? 0 : 1;

    getCardFace(intCurLeft, 2, FLATCARD);
    getZoomedPhoto(intCurLeft, 1);
	
    if (intCurLeft == 0)
    {
        document.getElementById("btnNext").src="images/webview_next.gif";
    }
    else
    {
        document.getElementById("btnNext").src="images/webview_back.gif";
    }
	
    showCard(intCurLeft, FLATCARD);
    lPreview(originalInstanceGUID, instanceVersionGUID, 1);
    cookiePreview.lastPage = intCurLeft;
    cookiePreview.store();
}

function showCard(curPhoto, curType) 
{
    if (curPhoto == 0)
    {
        showCardPhoto(curPhoto, cardFaceSrc, FRONT);
    }
    else if (curType == FLATCARD)
    {
        showCardPhoto(curPhoto, cardFaceSrc, INSIDE);
    }
    else
    {
        showCardPhoto(curPhoto, cardInsideSrc1, INSIDE);
        showCardPhoto(curPhoto + 1, cardInsideSrc2, INSIDE);
    }
	
	if (chk.getBrowser() == "Internet Explorer"  && chk.getOS() != "Macintosh" ) 
	{
	    if (chk.needsPngFix())
	    {
	        correctPNG();
	    }
    }
}

function showCardPhoto(curPhoto, locName, pageType)
{
    var imageLoc = document.getElementById(locName);
    
    // If image still loading, display "loading".
	if (!photoCache[curPhoto] && curPhoto < albumCount) 
	{
		imageLoc.src = imgLoading;
		return;
	}

    // If image has error, display without further processing.
	if (photoCache[curPhoto] && photoCache[curPhoto].src.slice(-1*imgError.length) == imgError) 
	{
		imageLoc.src = photoCache[curPhoto].src;
		return;
	}

    // If requested image is already shown in location, no need to do more.
	if (photoShown[curPhoto] == 1 && imageLoc.src == photoList[curPhoto] && photoList[curPhoto] != imgDummy) 
	{
	    return;
    }
   
    photoShown[curPhoto] = 1;
    imageLoc.photoIndex = curPhoto;
    var photoToShow;
   
    if (curPhoto >= albumCount)
    {
        photoToShow = imgBlank;
    }
    else if (photoCache[curPhoto])
    {
        photoToShow = photoList[curPhoto];
    }
    else
    {
        photoToShow = imgLoading;
    }
    
    if (pageType == FRONT)
    {
        if (document.getElementById("btnNext")) 
        {
            document.getElementById("btnNext").src = "images/webview_next.gif";
            document.getElementById("btnNext").title = "View Next Photo";
        }
    }
    else
    {
        if (document.getElementById("btnNext")) 
        {
            document.getElementById("btnNext").src = "images/webview_back.gif";
            document.getElementById("btnNext").title = "View Previous Photo";
        }
    }
    
	if (photoToShow != imgLoading) 
	{
	    ApplyTransition(locName, photoToShow, getTransition());
	}
}

function zoomCardFace(objectClicked)
{
    if (isNotRealPicture(objectClicked.src) == 1) return;

    zoomDiv = document.getElementById(cardZoomDiv);

    if (zoomDiv) 
    {
        var zoomInnerDiv = document.getElementById(cardZoomInner);
        var zoomTransition = getTransition();
	    
        if (curZoomState == 0) 
        {
	        curZoomState = 1;
	        zoomDiv.style.visibility = "visible";
	        zoomInnerDiv.innerHTML = 
	        "<IMG id=\"zoomedPhoto\" name=\"zoomedPhoto\" onclick=\"zoomCardFace(this); return false;\" border=\"0\" width=\"" + cardZoomWidth + "\" height=\"" + cardZoomHeight + "\" src=\"" + imgDummy + "\">";
	        ApplyTransition("zoomedPhoto", zoomedPhotoList[objectClicked.photoIndex], zoomTransition)
        } 
        else 
        {
	        curZoomState = 0;
	        setTimeout('hideZoom()', zoomTransition);
	        fadeImage("zoomedPhoto", zoomTransition)
        }
    }
}

function hideCardZoom()
{
	zoomDiv.style.visibility = "hidden";
}

// 

// old stuff
var curButtonsDivTop = 0;
var curButtonsDivLeft = 0;
var curSpreadDivTop = 0;
var curSpreadDivLeft = 0;
var buttonsDiv = null;
var curDiv = 0;
var isCoverPage = 1;


// Disable landing page
var timer = null;
var preLoadCards = 4;
GFALBUM = "BookGF";
STANDARDBOOK = "None";

// Set view for specified type.
function setCurrentAlbumType(type)
{
    if (type)
    {
         currentAlbumType = type;
    }
    else
    {
        currentAlbumType = (document.getElementById("photo")) ? GFALBUM : STANDARDBOOK;
    }
    
    setBookView();
}

// Init general settings for all books.
function setBookView()
{
    if (document.getElementById("ShareItem")) document.getElementById("ShareItem").style.visibility="hidden"; 
    if (document.getElementById("coverPage")) document.getElementById("coverPage").style.visibility="visible"; 
    if (document.getElementById("btnBuyNow")) document.getElementById("btnBuyNow").src="images/webview_buy_this_book.png";
    if (document.getElementById("ButtonView")) document.getElementById("ButtonView").style.visibility="visible";
    if (document.getElementById("CardButtonView")) document.getElementById("CardButtonView").style.visibility="hidden";
    if (document.getElementById("Iframe3")) document.getElementById("Iframe3").src="http://www.picaboo.com/promo/webview/IframeCreateBook.htm";
    if (document.getElementById("Iframe1")) document.getElementById("Iframe1").src="http://www.picaboo.com/promo/webview/IframeCreateBook.htm";
}

function getTransition()
{
    return (chk.getOS() == "Macintosh" ? 500 : (chk.getBrowser == "Internet Explorer" ? 500 : 240));
}

function isNotRealPicture(objectClicked)
{
    return (objectClicked.indexOf(imgBlank) != -1 || 
            objectClicked.indexOf(imgLoading) != -1 || 
            objectClicked.indexOf(imgCoverSheet) != -1) ? 1 : 0; 
}

function setZoomPhotoDivLeft()
{
    if (chk.getBrowser() != "Internet Explorer")
    { 
        if (chk.getBrowser() != "Netscape")
        {
            var windowWidth = getWindowWidth(top);
            windowWidth = document.documentElement ? document.documentElement.scrollWidth : windowWidth;
            
            if (windowWidth > 800)
            {
                document.getElementById("zoomPhoto").style.left = (windowWidth - 800) / 2;
            }
            else
            {
                document.getElementById("zoomPhoto").style.left = "0";
            }
        }
        else
        {
            if(screen.width == 1280)
            {
                document.getElementById("zoomPhoto").style.left = "240";
            }
            else if(screen.width == 1024)
            {
                document.getElementById("zoomPhoto").style.left = "110";
            }
            else if(screen.width == 800)
            {
                document.getElementById("zoomPhoto").style.left = "0";
            }
        }
    }
}

function showDiv(type)
{
    //Zoom
    setZoomPhotoDivLeft();
	     
    if (type == curDiv) return;
    curDiv = type;
  
    if (type == 3) 
    {
		if (document.getElementById("logo")) document.getElementById("logo").style.visibility="hidden"; // visible
		if (document.getElementById("footerPage")) document.getElementById("footerPage").style.visibility="hidden";
		if (document.getElementById("owner")) document.getElementById("owner").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";
    } 
    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("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("BuyItem")) document.getElementById("BuyItem").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("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 (chk.getBrowser() != "Internet Explorer")
            {
                if(screen.width < 1280)
                {
                    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("logo") && getParameter('showHeader') != 0) document.getElementById("logo").style.visibility= (currentAlbumType == GFALBUM) ? "hidden" : "visible";
		    //if (document.getElementById("shadowPage")) document.getElementById("shadowPage").style.visibility= "visible";
			if (document.getElementById("footerPage")) document.getElementById("footerPage").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("marketingCoverPhoto")) document.getElementById("marketingCoverPhoto").style.visibility="hidden";
            if (document.getElementById("marketingCoverPage")) document.getElementById("marketingCoverPage").style.visibility="hidden";
            if (document.getElementById("shadowAlbumInnerPage")) document.getElementById("shadowAlbumInnerPage").innerHTML = "<IMG alt=\"\" src=\"" + shadowAlbum + "\" border=\"0\" width=\"" + shadowWidth + "px\" height=\"" + shadowHeight + "px\" 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("BuyItem")) document.getElementById("BuyItem").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 (chk.getBrowser() != "Internet Explorer")
            { 
                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");

	if (zoomDiv) 
	{
	    var zoomInnerDiv = document.getElementById("zoomInnerDiv");
	    var zoomTransition = getTransition();
	    
		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], zoomTransition)
		} 
		else 
		{
			curZoomState = 0;
			setTimeout('hideZoom()', zoomTransition);
			fadeImage("zoomedPhoto", zoomTransition)
		}
	}
}

function toggleZoom(object)
{
    var spreadDiv = spreadDiv = document.getElementById("spreadPage");
	curSpreadDivTop = spreadDiv.offsetTop;
	curSpreadDivLeft = spreadDiv.offsetLeft;

	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 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" ) 
	{
	    if (chk.needsPngFix())
	    {
	        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;

	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;

	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');
		    showDiv(4);
			return;
		}
	}

	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');
		    showDiv(4);
			return;
		}
	}

	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
   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++;
    }
}

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]);
    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);
	}
};

