
var CFPRW = CFPRW || {};

CFPRW.ResizeHandler = function() {
    var resizeTimeoutId,
        counter = 0,
        normalSize = true;

    return {
        windowResize: function(e) {
            counter++;
            window.clearTimeout(resizeTimeoutId);
            resizeTimeoutId = window.setTimeout('CFPRW.ResizeHandler.onResize();', 100);
        },
        onResize: function() {
            if($(document).width() < 960 && normalSize) {
                normalSize=false;
                $('cufon canvas').each(function() {
                    $(this).height($(this).height()*0.8);
                    $(this).width($(this).width()*0.8);
                });
                $('cufon').each(function() {
                    $(this).width($(this).width()*0.8);
                    $(this).height($(this).height()*0.8);
                });
            }
        }
    };
}();

// WP always sets width and height, remove these for big images, set width 100%
CFPRW.adjustSinglePostImages = function() {
    $('.subpage_post .entry img').each(function(index) {
        var parent = null;
        if($(this).width()>400) {
            $(this).removeAttr('width');
            $(this).css('width', '100%');
            $(this).removeAttr('height');
            parent = $(this).parent();
            if(parent.hasClass('wp-caption')) {
                parent.css('width','100%');
            }
        }
    });
};

$(document).ready(function() {
    $('#cfp-nav-select option:first-child').after('<option value="-10">Home</option>');
    $('#cfp-nav-select').change(function() {
        switch($(this).val()) {
            case -1:
                return;
                break;
            case -10:
                window.location="/";
                break;
            default:
                $("#cfp-nav-form").submit();
        }
    });
    $('#search-404-submit').click(function() {
        $('#s').val($('#search-404').val());
        $('#searchform').submit();
    });

    CFPRW.adjustSinglePostImages();
});

