/**
 * Třída obsahující řadu obecných funkcí.
 */
var Utils = new function() {
    /**
     * Vrátí šířku okna prohlížeče. Počítá i s posunutým scrollbarem.
     *
     * @return pole [šířka, výška]
     */
    this.getScrolledWindowDimensions = function() {
        var left = 0,
            top = 0,
            screen = this.getWindowDimensions();

        // Netscape compliant
        if (typeof window.pageXOffset === 'number') {
            left = window.pageXOffset;
            top = window.pageYOffset;
        }
        // DOM compliant
        else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
            left = document.body.scrollLeft;
            top = document.body.scrollTop;
        }
        // IE6 standards compliant mode
        else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
            left = document.documentElement.scrollLeft;
            top = document.documentElement.scrollTop;
        }
        return [ (screen.width / 2) + left, (screen.height / 2) + top ];
    };

    /**
     * Vrátí šířku a výšku okna prohlížeče.
     *
     * @return objekt s atributy width a height
     */
    this.getWindowDimensions = function() {
        var width = 0,
        height = 0;

        // IE
        if(!window.innerWidth) {
            // strict mode
            if(document.documentElement.clientWidth !== 0) {
                width = document.documentElement.clientWidth;
                height = document.documentElement.clientHeight;
            }
            // quirks mode
            else {
                width = document.body.clientWidth;
                height = document.body.clientHeight;
            }
        }
        // Opera
        else if (window.opera) {
            width = document.documentElement.clientWidth;
            height = document.documentElement.clientHeight;
        }
        // other browsers
        else {
            width = window.innerWidth;
            height = window.innerHeight;
        }
        return {width:width, height:height};
    };

    /**
     * Vrátí třídu HTML elementu, která začíná daným prefixem.
     *
     * @return String
     */
    this.getHtmlClass = function(classStr, prefix) {
        var classes = classStr.split(' ');
        for (var i = 0; i < classes.length; i++) {
            if (classes[i].indexOf(prefix) === 0) {
                return classes[i];
            }
        }
        return '';
    }
}();

if (typeof String.trim === 'undefined') {

    /**
     * Odstraní whitespace znaky ze začátku a konce řetězce.
     */
    String.prototype.trim = function() {
        return this.replace(/^\s+|\s+$/g, '');
    };
}

/**
 * Zjistí, zda jsou dvě pole identické.
 */
Array.prototype.compare = function(testArr) {
    if (this.length != testArr.length) return false;
    for (var i = 0; i < testArr.length; i++) {
        if (this[i].compare) {
            if (!this[i].compare(testArr[i])) return false;
        }
        if (this[i] !== testArr[i]) return false;
    }
    return true;
}
