$('#nav ul ul').each(function(i){
	var link = $(this).prev('a');
	link.append(document.createElement('span'));
	link.click(function(){
		$(this).parent().toggleClass('active');
		$(this).next('ul').slideToggle(400);
		return false;
	});
	var link_href = new RegExp(link.attr('href'));
	if (window.location.toString().match(link_href)) {
		link.click();
	}
});

function create_dfn_box() {
	if (!document.getElementById('dfn')) {
		var dfn_box = document.createElement('div');
		dfn_box.id = 'dfn';
		document.body.appendChild(dfn_box);
	}
}

$('dfn')
	.addClass('active')
	.mouseover(function() {
		create_dfn_box();
		dfn_box = document.getElementById('dfn');
		dfn_box.innerHTML = terms[$(this).text().toLowerCase()];
		dfn_box.style.left = $(this).offset().left + $(this).width()  + 8 + 'px',
		dfn_box.style.top =  $(this).offset().top  - ($(this).height()/2) - 8 + 'px',
		$('#dfn').stop(false,true).fadeIn('100');
	})
	.mouseout(function() {
		$('#dfn').stop(false,true).fadeOut('100');
	})
	
var terms = {
	'pv'               : 'Photovoltaic, pertaining to the direct conversion of light into electricity; photo = light, voltaic = electric current',
	'photovoltaic'     : 'Pertaining to the direct conversion of light into electricity; photo = light, voltaic = electric current',
	'njcep'            : 'New Jersey&rsquo;s Clean Energy Program&trade;',
	'semiconductor'    : 'Any material that has a limited capacity for conducting an electric current. Certain semiconductors are uniquely suited to the photovoltaic conversion process.',
	'kwh'              : 'Kilowatt-Hour, 1,000 thousand watts acting over a period of 1 hour. The kWh is a unit of energy.',
	'mw'               : 'Megawatt, 1,000 kilowatts, or 1 million watts; standard measure of electric power plant generating capacity.',
	'carbon footprint' : 'A measure of the amount of carbon dioxide produced by a person, organization or state in a given time',
	'srec'             : 'Solar Renewable Energy Certificate, a clean energy credit issued in the form of a tradable certificate by the New Jersey Board of Public Utilities.',
	'net metering'     : 'Solar energy that is fed back into the electrical grid, causing the meter to run backwards.'
}
