/*
 * Class for working with windows. Popups and other nefarious things
*/
Aardvark.Windows = Class.create();
Aardvark.Windows.prototype = Object.extend(new Aardvark(), {
    initialize: function()
    {
        this.newWindow = ''
    },

    open: function(url, name, options)
    {
        // Create a hash from the options string
        options = $H(options)

        // Holds the string
        var parameters = ''

        // Turn the hash into a string
        options.each(function(option) {
            // Add a comma but not to the begining
            parameters += parameters == '' ? '' : ','
            // Add the key value pair
            parameters += option.key + '=' + option.value
        })

        if (!this.isOpen())
        {
            // Create a new window
            this.newWindow = window.open(url, name, parameters)
        }
        else
        {
            this.newWindow.location.href = url
        }

        if (window.focus)
        {
            this.newWindow.focus()
        }
    },

    setFocus: function(windowObject)
    {
        if (window.focus)
        {
            windowObject.focus()

            return true
        }
        else
        {
            return false
        }
    },

    changeParentLocation: function(location)
    {
        if (!opener.closed)
        {
            opener.location.href = location

            return true
        }
        else
        {
            return false
        }
    },

    isOpen: function()
    {
        if (!this.newWindow.closed && this.newWindow.location)
        {
            return true
        }
        else
        {
            return false
        }
    },

    getDimensions: function()
    {
        if (self.innerWidth)
        {
            return {
                width: self.innerWidth,
                height: self.innerHeight
            }
        }
        else if (document.documentElement && document.documentElement.clientWidth)
        {
            return {
                width: document.documentElement.clientWidth,
                height: document.documentElement.clientHeight
            }
        }
        else if (document.body)
        {
            return {
                width: document.body.clientWidth,
                height: document.body.clientHeight
            }
        }
    }
})