// JavaScript Document

$(document).ready(function() {
   
    $(".entry img").each(function() {
        
        if ($(this).hasClass("gallery-img"))
            return;
        
        $.src = $(this).attr('src');
        $(this).attr('src','http://peasfoundation.org/wp-content/themes/peas/images/bg_img.jpg');
        
        $.widthRatio = 0.95593220338983050847457627118644;
        $.heightRatio = 0.9073569482288828337874659400545;
        
        $.origWidth = parseInt($(this).css('width'));
        $.origHeight = parseInt($(this).css('height'));
        $.width = $.origWidth;
        $.height = $.origHeight;
        $.width = Math.floor($.width / $.widthRatio);
        $.height = Math.floor($.height / $.heightRatio);
        
        $.marginTop = 0;
        $.marginRight = 0;
        $.marginBottom = 0;
        $.marginLeft = 0;
        
        $.marginLeft = Math.round(($.width - $.origWidth) / 2);
        $.marginTop = Math.round(($.height - $.origHeight) / 2);
        
        $(this).css('width',$.width);
        $(this).css('height',$.height);
        
        if ($(this).hasClass('alignleft')) {
            $.class = 'alignleft';
            $.styles = '';
            $.marginTop = $.marginTop + 15;
        } else if ($(this).hasClass('aligncenter')) {
            $.class = 'aligncenter';
            $.styles = 'left: 50%;';
            $.marginLeft = (Math.round($.width / 2) * (-1)) + $.marginLeft;
        } else if ($(this).hasClass('alignright')) {
            $.class = 'alignright';
            $.marginTop = $.marginTop + 15;
            $.marginLeft = $.marginLeft - $.width;
        }
        
        $.img = '<img src="' + $.src + '" alt="" style="position: absolute; margin: ' + $.marginTop + 'px ' + $.marginRight + 'px ' + $.marginBottom + 'px ' + $.marginLeft + 'px;' + $.styles + '" />';
        $(this).before('<div class="' + $.class + '" style="position: relative;">' + $.img + '</div>');
    });
     
});

