/*
DOM scripting by brothercake -- http://www.brothercake.com/
*/

// Version 2.0
// Last Updated 7/23/2007
// Copyright 2007 The Church Media Group, Inc (www.churchmedia.cc)
// To use this, you'll need an image with the name/id= rotateimg
// If you have useLinks set to true, you'll need an anchor with the name = rotatelink

// example setup - add the following files to the head of your document (in that order)
// <script type="text/javascript" src="cmgrotator/cmgrotator1.js"></script>
// <script type="text/javascript" src="cmgrotator/cmgrotator2.js"></script>
// <link rel="stylesheet" type="text/css" href="cmgrotator/cmgrotator.css" />

// add and image with the id rotateimg and add an anchor around it named rotatelink (only if you use links in the rotator)
// <a href="#" name="rotatelink" id="rotatelink"><img src="images/rotator/1.jpg" width="734" height="174" id="rotateimg" border="0"></a>

// Global Vars
var ixf = { 'clock' : null, 'count' : 1 }
var Lnk = new Array();
var LnkTargt = new Array();
var ImgAlt = new Array();
var x = -1; // This is the number used for the array
var useLinks = false; // set to false if you do not use href
var rotateTime = 7000; // in milliseconds

// 1 LIST THE IMAGES

ixf.imgs = [
        'pic/screenbildp4b01.jpg',
        'pic/screenbildwkf01.jpg',
        'pic/screenbildzul01.jpg'
];



/* DO NOT EDIT ANYTHING BELOW */

//cache the images
ixf.imgsLen = ixf.imgs.length;
ixf.cache = [];
for(var i=0; i<ixf.imgsLen; i++)
{
        ixf.cache[i] = new Image;
        ixf.cache[i].src = ixf.imgs[i];
}

function crossfade()
{
        if(ixf.clock == null)
        {
                ixf.obj = arguments[0];
                ixf.src = arguments[1];
                if(typeof ixf.obj.style.opacity != 'undefined')
                {
                        ixf.type = 'w3c';
                }
                else if(typeof ixf.obj.style.MozOpacity != 'undefined')
                {
                        ixf.type = 'moz';
                }
                else if(typeof ixf.obj.style.KhtmlOpacity != 'undefined')
                {
                        ixf.type = 'khtml';
                }
                else if(typeof ixf.obj.filters == 'object')
                {
                        ixf.type = (ixf.obj.filters.length > 0 && typeof ixf.obj.filters.alpha == 'object' && typeof ixf.obj.filters.alpha.opacity == 'number') ? 'ie' : 'none';
                }
                else
                {
                        ixf.type = 'none';
                }

                if(typeof arguments[3] != 'undefined' && arguments[3] != '')
                {
                        ixf.obj.alt = arguments[3];
                }

                if(ixf.type != 'none')
                {
                        ixf.newimg = document.getElementsByTagName('body')[0].appendChild((typeof document.createElementNS != 'undefined') ? document.createElementNS('http://www.w3.org/1999/xhtml', 'img') : document.createElement('img'));
                        ixf.newimg.className = 'idupe';
                        ixf.newimg.src = ixf.src
                        ixf.newimg.style.left = ixf.getRealPosition(ixf.obj, 'x') + 'px';
                        ixf.newimg.style.top = ixf.getRealPosition(ixf.obj, 'y') + 'px';
                        ixf.length = parseInt(arguments[2], 10) * 1000;
                        ixf.resolution = parseInt(arguments[2], 10) * 20;
                        ixf.clock = setInterval('ixf.crossfade()', ixf.length/ixf.resolution);
                }
                else
                {
                        ixf.obj.src = ixf.src;
                }

        }
};


ixf.crossfade = function()
{
        ixf.count -= (1 / ixf.resolution);

        if(ixf.count < (1 / ixf.resolution))
        {
                clearInterval(ixf.clock);
                ixf.clock = null;
                ixf.count = 1;
                ixf.obj.src = ixf.src;
        }

        switch(ixf.type)
        {
                case 'ie' :
                        ixf.obj.filters.alpha.opacity = ixf.count * 100;
                        ixf.newimg.filters.alpha.opacity = (1 - ixf.count) * 100;
                        break;

                case 'khtml' :
                        ixf.obj.style.KhtmlOpacity = ixf.count;
                        ixf.newimg.style.KhtmlOpacity = (1 - ixf.count);
                        break;

                case 'moz' :
                        ixf.obj.style.MozOpacity = (ixf.count == 1 ? 0.9999999 : ixf.count);
                        ixf.newimg.style.MozOpacity = (1 - ixf.count);
                        break;

                default :
                        ixf.obj.style.opacity = (ixf.count == 1 ? 0.9999999 : ixf.count);
                        ixf.newimg.style.opacity = (1 - ixf.count);
        }

        ixf.newimg.style.visibility = 'visible';

        ixf.newimg.style.left = ixf.getRealPosition(ixf.obj, 'x') + 'px';
        ixf.newimg.style.top = ixf.getRealPosition(ixf.obj, 'y') + 'px';

        if(ixf.count == 1)
        {
                ixf.newimg.parentNode.removeChild(ixf.newimg);
        }
};

ixf.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;
};