﻿var maxspeed = 5;   
var startpos = 2;   
var timeout = 20;
var faderImage;
var mainImageParent;
var faderOpacity;
var newImagePath;

function ietruebody()
{
    return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;
}

function getposOffset(what, offsettype)
{
    var totaloffset = (offsettype == "left") ? what.offsetLeft : what.offsetTop;
    var parentEl = what.offsetParent;
    while (parentEl != null)
    {
        totaloffset = (offsettype == "left") ? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
        parentEl = parentEl.offsetParent;
    }
    return totaloffset;
}

function fadeOut()
{                 
    if(faderOpacity > 0)
    {        
        if(document.all)
		{		
		    faderImage.style.filter = 'alpha(opacity=' + faderOpacity + ')';
		    faderOpacity -= 5;	
		}
		else
		{
			faderImage.style.opacity = faderOpacity / 100;
			faderOpacity -= 3;	
		}
				    
        setTimeout("fadeOut()", 1);   
    }
    else
    {        
        mainImageParent.removeChild(faderImage);
		
		faderImage = document.createElement('img');
	    faderImage.setAttribute("id", "ctl00_mainArea_mainImage");
	    faderImage.setAttribute("src", "images/loading.gif");		
	    faderImage.setAttribute("alt", "");	    
	    mainImageParent.appendChild(faderImage);
      
        faderImage.setAttribute("src", newImagePath);               
        
        if(document.all)
		{		
		    faderImage.style.filter = 'alpha(opacity=100)';
		}
		else
		{
			faderImage.style.opacity = 1;
		}			       
    }
}

var firstCallToPage = true;

function changeImage(imagePath)
{              
    newImagePath = imagePath;    
    faderImage = document.getElementById ? document.getElementById("ctl00_mainArea_mainImage") : document.all.ctl00_mainArea_mainImage; 
    
    faderOpacity = 99;
    fadeOut();
}

function imageAlpha(obj, value)
{
    if (obj.filters && obj.filters[0])
    { 
        if (typeof obj.filters[0].opacity=="number") 
        {       
            obj.filters[0].opacity=value*100;
        }
        else 
        {
            obj.style.filter="alpha(opacity=" + value * 100 +")";
        }
    }
    else if (typeof obj.style.MozOpacity!="undefined") 
    {
        obj.style.MozOpacity=value;
    }
    else if (typeof obj.style.opacity!="undefined") 
    {
        obj.style.opacity=value;
    }
    else
    {
        // Nothing
    }    
}

function contains_ns6(a, b) 
{
    if (b!==null)
        while (b.parentNode)
            if ((b = b.parentNode) == a)
                return true;
    return false;
}

function InitializeScrollbars()
{    
    try
    {
        gallery_InitializeScrollbar();
    }
    catch(e) { }
    
    mainImageParent = document.getElementById ? document.getElementById("mainImageParent") : document.all.mainImageParent;            
}

window.onload = InitializeScrollbars;  
