﻿var $ = WDN.jQuery;

function cmdPanel() {
    if ($('#aSearch').html() == 'search [+]') {
        $('#panelSearch').removeClass('pClosed').addClass('pOpened');
        $('#aSearch').html('search [-]');
    } else {
        $('#panelSearch').removeClass('pOpened').addClass('pClosed');
        $('#aSearch').html('search [+]');
    }

}



var exText = "<small>[+]</small>";//"expand <small>[+]</small>";
var clText = "<small>[-]</small>";//"collapse <small>[-]</small>";

function setMessageHeight() {
    var posts = $('div .blogEntryBody').get();
    var mHeight;
    var sHeight;
    var divLB;
    for (var i = 0; i < posts.length; i++) {
        mHeight = posts[i].offsetHeight;
        sHeight = posts[i].scrollHeight;
        //$('#console').append('<div>mHeight[' + mHeight + '] ___ sHeight[' + sHeight + ']</div>');
        if (sHeight > mHeight) {
            divLB = document.getElementById("bejs" + posts[i].id.substring(13));
            divLB.style.borderTop = "1px solid #E3E3E3";
            var a = document.createElement("a");
            a.innerHTML = exText; //"expand <small>[+]</small>";
            a.id = "messageExpandID" + posts[i].id.substring(13);
            a.className = "expandBlogAnchor";
            a.title = "Expand/Collapse"
            a.onclick = expandMessage(posts[i].id.substring(13));
            divLB.appendChild(a);
        }
    }
}

function expandMessage(id) {
    return function() {
        var a = document.getElementById("messageExpandID" + id);
        var div = document.getElementById("blogEntryBody" + id);
        if (a.innerHTML.toLowerCase() == exText) {
            div.style.maxHeight = div.scrollHeight + "px";
            a.innerHTML = clText;
        } else {
            div.style.maxHeight = "273px"; //Set in CSS File Also
            a.innerHTML = exText;
            document.getElementById("be" + id).scrollIntoView(true);
        }
    };
}

$(document).ready(function() {
    setMessageHeight();
});

