$(function() {
//    $("ul#nav").superfish({
//        'hoverClass': 'sfHover'
//    });
//    $("ul#nav li a.selected").parent().addClass("selected");
    $("ul.sectors li").hoverPod();
    $(".aside .image").hoverPod();
    $(".cms").lockDown();
    $(".cms .imageContainer").imagefit();
    $(".wideList div a").imagefit();
    $(".wideList div a").centreImages();
    $(document).externalLink();
    $("ul#productListings").equalHeights({
        "elementToApply": "h3"
    });
    $("ul#productListings").equalHeights({
        "elementToApply": "p"
    });
    $("ul.searchresultpods").equalHeights({
        "elementToApply": "h6"
    })
});
$.fn.equalHeights = function(options) {
    var defaults = {
        'elementToApply': 'h3'
    },
        options = $.extend(defaults, options);
    $(this).each(function() {
        var currentTallest = 0;
        $(this).children().find(options.elementToApply).each(function(i) {
            if ($(this).height() > currentTallest) {
                currentTallest = $(this).height()
            }
        });
        if ($.browser.msie && $.browser.version == 6.0) {
            $(this).children().find(options.elementToApply).css({
                'height': currentTallest
            })
        }
        $(this).children().find(options.elementToApply).css({
            'min-height': currentTallest
        })
    });
    return this
};
(function($) {
    $.fn.imagefit = function(options) {
        if ($(this).parent().attr('expand') == true) {
            alert('got here');
            var fit = {
                all: function(imgs) {
                    imgs.each(function() {
                        fit.one(this)
                    })
                },
                one: function(img) {
                    $(img).width('100%').each(function() {
                        $(this).height(Math.round($(this).attr('startheight') * ($(this).width() / $(this).attr('startwidth'))))
                    })
                }
            }
        };
        this.each(function() {
            if ($(this).parent().attr('expand') == true) {
                alert('got here2');
                var container = this;
                var imgs = $('img', container).not($("table img"));
                imgs.each(function() {
                    $(this).attr('startwidth', $(this).width()).attr('startheight', $(this).height()).css('max-width', $(this).attr('startwidth') + "px");
                    fit.one(this)
                });
                $(window).bind('resize', function() {
                    fit.all(imgs)
                })
            }
        });
        return this
    }
})(jQuery);
(function($) {
    $.fn.centreImages = function(options) {
        return this.each(function() {
            var $$ = $(this);
            var imgs = $("img", $$);
            imgs.each(function() {
                $(this).css({
                    'top': ((parseInt($$.height()) / 2) - (parseInt($(this).height()) / 2)),
                    'position': 'absolute'
                })
            })
        })
    }
})(jQuery);
