///-codeFile-//////////////////////////////////////////////////////////////////
// Support.js
//
// Written by Doug Greenall (douggreenall.co.uk)
// Copyright (c) 2008 Doug Greenall
//
// Feel free to use this code in any of your own personal projects but please
// leave this notice and my details intact. This code may not be used for any
// commercial projects without explicit permission
///////////////////////////////////////////////////////////////////////////////


///-function-//////////////////////////////////////////////////////////////////
// wGet
///////////////////////////////////////////////////////////////////////////////
function wGet(ID) { return window.document.getElementById(ID); }


///-class-/////////////////////////////////////////////////////////////////////
// Vector2D
///////////////////////////////////////////////////////////////////////////////
function Vector2D(X, Y)
{
    ///-data-//////////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////

    this._x = X;
    this._y = Y;


    ///-arithmetic-////////////////////////////////////////////////////////////
    ///////////////////////////////////////////////////////////////////////////

    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;
    };


    ///-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'; };
}

///-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 = 'images/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);
}

