﻿///-codeFile-//////////////////////////////////////////////////////////////////
// Support.js
///////////////////////////////////////////////////////////////////////////////


var menuBackground = new Image();
menuBackground.src = 'http://imgsfour.rekoop.com/web/nav/menuselected.gif';


var MSIEVersion = 0;
if (navigator.appVersion.indexOf('MSIE') > -1)
{
    try { MSIEVersion = parseFloat(navigator.appVersion.split('MSIE')[1]); }
    catch (e) {}
}


///-function-//////////////////////////////////////////////////////////////////
// wGet
///////////////////////////////////////////////////////////////////////////////
function wGet(ID) { return window.document.getElementById(ID); }


///-function-//////////////////////////////////////////////////////////////////
// WindowOnloadFixes
///////////////////////////////////////////////////////////////////////////////
function WindowOnloadFixes()
{
    IE6PNGCSS();
    IE6PNGImages();
}


///-function-//////////////////////////////////////////////////////////////////
// IE6PNGCSS
///////////////////////////////////////////////////////////////////////////////
function IE6PNGCSS()
{
    if (MSIEVersion >= 5.5 && MSIEVersion < 7.0 && window.document.body.filters)
    {
        for (var countCSS = 0; countCSS < window.document.styleSheets.length; ++countCSS)
        {
            for (var countRules = 0; countRules < window.document.styleSheets[countCSS].rules.length; ++countRules)
            {
                try
                {
                    if (window.document.styleSheets[countCSS].rules[countRules].style.backgroundImage.indexOf('.png') > -1)
                    {
                        if (window.document.styleSheets[countCSS].rules[countRules].style.filter == '')
                        {
                            var pngSrc = window.document.styleSheets[countCSS].rules[countRules].style.backgroundImage;
                            pngSrc = pngSrc.replace(/url\(/, '').replace(/\.\.\//g, '').replace(/\)/g, '');

                            window.document.styleSheets[countCSS].rules[countRules].style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + pngSrc + '\', sizingMethod=\'scale\');';
                            window.document.styleSheets[countCSS].rules[countRules].style.backgroundImage = '';
                        }
                    }
                }
                catch (e) {}
            }
        }
    }
}


///-function-//////////////////////////////////////////////////////////////////
// IE6PNGImage
///////////////////////////////////////////////////////////////////////////////
function IE6PNGImage(Img, Force)
{
    try
    {
        if (Img.src.indexOf('.png') > -1 || Force)
        {
            if (Img.style.filter == '' || Force)
            {
                Img.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + Img.src + '\', sizingMethod=\'scale\');';
                Img.src = 'http://imgsfour.rekoop.com/web/nav/trans.gif';
            }
        }
    }
    catch (e) {}
}


///-function-//////////////////////////////////////////////////////////////////
// IE6PNGImages
///////////////////////////////////////////////////////////////////////////////
function IE6PNGImages()
{
    if (MSIEVersion >= 5.5 && MSIEVersion < 7.0 && window.document.body.filters)
        for (var count = 0; count < window.document.images.length; ++count)
            IE6PNGImage(window.document.images[count]);
}


///-function-//////////////////////////////////////////////////////////////////
// IE6PNGImageByID
///////////////////////////////////////////////////////////////////////////////
function IE6PNGImageByID(ID, Force)
{
    if (MSIEVersion >= 5.5 && MSIEVersion < 7.0 && window.document.body.filters)
        IE6PNGImage(wGet(ID), Force);
}


///-function-//////////////////////////////////////////////////////////////////
// ChangeMenuBackground
///////////////////////////////////////////////////////////////////////////////
function ChangeMenuBackground(LayerID, On)
{
    if (wGet(LayerID))
    {
        if (On)
            wGet(LayerID).style.background = 'url(' + menuBackground.src + ')';
        else
            wGet(LayerID).style.background = 'none';
    }
}


///-function-//////////////////////////////////////////////////////////////////
// ShowContent
///////////////////////////////////////////////////////////////////////////////
function ShowContent(ID, ContentIDs)
{
    if (wGet(ID))
    {
        wGet(ID).style.visibility = 'visible';

        for (var count = 0; count < ContentIDs.length; ++count)
            if (ContentIDs[count] != ID && wGet(ContentIDs[count]))
                wGet(ContentIDs[count]).style.visibility = 'hidden';
    }
}


///-class-/////////////////////////////////////////////////////////////////////
// Vector2D
///////////////////////////////////////////////////////////////////////////////
function Vector2D(X, Y)
{
    ///-data-//////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////

    this._x = X;
    this._y = Y;


    ///-methods-///////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////

    this.toString = function() { return this._x + '|' + this._y; };
    this.Clone = function() { return new Vector2D(this._x, this._y); };

    this.GetXInt = function() { return Math.round(this._x); };
    this.GetYInt = function() { return Math.round(this._y); };

    this.GetXPxl = function() { return Math.round(this._x) + 'px'; };
    this.GetYPxl = function() { return Math.round(this._y) + 'px'; };

    this.Equals = function(Vector) { return this._x == Vector._x && this._y == Vector._y; };

    this.AddVal = function(Value) { this._x += Value; this._y += Value; return this; };
    this.SubVal = function(Value) { this._x -= Value; this._y -= Value; return this; };
    this.MulVal = function(Value) { this._x *= Value; this._y *= Value; return this; };
    this.DivVal = function(Value)
    {
        if (Value)
        {
            this._x /= Value;
            this._y /= Value;
        }

        return this;
    };

    this.AddVec = function(Vector) { this._x += Vector._x; this._y += Vector._y; return this; };
    this.SubVec = function(Vector) { this._x -= Vector._x; this._y -= Vector._y; return this; };
    this.MulVec = function(Vector) { this._x *= Vector._x; this._y *= Vector._y; return this; };
    this.DivVec = function(Vector)
    {
        if (Vector._x && Vector._y)
        {
            this._x /= Vector._x;
            this._y /= Vector._y;
        }

        return this;
    };

    this.Length = function() { return Math.sqrt(Math.pow(this._x, 2) + Math.pow(this._y, 2)); };
}


///-class-/////////////////////////////////////////////////////////////////////
// Fader
///////////////////////////////////////////////////////////////////////////////
function Fader(ID)
{
    ///-data-//////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////

    this._ID = ID;
    this._interval = '';
    this._opacity = 1.0;
    this._decrement = 0.02;
    this._items = new Array();
    this._itemIndex = 0;
    this._element0 = null;
    this._element1 = null;
    this._delay = 100;


    ///-methods-///////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////

    this.GetElements = function()
    {
        if (!this._element0 || !this._element1)
        {
            var index = this._itemIndex + 1;
            if (index >= this._items.length)
                index = 0;

            this._element0 = wGet(this._items[this._itemIndex]);
            this._element1 = wGet(this._items[index]);
        }

        return this._element0 && this._element1;
    };

    this.SetItemOpacity = function(Item, Value)
    {
        if (MSIEVersion > 5.5 && window.document.body.filters)
            Item.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + Math.round(Value * 100) + ')';
        else
        {
            Item.style.opacity = Value;
            Item.style.MozOpacity = Value;
        }
    };

    this.SetOpacity = function()
    {
        if (this.GetElements())
        {
            this.SetItemOpacity(this._element0, this._opacity);
            this.SetItemOpacity(this._element1, (1.0 - this._opacity));
        }
    };

    this.SetZIndex = function()
    {
        for (var count = 0; count < this._items.length; ++count)
            if (wGet(this._items[count]))
            {
                if (count == this._itemIndex)
                    wGet(this._items[count]).style.zIndex = 2;
                else
                    wGet(this._items[count]).style.zIndex = 1;
            }
    };

    this.AddItem = function(ID)
    {
        this._items[this._items.length] = ID;
    };

    this.Animate = function()
    {
        if (this._interval != '')
        {
            if (this._delay)
            {
                --this._delay;
            }
            else
            {
                this._opacity -= this._decrement;

                if (this._opacity < 0.0)
                {
                    this._opacity = 1.0;

                    ++this._itemIndex;
                    if (this._itemIndex >= this._items.length)
                        this._itemIndex = 0;

                    this._element0 = null;
                    this._element1 = null;

                    this._delay = 100;

                    this.SetZIndex();
                }

                this.SetOpacity();
            }
        }
    };

    this.Start = function()
    {
        for (var count = 0; count < this._items.length; ++count)
        {
            var itemNext = wGet(this._items[count]);

            this.SetItemOpacity(itemNext, 0);

            if (itemNext)
                itemNext.style.visibility = 'visible';
        }

        this.SetOpacity();
        this.SetZIndex();

        if (this._interval == '')
            this._interval = setInterval(this._ID + '.Animate()', 50);
    };

    this.Stop = function()
    {
        if (this._interval != '')
            clearInterval(this._interval);

        this._interval = '';
    };


    this.ClickItem = function(Index)
    {
        this.Stop();

        if (this.GetElements())
        {
            this.SetItemOpacity(this._element0, 0.0);
            this.SetItemOpacity(this._element1, 0.0);
        }

        this._element0 = null;
        this._element1 = null;

        this._itemIndex = Index;
        this.GetElements();

        this._delay = 100;
        this._opacity = 1.0;

        this.SetOpacity();
        this.SetZIndex();

        this.Start();
    };
}


///-class-/////////////////////////////////////////////////////////////////////
// TickerHeadline
///////////////////////////////////////////////////////////////////////////////
function TickerHeadline(Headline, HREF)
{
    this._headline = Headline;
    this._href = HREF;
}


///-class-/////////////////////////////////////////////////////////////////////
// Ticker
///////////////////////////////////////////////////////////////////////////////
function Ticker(ID, LayerID)
{
    ///-data-//////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////

    this._ID = ID;
    this._layerID = LayerID;
    this._layer = null;
    this._interval = '';
    this._headlines = new Array();
    this._headlineIndex = 0;
    this._headlinePosition = -1;
    this._delay = 0;


    ///-methods-///////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////

    this.GetLayer = function()
    {
        if (!this._layer)
            this._layer = wGet(this._layerID);

        return this._layer;
    };

    this.AddHeadline = function(Headline, HREF)
    {
        this._headlines[this._headlines.length] = new TickerHeadline(Headline, HREF);
    };

    this.Animate = function()
    {
        if (this._delay)
        {
            --this._delay;
        }
        else if (this.GetLayer())
        {
            if (this._headlinePosition >= this._headlines[this._headlineIndex]._headline.length)
            {
                ++this._headlineIndex;

                if (this._headlineIndex >= this._headlines.length)
                    this._headlineIndex = 0;

                this._headlinePosition = -1;
                this._delay = 50;
            }
            else
            {
                if (this._headlinePosition == -1)
                {
                    this._layer.innerHTML = '<a href="' + this._headlines[this._headlineIndex]._href + '" class="contentHighlighted link"><span id="' + this._layerID + 'Headline"></span></a>\n';
                    this._headlinePosition = 0;
                }
                else if (wGet(this._layerID + 'Headline'))
                {
                    wGet(this._layerID + 'Headline').innerHTML += this._headlines[this._headlineIndex]._headline.substr(this._headlinePosition, 1);
                    ++this._headlinePosition;
                }
            }
        }
    };

    this.Start = function()
    {
        if (this._interval == '')
            this._interval = setInterval(this._ID + '.Animate()', 50);
    };

    this.Stop = function()
    {
        if (this._interval != '')
            clearInterval(this._interval);

        this._interval = '';
    };
}
