//------------------------------------------------------------------------------
//  WAX 1.5 - general-purpose web application library
//  Copyright (C) 2000-2006 SnapWorks
//  Website : http://www.snap-works.com/
//  Email   : info@snap-works.com
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//  Browser detection
//------------------------------------------------------------------------------

var Browsers = {
    Other   : 0,
    Gecko   : 1,
    MSIE    : 2,
    Opera   : 3
}

var browser = Browsers.Other;
    
if (window.opera) {
    browser = Browsers.Opera;
} else if (navigator.userAgent.match(/Gecko/)) {
    browser = Browsers.Gecko;
} else if(window.clipboardData) {
    browser = Browsers.MSIE;
}

//------------------------------------------------------------------------------
//  void ExtendClass(Object superClass, Object baseClass)
//------------------------------------------------------------------------------
function ExtendClass(superClass, baseClass) // {{{
{
    function inheritance() {}
    inheritance.prototype = baseClass.prototype;
    superClass.prototype = new inheritance();
    superClass.prototype.constructor = superClass;
} // }}}

//------------------------------------------------------------------------------
//  DomNode $(id)
//  Return dom node by id.  
//------------------------------------------------------------------------------
function $(id)
{
    return document.getElementById(id);
}

//------------------------------------------------------------------------------
//  void applyAlpha(DomNode node, int alpha)
//  Apply alpha to given node.  
//------------------------------------------------------------------------------
function applyAlpha(node, alpha)
{
    alpha = Math.round(alpha);
    
	
    if (null != node.style.opacity) {
        node.style.opacity = alpha / 255;
    } else if (null != node.filters) {
        node.style.filter = 'alpha(opacity='+alpha * (100/255)+')';
    } else if (null != node.style.MozOpacity) {
        node.style.MozOpacity = alpha / 255;
    } else if (null != node.style.KhtmlOpacity) {
        node.style.KhtmlOpacity = alpha / 255;
    }
}

//------------------------------------------------------------------------------
//  DomNode createCenteredElement(DomNode parent, int width, int height)
//  Create horizontally and vertically centered box inside parent of given size
//  and returns its inner container.
//------------------------------------------------------------------------------
function createCenteredElement(parent, width, height)
{
    document.createElement('div');
    
    var container1 = document.createElement('div');
    var container2 = document.createElement('div');
    
    container1.style.position = 'absolute';
    container1.style.left = '50%';
    container1.style.top = '50%';
    
    container2.style.position = 'absolute';
    container2.style.left = Math.round(-width/2) + 'px';
    container2.style.top = Math.round(-height/2) + 'px';
    container2.style.width = (width) + 'px';
    container2.style.height = (height) + 'px';
    
    container1.appendChild(container2);
    parent.appendChild(container1);
    return container2;
}
