(function($) {

    // Render New Column Heights when page loads
    $(window).load(function() {
        $('*').ReWriteSectionHeight();
    });

    // Find Longest AgeTab Column
    // Add difference to other columns via padding-top
	$.fn.ReWriteAgeTabColHeight = function () {
		var subImages = $('.PL_AgeSubImage');
		var subImageOffsetArray = [];
		subImages.each(function() {
			subImageOffsetArray.push($(this).offset().top);
		});
		var greatestOffset = subImageOffsetArray[0];
		var smallestOffset = subImageOffsetArray[0];
		subImages.each(function(i) {
			if (subImageOffsetArray[i] > greatestOffset) {
				greatestOffset = subImageOffsetArray[i];
			}else if (subImageOffsetArray[i] <= smallestOffset) {
				smallestOffset = subImageOffsetArray[i];
			}
		});
		var offsetDiff = greatestOffset - smallestOffset;
		$(subImages).each(function() {
			//console.log('diff: ' + offsetDiff + '\nCurrOffset: ' + $(this).offset().top);
			if ($(this).offset().top !== greatestOffset) {
				$(this).css('paddingTop', offsetDiff + 'px');
			}
		});
	};

    // Find Longest Section
    // Add difference to shorter extension via height
    $.fn.ReWriteSectionHeight = function() {
        var KidsProducts = $('div[id^="PL_KidsProducts"]').height();
        var Featured = $('div[id^="PL_FeaturedOffers"]').height();
        var SectionDiff = 0;
        if (KidsProducts >= Featured) {
            SectionDiff = KidsProducts - Featured;
			//console.log('Kids\n KidsProducts: ' + KidsProducts + '\nFeatured: ' + Featured + '\nSectionDiff: ' + SectionDiff);
            $('#FeaturedOffers_Extension').css('height', SectionDiff);
        } else if (Featured >= KidsProducts) {
            SectionDiff = Featured - KidsProducts;
			//console.log('Featured\n KidsProducts: ' + KidsProducts + '\nFeatured: ' + Featured + '\nSectionDiff: ' + SectionDiff);
            $('#KidsProducts_Extension').css('height', SectionDiff);
        }
		$('*').ReWriteAgeTabColHeight();
    };

}) (jQuery);
