/*
 * window.history.back does not restore the document
 * @fix Remove app.js or fix it with a diff. approach
 *
jQuery(document).ready(function(){
    var doc    = jQuery(document);
    var body   = jQuery('body');
    var button = jQuery('#diashow');
    var fader  = jQuery('<div id="fader"><h3>Diashow wird geladen...</h3></div>');
    
    function showDiashow()
    {
        jQuery(window).unload(removeFader);
        document.location.href = button.attr('href');
    }
    function removeFader()
    {
        fader.remove();
    }
    function animateDiashowButton() {
        fader.css({'height':doc.height(), 'width':doc.width()});
        fader.appendTo(body);
        fader.fadeIn(500, showDiashow);
        return false;
    }
    button.click(animateDiashowButton);
});
*/
var app = {
    domain : 'www.wand-farbe-kunst.de'
};
app.lib = {
    array : {
        walk : function(arr, cb, data) {
            for (var i = arr.length; --i >= 0;) {
                if (false === cb(arr[i], i, data)) {
                    return false;
                }
            }
            return true;
        },
        map : function(arr, cb, data) {
            var result = [];
            for (var i = arr.length; --i >= 0;) {
                result.unshift(cb(arr[i], i, data));
            }
            return result;
        },
        filter : function(arr, cb, data) {
            var result = [];
            for (var i = arr.length; --i >= 0;) {
                if (false !== cb(arr[i], i, data)) {
                    result.unshift(arr[i]);
                }
            }
            return result;
        },
        unique : function(arr) {
            var result = [];
            var hash   = {};
            var key, value;
            for (key in arr) {
                value = arr[key];
                key = value.toString();
                if (hash[key]) {
                    continue;
                }
                hash[key] = result.push(value);
            }
            return result;
        }
    }
}

function AccessKeysToTitle() {
    function appendAccesskey(a) {
        var accesskey = a.getAttribute('accesskey') || '';
        if(accesskey.length) {
            var title = a.getAttribute('title') || '';
            if (title.length) {
                title = title.replace(/\s+\[.\]$/, '');
            }
            a.setAttribute('title', title.concat(' [' + accesskey + ']'));
        }
    }
    app.lib.arr.walk(document.getElementsByTagName('A'), appendAccesskey);
}

function AccesskeyTitleShow()
{
    
}
function FrontEditFrame(edit)
{
    var frontEdit = edit.parent();
    var animate = jQuery('<div/>');
    animate.css({
        'display':'none',
        'width':frontEdit.width() + 'px',
        'height':frontEdit.height() + 'px',
        'position':'absolute',
        'border':'1px dotted red'
    });
    animate.addClass('frontedit-frame');
    frontEdit.prepend(animate);
    animate.show(250);
}

function FrontEditShow(e)
{
    var edit = jQuery('div.frontedit-rel', this);
    var cont = edit.next();
    edit.css({
        'left' : cont.position().left || e.clientX || 'inherit',
        'position':'absolute'
    });
    FrontEditFrame(edit.show());
}
function FrontEditHide(e)
{
    var edit = jQuery('div.frontedit-rel', this);
    var frame = edit.siblings('div.frontedit-frame');
    frame.hide(250, function(){frame.remove()});
    edit.hide();
}
jQuery(document).ready(function(){
    jQuery('div.frontedit').hover(FrontEditShow, FrontEditHide);
});
