var current = 1;


$(document).ready(function(){
	// hide all but first
	$("dd:not(:first)").hide();
	$("dt:first").toggleClass( openClass );

	$("dt a").click(function(){

		// Close open list
		$("dt").removeClass() 
		$(this).parent().toggleClass( openClass )
		$("dd:visible").slideUp("slow");

		// Open clicked listing
		$(this).parent().next().slideDown("slow");

		return false;
	});



	// RSS feeds
	$("#RssFeedHolder div:not(:first)").hide();
	$("#RssFeedHolder h3:first").toggleClass( openClass );


	$('h3.gen').click(function () {

		// change image to normal for the old open title
		// Don't change it if open already
		if (!$(this).hasClass('open'))		{
			var $onKids = $('h3.open a').children('img');
			$onKids.attr('src', $onKids.attr('src').replace('_on',''));
		}

		var myGroup = trim($(this).attr('class').replace('gen','').replace('open',''));
		if ($(this).hasClass('open'))		{
			// Close
			//$('h3.' + myGroup).removeClass('open');
			//$('div.' + myGroup + '_dd').slideUp();
			//alert($('h3.' + myGroup + ' a').attr('src').replace('_on','').replace('_over',''));
		}	else	{
			// Open
			$('h3.' + myGroup).removeClass('open');
			$('div.' + myGroup + '_dd').slideUp();
			$(this).addClass('open').next().slideDown();
			$('h3.open a img').attr('src', doOnImg($('h3.open a img').attr('src')));
		}

		return true;

	});


	// Image rollovers
	$('.rollOver').hover(
		function ()	{	
			if (($(this).attr('src').indexOf("_on") == -1) || ($(this).attr('src').indexOf("_on") == -1))		{	
				$(this).attr('src',doOverImg($(this).attr('src')))
			}
		},	
		function ()	{	
			if ($(this).attr('src').indexOf("_on") == -1)		{	
				$(this).attr('src',doNormalImg($(this).attr('src')));
			}
		}
	)


});



var normalSuffix = ''
var overSuffix = '_over'
var onSuffix = '_on'


// Roll over helpers

function doOnImg(path)	{
	path = path.replace('_on','').replace('_over','');
	start = path.substring(0, path.indexOf('.'));
	end = path.substring(path.indexOf('.'));
	overpath = (start + onSuffix + end);
	return overpath;
}
function doNormalImg(path)	{
	path = path.replace('_on','').replace('_over','');
	start = path.substring(0, path.indexOf('.'));
	end = path.substring(path.indexOf('.'));
	overpath = (start + normalSuffix + end);
	return overpath;
}
function doOverImg(path)	{
	path = path.replace('_on','').replace('_over','');
	start = path.substring(0, path.indexOf('.'));
	end = path.substring(path.indexOf('.'));
	overpath = (start + overSuffix + end);
	return overpath;
}
function doDefaultImg(path)	{
	return path.replace(overSuffix,'');
}




function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}