
/* This Increments when the images construct */
var g_bAgents = false;
var g_bImageLoopStopped = false;
var g_bStopImageLoop = false;
var g_niPropertyImages = new Array();
var g_niAgentImages = 0;
var g_sImageRoot = "./idxsource/images/";
var g_aPropertyImageViews = new Array();
var g_aAgentImageViews = new Array();
var g_clPropertyMouseOver = 0;




function PropertyImage(sName, iWidth, iHeight, iEnlargedWidth, iEnlargedHeight)
{
    if (g_bAgents)
    {
        this.sSmallSource = "/agents/small/" + sName;
        this.sMediumSource = "/agents/medium/" + sName;
    }
    else
    {
        this.sSmallSource = g_sImageRoot + "small/" + sName;
        this.sMediumSource = g_sImageRoot + "medium/" + sName;
    }
    this.iWidth = iWidth;
    this.iHeight = iHeight;
    this.iEnlargedWidth = iEnlargedWidth;
    this.iEnlargedHeight = iEnlargedHeight;
}


function PropertyImageView(aImageNamesAndSizes)
{
    var i = 0;
    var niImages = 0;

    
    if (g_bAgents == true)
    {
        g_aAgentImageViews[g_niAgentImages] = this;
        g_niAgentImages++;
        
        this.iImage = g_niAgentImages - 1;
        this.sImage = "agent" +  (this.iImage + 1);
    }
    else
    {
        this.iImage = g_niPropertyImages[g_sSelectedTab] - 1;
        this.sImage = "image" +  (this.iImage + 1);
    }
    
    this.clImage = document.getElementById(this.sImage);
    this.clBackImage = new Image();
    this.fZoom = 0.0;
    this.aImages = new Array();
    this.iSelected = 0;
    
    while (aImageNamesAndSizes[i])
    {
        this.aImages[niImages++] = new PropertyImage(aImageNamesAndSizes[i], aImageNamesAndSizes[i + 1], aImageNamesAndSizes[i + 2], aImageNamesAndSizes[i + 3], aImageNamesAndSizes[i + 4]);
        i += 5;
    }
}

function BackImageLoaded()
{
    this._PropertyView.bLoaded = true;
}

PropertyImageView.prototype['UpdateImage'] = function()
{
    /* Fade Out Image */
    this.bFadingOut = false;
    this.bLoaded = false;
    
    this.clBackImage._PropertyView = this;
    this.clBackImage.onload = BackImageLoaded;
    
    if (this.fZoom > 0.0)
    {
        this.clBackImage.src = this.aImages[this.iSelected].sMediumSource;
    }
    else
    {
        this.clBackImage.src = this.aImages[this.iSelected].sSmallSource;
    }
}


PropertyImageView.prototype['ExpandImage'] = function()
{
    g_clPropertyMouseOver = this;
    
   // this.clBackExpandedImage.onload = BigImageLoaded;
    //this.clBackExpandedImage.src = this.aImages[this.iSelected].sMediumSource;
    
    
    document.getElementById(this.sImage).src = this.aImages[this.iSelected].sMediumSource;
}


PropertyImageView.prototype['NextImage'] = function()
{
    var iPrevImage = this.iSelected;
    
    if (!this.ValidateTransition())
        return;
    
    this.iSelected++;
    
    if (this.iSelected >= this.aImages.length)
        this.iSelected = 0;
        
    if (iPrevImage != this.iSelected)
        this.UpdateImage();
}

PropertyImageView.prototype['ValidateTransition'] = function()
{
    if (this.bFadingOut)
        return 0;
        
    return 1;
}

PropertyImageView.prototype['ResizeImage'] = function()
{
    var aSelected = this.aImages[this.iSelected];
    var iMaxWidthDiff = aSelected.iEnlargedWidth - aSelected.iWidth;
    var iMaxHeightDiff = aSelected.iEnlargedHeight - aSelected.iHeight;
    var iWidth = aSelected.iWidth + (iMaxWidthDiff * this.fZoom);
    var iHeight = aSelected.iHeight + (iMaxHeightDiff * this.fZoom);
    
    this.clImage.style.width = iWidth;
    this.clImage.style.height = iHeight;
}               

function PropertyImages_TransitionHandler()
{
    var fOpacity, i;
    var clPropertyView;
    var bResizeImage;

    g_bImageLoopStopped = false;
    
    if (g_aPropertyImageViews[g_sSelectedTab])
    {
        for (i = 0; i < g_aPropertyImageViews[g_sSelectedTab].length + g_aAgentImageViews.length; i++)
        {
            if (i <  g_aPropertyImageViews[g_sSelectedTab].length)
            {
                sName = 'property';
                clPropertyView =  g_aPropertyImageViews[g_sSelectedTab][i];
            }
            else
            {
                sName = 'agent';
                clPropertyView = g_aAgentImageViews[i -  g_aPropertyImageViews[g_sSelectedTab].length];
            }
            
            if (!clPropertyView)
                continue;
               
            if (!clPropertyView.clImage)
                clPropertyView.clImage = document.getElementById(clPropertyView.sImage);

            if (!clPropertyView.clImage)
                continue;

            if (g_clPropertyMouseOver == clPropertyView)
            {
                if (clPropertyView.fZoom != 1.0)
                {
                    bResizeImage = true;
                    
                    clPropertyView.fZoom += 0.15;
                    
                    if (clPropertyView.fZoom > 1.0)
                        clPropertyView.fZoom = 1.0;
                }
            }
            else if (clPropertyView.fZoom != 0.0)
            {
                bResizeImage = true;
                
                clPropertyView.fZoom -= 0.15;
                
                if (clPropertyView.fZoom <= 0.0)
                {
                    /*if (typeof document.body.style.maxHeight == "undefined")
                    {
                        /* If we're using IE6 or lower
                        //document.getElementById(clPropertyView.sImage).filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='" + clPropertyView.aImages[clPropertyView.iSelected].sSmallSource + "')";
                    }
                    else*/
                    
                    clPropertyView.clImage.src = clPropertyView.aImages[clPropertyView.iSelected].sSmallSource;
                    
                    
                    clPropertyView.fZoom = 0.0;
                }
            }
            
            if (bResizeImage)
            { 
                clPropertyView.ResizeImage();
                
                bResizeImage = false;
            }
            

            if (clPropertyView.clImage.style.opacity != null)
                fOpacity = parseFloat(clPropertyView.clImage.style.opacity);
            else
            {
                if (clPropertyView.clImage.style.opacity != 1.0)
                    clPropertyView.clImage.style.opacity = 1.0;
                
                fOpacity = 1.0;
            }
            
            if (clPropertyView.bLoaded)
            {
                /* Set the Image on the Document, and start fading in */
                
                if ((clPropertyView.fZoom == 0.0) || (clPropertyView.fZoom == 1.0))
                    clPropertyView.ResizeImage();
                    
                clPropertyView.clImage.parentNode.style.backgroundImage = 'url(' + clPropertyView.clBackImage.src + ')';
                
                clPropertyView.bFadingOut = true;
                clPropertyView.bLoaded = false;
            }        
            
            if (clPropertyView.bFadingOut)
            {
                fOpacity -= 0.06;
                
                if (fOpacity <= 0.0)
                {
                    fOpacity = 1.0;
                    
                    clPropertyView.clImage.src = clPropertyView.clBackImage.src;
                    clPropertyView.clImage.style.opacity = 1.0;
                    clPropertyView.clImage.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=100)";
                    
                    clPropertyView.bFadingOut = false;
                }
                else
                {
                    var iOpacityRounded = parseInt(Math.round(fOpacity * 100));
                   
                    clPropertyView.clImage.style.opacity = fOpacity;
                    clPropertyView.clImage.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + iOpacityRounded.toString() + ")";
                        
                }
            }
        }
    }
    
    if (g_bStopImageLoop)
    {
        g_bImageLoopStopped = true;
        return;
    }
    
    setTimeout('PropertyImages_TransitionHandler()', 30);
}

PropertyImages_TransitionHandler();