jQuery.fn.sprites = function(settings) {
	settings = jQuery.extend({
		allowClick: true,
		show: {opacity: 'show'},
		hide: {opacity: 'hide'},
		active: 'active',
		click: 'click'
	}, settings);

	// Attach events to each child
	jQuery(this).children().each(function(){		

		// Do not attach events to active children
		if(!jQuery(this).hasClass(settings.active)){
			
			//hide the css defined :hover background
			jQuery(this).children('a').css({background: "none"});
			
			// Mouseover
			jQuery(this).hover(function() {
				jQuery('<div style="display:none"></div>').prependTo(this).animate(settings.show);		
			
			//Mouseout
			},function(){
				jQuery(this).children('div').animate(settings.hide, function(){
					jQuery(this).remove();
				});
			});
			
			//click events on the a if allowClick is true
			if(settings.allowClick){
				
				// Mousedown
				jQuery(this).children('a').mousedown(function(){
					jQuery(this).prev().addClass('click');
				//Mouseup
				}).mouseup(function(){
					jQuery(this).prev().removeClass('click');
				});
			}
			
		}
	});
};

	$(document).ready(function(){
    var sPath = window.location.pathname;
    sPage = sPath.substring(sPath.lastIndexOf('/') - 4);
    sPage = sPage.substring(5, sPage.length - 5);
    if (sPage == 'index') sPage = 'home';
    var activeClass ='#sn' + sPage;
    $(activeClass).addClass("active");
    $('.active').fadeIn(1000);
  
		$('.spritesnav').sprites({
			hide: {height: 'hide'}
		});
		
		if($('#accordion').length) {
			$('#accordion').accordion();
    }
		
	});
