$(document).ready(function() {
    setTimeout('imageSubstitutor()',500);
}); 

function imageSubstitutor() {
    $('.imgSubstitutor').each(function(){
        var aId = $(this).attr('id');
        var aElementType = $(this).attr('tagName').toLowerCase();
        
        if(aId) {
            if(images[aId]) {
                var aImgSrc = images[aId];    
            } else {
                var aImgSrc = '/noimage.jpg';                
            }
            switch(aElementType) {
                case 'a':
                    $(this).css('background-image','url(' + aImgSrc + ')');
                break;
                case 'div':
                    $(this).css('background-image','url(' + aImgSrc + ')');
                break;
                case 'img':
                    $(this).attr('src',aImgSrc);
                break;
            }
            
            if(admin == 1) {
                var p = $(this);
                var position = p.position();
                var aW = $("#" + aId).width();
                var aH = $("#" + aId).height();
                var aHref = '/update:ImageSubstitutor:getSubstitutionInterface/id:' + aId + ':w:' + aW + ':h:' + aH;
                $("body").append('<a class="imageSubstitutor" id="substitutor_' + aId + '" href="' + aHref + '" style="top: ' + position.top + 'px; left: ' + position.left + 'px;" forElement="' + aId + '">+</a>');
                
                $('#substitutor_' + aId).fancybox({
                    'width'                : '70%',
                    'height'            : '40%',
                    'autoScale'            : false,
                    'transitionIn'        : 'elastic',
                    'transitionOut'        : 'elastic',
                    'type'                : 'iframe'
                });  
            }            
        }
    });    
}
    






