
var DomLoaded = {
    load: jQuery(document).ready
};


jQuery(document).ready(function($) {

    // fix for IE background images flicker bug from http://www.mister-pixel.com/
    try {
        document.execCommand("BackgroundImageCache", false, true);
    } catch(err) {}
    
    // remove non-js links
    $('.noJS').remove();

    // menu
    colorcells = [];
    hovercells = [];
    tids = []; // timeout ids
    curr = -1; // current menu
    
    colorLayerItems = $('#colorlayer > *');

    $('#hoverlayer > *').each(function(idx, val) {
        
        colorcells.push(colorLayerItems[idx]);
        hovercells.push(val);

        $(val).mouseenter(function() {
            try {
                if ((curr != -1) && (curr != idx)) {
                    $(colorcells[curr]).css('background', 'red');
                    $(hovercells[curr]).children().first().css('visibility', 'hidden');
                }
                curr = idx;
                if (tids[idx]) clearTimeout(tids[idx]);
                $(colorcells[idx]).css('background', 'white');
                $(val).children().first().css('visibility', 'visible');
            } catch(err) {} 
        });

        $(val).mouseleave(function() {
            try {
                tids[idx] = setTimeout(function() {
                    $(colorcells[idx]).css('background', 'red');
                    $(val).children().first().css('visibility', 'hidden');
                }, 250);
            } catch(err) {} 
        });
    });

    // footer menu
    $('#footer-hoverlayer > *').each(function(idx, element) {
        $(element).mouseenter(function(e) {
            idx = $.inArray(this, $(this).parent().children());
            $('#footer-colorlayer > *')[idx].style.background = 'white';
        });
        $(element).mouseleave(function(e) {
            idx = $.inArray(this, $(this).parent().children());
            $('#footer-colorlayer > *')[idx].style.background = 'red';
        });
    });

    // input fields...
    $('input.hasdefault').each(function(idx, val) {
        $(val).focus(function() {
            if (val.value == val.defaultValue) val.value = "";
        });
        $(val).blur(function() {
            if (val.value == "") val.value = val.defaultValue;
        });
    });

    // textile new window links
    $('.textile a').each(function(idx, element) {
        if (element.title != 'out') return;
        element.title = "";
        element.target = "_blank";
    });

    $('a.targetblank').each(function(idx, element) {
        element.target = "_blank";
    });
    
    window.initLightbox && initLightbox();
});



window.wopen = false;

function magnify(href, width, height) {
    ie6 = /msie 6/i.test(navigator.userAgent);
    if (ie6 ? window.wopen : (window.wopen && w.onload)) w.close();
    
    width = width || 620;
    height = height || 600;
    w = window.open(href, '', 'scrollbars=yes,resizable=yes,menu=no,width='+width+',height='+height);
    //w.moveTo(100, 240);
    w.orig = window;
    window.wopen = true;
    return false;
}

