jQuery().ready(function(){

	$("#acc1").accordion({
		alwaysOpen: false,
		autoheight: false,
		header: 'a.acc1',
		clearStyle: true,
		active: parseInt($.cookie('acc1')) // set current position
	});

	$("#acc2").accordion({
		alwaysOpen: false,
		autoheight: false,
		header: 'a.acc2',
		clearStyle: true,
		active: parseInt($.cookie('acc2')) // set current position

	});
	$("#acc3").accordion({
		alwaysOpen: false,
		autoheight: false,
		header: 'a.acc3',
		clearStyle: true,
		active: parseInt($.cookie('acc3')) // set current position
	});

	/* Remember position */
	jQuery('#acc1 a.acc1').bind('click', function() {
		var options = { path: '/', expires: 3600};
		var index = _getActiveIndex( $(this).parent().attr('id'), 1);
		$.cookie('acc1', index, options);		
	});

	jQuery('#acc2 a.acc2').bind('click', function() {
		var options = { path: '/', expires: 3600};
		var index = _getActiveIndex( $(this).parent().attr('id'), 2);
		$.cookie('acc2', index, options);		
	});

	jQuery('#acc3 a.acc3').bind('click', function() {
		var options = { path: '/', expires: 3600};
		var index = _getActiveIndex( $(this).parent().attr('id'), 3);
		$.cookie('acc3', index, options);
	});
});

function _resetIndexes(currentId, menuLevel){
	$.cookie("acc1", null);
	$.cookie("acc2", null);
	$.cookie("acc3", null);
}

function _getActiveIndex(currentId, menuLevel){
	var accordion = $("#acc"+menuLevel);
	var i = 0;
	var active = $.map(accordion.find("li.acc-li-"+menuLevel), function(a) {
		if ($(a).attr('id') == currentId){
			return i;
		}
		i++;
	});
	return active;
}


