/*---------------------------------------------------------------------
- Fix IE6 background image flicker bug
- Prevents IE6 flicker when hover on links with background-image
- Author: MGM, inspired by http://mister-pixel.com
----------------------------------------------------------------------*/
try {
	document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

/*---------------------------------------------------------------------
- Set height on left navigation
- Prevents...
- Author: MGM
----------------------------------------------------------------------*/
$.leftnavHeight = function() {
    if(document.getElementById("leftnav") != null) {
        var contentHeight = $('#maincontent').height() + 5;
        $('#leftnav').height(contentHeight);
    }
}

/*---------------------------------------------------------------------
- Accordion function (based on jQuery)
- Toggles sections within a container
- Author: MGM, inspired by http://fmarcia.info/jquery/accordion.html
----------------------------------------------------------------------*/
$.accordion = function(items, first, options) {

    var active = first;
    var running = 0;

    // optional vars, set in function call
    var titles = options && options.titles || '.title';
    var contents = options && options.contents || '.content';
    var onClick = options && options.onClick || function(){};
    var onShow = options && options.onShow || function(){};
    var onHide = options && options.onHide || function(){};
    var showSpeed = options && options.showSpeed || 'slow';
    var hideSpeed = options && options.hideSpeed || 'fast';

    // collapse all and show first item
    $(items).not(active).children(contents).hide();
    $(items).not(active).each(onHide);
    $(active).each(onShow);

    // attach click events to title elements
    $(items).children(titles).click(function(e){

	    var p = $(contents, this.parentNode);
	    $(this.parentNode).each(onClick);

	    if (running || !p.is(":hidden")) return false;
	    running = 2;

	    $(active).children(contents).not(':hidden').slideUp(hideSpeed, function(){--running;});
	    p.slideDown(showSpeed, function(){--running;});

	    $(active).each(onHide);
	    active = '#' + $(this.parentNode)[0].id;
	    $(active).each(onShow);

	    return false;
    });

};

// executes when the DOM is ready. jQuery replacement for window.onload
$(function(){
	$.leftnavHeight();
});