

//cache the images
ixf4.imgsLen = ixf4.imgs.length;
ixf4.cache = [];
for(var i=0; i<ixf4.imgsLen; i++)
{
    ixf4.cache[i] = new Image;
    ixf4.cache[i].src = ixf4.imgs[i];
}


//crossfade setup function
function crossfade4()
{
    //if the timer is not already going
    if(ixf4.clock == null)
    {
        //copy the image object 
        ixf4.obj = document.getElementById(arguments[0]);
        
        //copy the image src argument 
        ixf4.src = ixf4.imgs[arguments[5]];
        
        //store the supported form of opacity
        if(typeof ixf4.obj.style.opacity != 'undefined')
        {
            ixf4.type = 'w3c';
        }
        else if(typeof ixf4.obj.style.MozOpacity != 'undefined')
        {
            ixf4.type = 'moz';
        }
        else if(typeof ixf4.obj.style.KhtmlOpacity != 'undefined')
        {
            ixf4.type = 'khtml';
        }
        else if(typeof ixf4.obj.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
            ixf4.type = (ixf4.obj.filters.length > 0 && typeof ixf4.obj.filters.alpha == 'object' && typeof ixf4.obj.filters.alpha.opacity == 'number') ? 'ie' : 'none';
        }
        else
        {
            ixf4.type = 'none';
        }
        
        //change the image alt text if defined
        if(typeof arguments[4] != 'undefined' && arguments[4] != '')
        {
            ixf4.obj.alt = arguments[4];
        }
        
        //if any kind of opacity is supported
        if(ixf4.type != 'none')
        {
            //create a new image object and append it to body
            //detecting support for namespaced element creation, in case we're in the XML DOM
            ixf4.newimg = document.getElementsByTagName('body')[0].appendChild((typeof document.createElementNS != 'undefined') ? document.createElementNS('http://www.w3.org/1999/xhtml', 'img') : document.createElement('img'));

            //set positioning classname
            ixf4.newimg.className = 'idupe4';
            
            //set src to new image src
            ixf4.newimg.src = ixf4.src

            //move it to superimpose original image
            ixf4.newimg.style.left = ixf4.getRealPosition(ixf4.obj, 'x') + 'px';
            ixf4.newimg.style.top = ixf4.getRealPosition(ixf4.obj, 'y') + 'px';
            
            //copy and convert fade duration argument 
            ixf4.length = parseInt(eval(arguments[2]* 1000), 10) ;
            
            //create fade resolution argument as 20 steps per transition
            ixf4.resolution = parseInt(eval(arguments[2]* 20), 10) ;
            
            //start the timer
            ixf4.clock = setInterval('ixf4.crossfade()', ixf4.length/ixf4.resolution);
        }
        
        //otherwise if opacity is not supported
        else
        {
            //just do the image swap
            ixf4.obj.src = ixf4.src;
        }

        //alert(arguments[5]);
        //alert(eval(parseInt(arguments[5]) + 1));
        //alert((eval(parseInt(arguments[5]) + 1)  % ixf4.imgs.length));


        if(arguments[6]==1) {
			for (tno=0;tno<20;tno++) {
				thisNumberAround =(Math.round(ixf4.imgs.length*Math.random())+1)  % ixf4.imgs.length;
				if(thisNumberAround != arguments[5]) { break; }

			}

		}
		else {
			thisNumberAround = (eval(parseInt(arguments[5]) + 1)  % ixf4.imgs.length);

		}
        timermSeconds = arguments[3] * 1000;
        setTimeout("crossfade4('"+arguments[0]+"',"+arguments[1]+",'"+arguments[2]+"','"+arguments[3]+"','"+arguments[4]+"',"+thisNumberAround+","+arguments[6]+")",timermSeconds);
        
    }
};


//crossfade timer function
ixf4.crossfade = function()
{
    //decrease the counter on a linear scale
    ixf4.count -= (1 / ixf4.resolution);
    
    //if the counter has reached the bottom
    if(ixf4.count < (1 / ixf4.resolution))
    {
        //clear the timer
        clearInterval(ixf4.clock);
        ixf4.clock = null;
        
        //reset the counter
        ixf4.count = 1;
        
        //set the original image to the src of the new image
        ixf4.obj.src = ixf4.src;
    }
    
    //set new opacity value on both elements
    //using whatever method is supported
    switch(ixf4.type)
    {
        case 'ie' :
            ixf4.obj.filters.alpha.opacity = ixf4.count * 100;
            ixf4.newimg.filters.alpha.opacity = (1 - ixf4.count) * 100;
            break;
            
        case 'khtml' :
            ixf4.obj.style.KhtmlOpacity = ixf4.count;
            ixf4.newimg.style.KhtmlOpacity = (1 - ixf4.count);
            break;
            
        case 'moz' : 
            //restrict max opacity to prevent a visual popping effect in firefox
            ixf4.obj.style.MozOpacity = (ixf4.count == 1 ? 0.9999999 : ixf4.count);
            ixf4.newimg.style.MozOpacity = (1 - ixf4.count);
            break;
            
        default : 
            //restrict max opacity to prevent a visual popping effect in firefox
            ixf4.obj.style.opacity = (ixf4.count == 1 ? 0.9999999 : ixf4.count);
            ixf4.newimg.style.opacity = (1 - ixf4.count);
    }
    
    //now that we've gone through one fade iteration 
    //we can show the image that's fading in
    ixf4.newimg.style.visibility = 'visible';
    
    //keep new image in position with original image
    //in case text size changes mid transition or something
    ixf4.newimg.style.left = ixf4.getRealPosition(ixf4.obj, 'x') + 'px';
    ixf4.newimg.style.top = ixf4.getRealPosition(ixf4.obj, 'y') + 'px';
    
    //if the counter is at the top, which is just after the timer has finished
    if(ixf4.count == 1)
    {
        //remove the duplicate image
        ixf4.newimg.parentNode.removeChild(ixf4.newimg);
    }
};



//get real position method
ixf4.getRealPosition = function()
{
    this.pos = (arguments[1] == 'x') ? arguments[0].offsetLeft : arguments[0].offsetTop;
    this.tmp = arguments[0].offsetParent;
    while(this.tmp != null)
    {
        this.pos += (arguments[1] == 'x') ? this.tmp.offsetLeft : this.tmp.offsetTop;
        this.tmp = this.tmp.offsetParent;
    }
    
    return this.pos;
};
