﻿//************************************************************************************* 
// File     :   aram_recentarticle_equalize.js
// Version  :   1.1.0.1
// Requires :   mf_domLibrary_0.1.js, prototype.js
// Author   :   Kyle Weems (ksw)
// Origin   :   mindfly.com
// Created  :   August 15, 2007
// Modified :   September 18, 2007 (ksw)
// Purpose  :   Equalizes heights of Recent Articles list to prevent boxes from 'popping'
//              down out of their orderly rows.       
//*************************************************************************************

// Version History (only for changes of at least 0.0.1 in version number)
// ===============
// Version 1.0   (08/15/2007) - Basic functionality. 
// Version 1.1   (09/06/2007) - Brought function up to date in referring to the right ID for the list items. Fixed functionality by having it also resize the div inside the LI to ensure it wraps around the text. Added onresizeevent call as well.


//=============================================================================================
// equalizeRecentArticles()
//=============================================================================================
// Checks the heights of all list items named 'liSecondaryItem' on the Articles/Gallery list pages,
// and resizes them to the height of the tallest LI. Performs a similiar resizing to the DIV inside of the 
// list item. This is needed to prevent visual distortion to the Recent Articles/Galleries lists caused when
// unevenly sized boxes 'pop out' of the row.
function equalizeRecentArticles()
{
    // Create a variable to store the height of the tallest list item.
    var tallest = 0;
    // Get arrays of liSecondaryItem and divLiSecondaryItem
    var articleList = document.getElementsByClassName('liSecondaryItem');
    var articleDiv  = document.getElementsByClassName('divLiSecondaryItem');
    // If there is at least one list item, then...
    if(articleList.length)
    {
        // ... loop through all the list items. For each item... 
        for(i=0;i<articleList.length;i++)
        {
            // remove any existing heights associated with the LI and div inside it.
            articleList[i].style.height = '';
            articleDiv[i].style.height  = '';
            // Check if the current list item is taller than the tallest one so far. If so, save that value.
            if(articleList[i].offsetHeight > tallest)
            {
                tallest = articleList[i].offsetHeight;
            }
        } // end of for(i=0;i<articleList.length) loop
        // Loop again through the list.
        for(i=0;i<articleList.length;i++)
        {
            if(articleList[i].offsetHeight < tallest)
            {
                // For each list item, assign it's height to equal the tallest list item.
                articleList[i].style.height = tallest + 'px';
                // Resize the divs as well (but a bit shorter to allow spacing).
                articleDiv[i].style.height  = ((tallest*1)-22) + 'px';
            }
        } // end of for(i=0;i<articleList.length) loop
    } // end of if(articleList.length)
} // end of function equalizeRecentArticles()


// When the page loads, run the equalizeRecentArticles() function.
addLoadEvent(equalizeRecentArticles);
// When the window is resized, run the equalizeRecentArticles() function.
addOnresizeEvent(equalizeRecentArticles);

