var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function nav_open(){
	nav_canceltimer();
	nav_close();
	ddmenuitem = $(this).find('ul').css('display', 'block');
}

function nav_close(){
	if(ddmenuitem) ddmenuitem.css('display', 'none');
}

function nav_timer(){
	closetimer = window.setTimeout(nav_close, timeout);
}

function nav_canceltimer(){
	if(closetimer){
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

$(document).ready(function(){

	$('#nav li:last').attr('class','last');

	$('#nav > li').bind('mouseover', nav_open);
	$('#nav > li').bind('mouseout',  nav_timer);
	
	var mainHeight = $('#main').height();
	var sideHeight = $('#side').height();
	var tallestItem = "";
	if (sideHeight > mainHeight){
		tallestItem = sideHeight;
	}else{
		tallestItem = mainHeight;
	}
	tallestItem = tallestItem + 80;
	$('#main-content').css('height',tallestItem+'px');
	$('#side').css('height',tallestItem+'px');

	$('.quote').prepend('<img src="/css/img/quote-open.gif" title="" alt="" class="quote-open" />');
	$('.quote').append('<img src="/css/img/quote-close.gif" title="" alt="" class="quote-close" />');

	





$.fn.reverse = function() {
    return this.pushStack(this.get().reverse(), arguments);
};

// create two new functions: prevALL and nextALL. they're very similar, hence this style.
$.each( ['prev', 'next'], function(unusedIndex, name) {
    $.fn[ name + 'ALL' ] = function(matchExpr) {
        // get all the elements in the body, including the body.
        var $all = $('body').find('*').andSelf();

        // slice the $all object according to which way we're looking
        $all = (name == 'prev')
             ? $all.slice(0, $all.index(this)).reverse()
             : $all.slice($all.index(this) + 1)
        ;
        // filter the matches if specified
        if (matchExpr) $all = $all.filter(matchExpr);
        return $all;
    };
});

//$('#staff').prevALL('#main-content').css('padding-right','0');





});

document.onclick = nav_close;
