
function toggleDisplay(id)
{
    el = document.getElementById(id);
    if( el.style.display != 'none' )
        el.style.display = 'none';
    else
        el.style.display = 'block';
}


var fadingBlocks = new Array();

function fadeBlock(id)
{
    if( fadingBlocks[id] )
        return;

    ctr = 0;

    function doFade()
    {
        ctr++;

        opacity = el.style.opacity;
        //alert("Fading... opacity = " + opacity + ", delta = " + delta);
        opacity = parseFloat(opacity) + delta;

        if( opacity > 0.9  || opacity < 0.1 || ctr > 10 )
        {
            clearInterval(intervalId);
            opacity = Math.round(opacity, 0);
            if( delta < 0 )
                toggleDisplay(id);
            fadingBlocks[id] = 0;
        }

        el.style.opacity = opacity;
    }

    fadingBlocks[id] = 1;
    el = document.getElementById(id);
    delta = ( el.style.display != 'none' ) ? -0.1 : 0.1;
    if( delta > 0 )
        toggleDisplay(id);
    intervalId = setInterval(doFade, 50);
}


function expand( element ) {

if(jQuery(element).children().hasClass("expand")){
    jQuery("> span.collapsing", element).removeClass("expand").addClass("collapse").attr("title", "click to collapse");
    jQuery("> span span.sym img", element).attr("alt", "collapse").attr("src","/wp-content/plugins/collapsing-categories/img/collapse.gif");
    jQuery("> ul", element).slideDown("fast");
    }
}

var contentWidth = 0;
var windowWidth = 0;
jQuery(document).ready(function($) {
    contentWidth = $('.post').width();
    windowWidth = $(window).width();
    jQuery('.entry_author_image img').click(function() {jQuery(this).width() == 100 ? jQuery(this).width('auto') : jQuery(this).width('100px');});
    //jQuery('.cat-item ul.children').css({display: 'none'});
    //jQuery('.sidebarlist > ul > li.cat-item').hoverIntent(function(){/*jQuery('.cat-item ul.children').not(this).slideUp("slow");*/jQuery('ul', this).slideDown("slow");}, function(){;});
    jQuery(".sidebarlist > ul.list > li.collapsing > ul").slideDown("fast");
    jQuery("li.item").each(function(){if(jQuery(this).siblings().length == 0){jQuery(this).parent("ul").css("display", "none").parent().addClass("oneItemCategory").children("span").remove();} });
    jQuery('.sidebarlist li.collapsing').hoverIntent(function(){expand(this);}, function(){;});
    jQuery("a#trans").parents("fieldset").css("display", "none").before("<a id=\"translations\" name=\"translations\"></a>");
    jQuery("legend a.url:contains('Kiran')").parent("legend").parent("fieldset").css({'background-color':'paleGoldenRod','border':'2px solid green'});
    

});



var tdsbBackground = "";
function fadeSideBar()
{
    tdsb = document.getElementById('tdsidebar');
    sb = document.getElementById('sidebar');
    divcont = document.getElementById('content');

    // I am not sure how the below works to toggle the background on and off
    // for the container cell. tdsbBackground, as set below, doesn't work!!!
    // It's empty, I guess because sb.style.backgroundColor is computer and
    // not available here. But the below logic, to toggle the background from
    // transparent to colour and back works magically!!!

    if( tdsbBackground == "" )
        tdsbBackground = sb.style.backgroundColor;

    if( sb.style.display == 'none' )
    {
        divcont.style.borderRadiusBottomleft = '0px';
        divcont.style.webkitBorderBottomLeftRadius = '0px';
        divcont.style.MozBorderRadiusBottomleft = '0px';
        tdsb.style.backgroundColor = tdsbBackground;
    }
    else
    {
        divcont.style.borderRadiusBottomleft = '30px';
        divcont.style.webkitBorderBottomLeftRadius = '30px';
        divcont.style.MozBorderRadiusBottomleft = '30px';
        tdsb.style.backgroundColor = 'transparent';
    }

    //fadeBlock('sidebar');
    if(jQuery('#sidebar').css('display') != 'none')
    jQuery('#sidebar').animate({'width': '0px', 'opacity': 0}, 'slow', 'swing', function(){jQuery('#sidebar').css({'display' :'none'});});
    else
    jQuery('#sidebar').css({'display': 'block'}).animate({'width': '270px', 'opacity': 1}, 'slow', 'swing');
    jQuery('.post').width() == contentWidth ? jQuery('.post').width(windowWidth - 122).css({maxWidth:'1096px'}): jQuery('.post').width(contentWidth).css('maxWidth',contentWidth + 'px');
    // .css({maxWidth:'none'})
}

function toggleDelicious()
{
    recent = document.getElementById('recent');
    rechdr = document.getElementById('recentheader');
    reclist = document.getElementById('recentlist');
    recmore = document.getElementById('recentmore');

    if( reclist.style.display == 'block' )
    {
        recmore.style.display = 'none';
    }
    else
    {
        recmore.style.display = 'block';
    }

    fadeBlock('recentlist');
}


function recalcBlocks()
{
    document.getElementById("container").style.height = getWinHeight() + "px";
}


// code borrowed from: http://www.howtocreate.co.uk/tutorials/javascript/browserwindow
function getWinHeight()
{
    var myHeight = 0;
    if( typeof( window.innerHeight ) == 'number' )
    {
        //Non-IE
        myHeight = window.innerHeight;
    }
    else
    if( document.documentElement && document.documentElement.clientHeight )
    {
        //IE 6+ in 'standards compliant mode'
        myHeight = document.documentElement.clientHeight;
    }
    else
    if( document.body && document.body.clientHeight )
    {
        //IE 4 compatible
        myHeight = document.body.clientHeight;
    }

    return(myHeight);
}

function getWinWidth()
{
    var myWidth = 0;
    if( typeof( window.innerWidth ) == 'number' )
    {
        //Non-IE
        myWidth = window.innerWidth;
    }
    else
    if( document.documentElement && document.documentElement.clientWidth )
    {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
    }
    else
    if( document.body && document.body.clientWidth )
    {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
    }

    return(myWidth);
}
