window.addEvent('domready', function(){
    
    $$('a[rel=submit]').addEvent('click', function(e){
        if (e) e.preventDefault();
        if (!this.hasClass('delete') || confirm('Are you sure?')) {
            this.getParent('form').submit();
        }
    });
    
    $$('a[rel=_blank]').removeEvents('click').addEvent('click', function(e){
        if (e) e.preventDefault();
        window.open(this.getProperty('href'));
    });
    
    if ($('backtotop')) {
        $('backtotop').addEvent('click', function(e){
            if (e) e.preventDefault();
            new Fx.Scroll(document.body).start(0, 0);
        });
    }
    
});

function spawnOverlay(onCompleteFunc)
{
    new Element('div', {
        id: 'overlay',
        styles:{
            'width'  : window.getScrollSize().x,
            'height' : window.getScrollSize().y,
            'opacity': 0
        }
    }).inject(document.body);
    
    new Fx.Tween($('overlay'), {
        duration: 500,
        onComplete: onCompleteFunc
        
    }).start('opacity', 0.7);
}

function killOverlay()
{
    if ($('overlay')) {
        new Fx.Tween($('overlay'), {
            duration: 500,
            onComplete: function(){
                if ($('overlay')) $('overlay').destroy();
            }
        }).start('opacity', 0);
    }
}

function injectLoader(target)
{
    new Element('img', {
        src: base + 'pinnacle/assets/img/ajaxload.gif',
        width: 16,
        height: 11,
        alt: 'Loading…'
    }).inject(target);
}

