﻿/* 4-9-2009 */

// optimize IE for images
if( Browser.Engine.trident ) try {document.execCommand("BackgroundImageCache", false, true);} catch( e ) { };

var Void=function(){};if(!console){var console={log:Void}};

window.addEvent('load', MKQ.Load );
window.addEvent('domready', MKQ.Init );

var exhibitViewer = { 
    writeExhibitById: function() {
        console.log( 'warning!!! old exhibit viewer');
    }
}


Element.implement({
    findParent: function(className) {
        var rollbackEle = this;
        while (rollbackEle != null && rollbackEle != document && !rollbackEle.hasClass(className)) {
            rollbackEle = rollbackEle.getParent();
        };
        return rollbackEle;
    },
    'VoidLink': function() {
        this.setAttribute('href', Settings.VOID_LINK);
        return this;
    },
    Hide: function() {
        this.addClass('hidden');
        return this;
    },
    Show: function() {
        this.removeClass('hidden');
        return this;
    },
    IsHidden: function() {
        return this.hasClass('hidden');
    },
    getRealSize: function(flag) {
        var theSize = this.getSize();
        if (theSize.x == 0 || theSize.y == 0 && this.IsHidden()) {
            if (flag) {
                this.getParent().Show();
                theSize = this.getSize();
                this.getParent().Hide();
            } else {
                this.Show();
                theSize = this.getSize();
                this.Hide();
            }
        }
        return theSize;
    }
});

function addCommas(nStr) {
    nStr += '';
    x = nStr.split('.');
    x1 = x[0];
    x2 = x.length > 1 ? '.' + x[1] : '';
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x1)) {
        x1 = x1.replace(rgx, '$1' + ',' + '$2');
    }
    return x1 + x2;
}
