$(document).ready(function(){ 

	//http://stilbuero.de/jquery/cookie/	
	var options = {expires: 365};
	
	$("#accordion").accordion({
		autoHeight: false,
		//active: ".current",
		active: ".current",
		animated: false,
		 selectedClass: "active",
		 change: function(event, ui) {
		
			if (ui.newHeader.text() == 'Category'){				
				$.cookie(COOKIE_ACCORDION_SELECTED, 0, options);
			}
			if (ui.newHeader.text() == 'Application'){
				$.cookie(COOKIE_ACCORDION_SELECTED, 1, options);
			}
			if (ui.newHeader.text() == 'Range'){
				$.cookie(COOKIE_ACCORDION_SELECTED, 2, options);
			}			
		}, 
		icons: {
			header: "sussex_header",
				headerSelected: "sussex_header_selected"
		}

	});	
	
	/*
	 * if we want to override the index 
	 * otherwise use the index set in the cookie
	 */
	var idToActivate;
	if (accordionIdtoActivate && accordionIdtoActivate != ''){
		idToActivate = accordionIdtoActivate;
	}else{
		idToActivate = $.cookie(COOKIE_ACCORDION_SELECTED)		
	}	
	$("#accordion").accordion('activate', Number(idToActivate));
	
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		//no slide effect
	}else{
		$('#accordion').accordion('option', 'animated', 'slide');
	}
	
	var curSelection = $('#selected').text();
	$.each($('#accordion li a'), function() { 
		if ($(this).text() == curSelection){
			$(this).addClass('active');
		}		
	});
	
	
	
	
});