var nIntervalID;
var nDirection;
var nGalleryLeft;

function ScrollLeft()
{
    nDirection = 5;
    nIntervalID = window.setInterval(StartScroll, 20);
}

function ScrollRight()
{
    nDirection = -5;
    nIntervalID =  window.setInterval(StartScroll, 20);
}

function StartScroll()
{
    var nXPos = 0;
    if(parseInt(document.getElementById('GalleryWrapper').style.left, 10))
    {
        nXPos = parseInt(document.getElementById('GalleryWrapper').style.left, 10); 
    }
    
    if((nDirection < 0 && nXPos > nGalleryLeft) || (nDirection > 0 && nXPos < 0))
    {        
        document.getElementById('GalleryWrapper').style.left = (nXPos + nDirection) + "px";
    }
}

function StopScroll()
{
    window.clearInterval(nIntervalID);
}

function InitGallery()
{
    var nGalleryWidth = 0; 
    for(var i=0; i<document.getElementById('GalleryWrapper').childNodes.length; i++)
    {
        if(document.getElementById('GalleryWrapper').childNodes[i].nodeName == "IMG")
        {
            nGalleryWidth = nGalleryWidth + 136;
        }
    }
    nGalleryLeft = (nGalleryWidth - 676 - 4) * -1;
}

function ClosePopupFrame()
{
    var pPopupFrame = getObject("GallerPopupFrame");
    if (pPopupFrame)
    {
        document.body.removeChild(pPopupFrame);
        hideFixMSIE('GallerPopupFrame');
    }
}

function ShowImageGallery(strImageSrc, strTitle)
{
    
    ClosePopupFrame();
    
    pPopupFrame = document.createElement('DIV');    
    pPopupFrame.id = 'GallerPopupFrame';
    pPopupFrame.className = 'gallerypopup'; 
    
    pPopupFrame.innerHTML = '<div class="close"><img src="' + strRootPath + 'images/close.gif" onclick="ClosePopupFrame();" /></div><img src="' + strImageSrc + '" onclick="ClosePopupFrame();" onload="OnImageLoad(this)" style="padding:2px;" alt="' + strTitle + '" />';        
    // alert('ShowImageGallery');  
    document.body.appendChild(pPopupFrame); 
}

function OnImageLoad(pImage)
{                                           
    var pPopupFrame = getObject("GallerPopupFrame");
    if (pPopupFrame)
    {
        var x = (getFrameWidth() / 2) - (pImage.width / 2) + getScrollX();
        var y = (getFrameHeight() / 2) - (pImage.height / 2) + getScrollY();  
                  
        pPopupFrame.style.top = y + 'px';
        pPopupFrame.style.left = x + 'px';
        
        pPopupFrame.style.visibility = "visible";
    
        resizeFixMSIE('GallerPopupFrame');
    }         
} 