/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * header.js
 *
 * Initialization script
 *
 * LICENSE: This source file is subject to version 1.0 of the OpenFlyers
 * license that is available through the world-wide-web at the following
 * URI: http://www.openflyers.com/license/semifreelicense1_0.txt. If you did not receive a
 * copy of the OpenFlyers License and are unable to obtain it through the
 * web, please send a note to contact@openflyers.com so we can mail you
 * a copy immediately.
 *
 * @category    Javascript
 * @package     OpenFlyers
 * @author      Stéphane Goossens
 * @copyright   2008 OPENFLYERS S.A.R.L. <contact@openflyers.com>
 * @license     http://www.openflyers.com/license/semifreelicense1_0.txt  OpenFlyers License
 * @link        http://www.openflyers.com
 * @since       Thu Jan 09 2014
 */

/**
 * calculateHeaderSize
 * 
 * @return void
 */
function calculateHeaderSize() {
    // When header has advertisement, the CSS is used but when header has not advertisement, header size must be calculated
    if (!hasAdvertisement) {
        var header         = document.getElementById('headerContainer');
        var headerHeight   = 110;
        var titleHeight    = 20;
        var marginLogos    = 20;
        // Get logos height
        var logos       = document.getElementById('logos');
        var logosHeight = marginLogos;
        for ( var i = 0; i < logos.children.length; i++) {
            var element  = logos.children[i];
            logosHeight += element.offsetHeight;
        }
        // Set header height
        headerHeight        = headerHeight > logosHeight ? headerHeight : logosHeight;
        header.style.height = headerHeight + 'px';
        for ( var i = 0; i < header.children.length; i++) {
            var element  = header.children[i];
            if (element.className !== 'lightSpacer') {
                element.style.height = headerHeight + 'px';
            }
        }
        // Web feed
        var webFeed          = document.getElementById('webFeed');
        var externalWebFeed  = document.getElementById('externalWebFeed');
        var paddingWebFeed = externalWebFeed != null ? 5 : 0;
        var webFeedHeight    = (externalWebFeed != null ? headerHeight / 2 : headerHeight) - titleHeight - paddingWebFeed;
        webFeed.style.height = webFeedHeight + 'px';
        if (externalWebFeed) {
            externalWebFeed.children[0].children[1].style.height = webFeedHeight + 'px';
        }
        // Weather
        var weather = document.getElementById('weatherBox');
        weather.style.height = (headerHeight - titleHeight) + 'px';
    }
}

YAHOO.util.Event.onDOMReady(calculateHeaderSize);