var baseurl = "";

jQuery(document).ready(function() {
	var id = 0;
	 var options = { path: '/', expires: 10 };
 	
	
	jQuery('li:has(.SubCategories)').each(function() {
		var htmlStr = '<img src="'+baseurl+'/wp-content/themes/ministry-free/css/arrow-right.gif" alt="" class="clicker" />'+jQuery(this).html();
      	jQuery(this).html(htmlStr);
		jQuery(this).attr('id', 'li'+id);
		
		if(jQuery.cookie('li'+id) == 'active') {
			jQuery(this).addClass('active');
			jQuery(this).children('img:first').attr('src', baseurl+'/wp-content/themes/ministry-free/css/arrow-down.gif');
		}
		
		id += 1;
		
	});
	jQuery('li.arrow:has(.SubCategories)').each(function() {
		var htmlStr = '<img src="'+baseurl+'/wp-content/themes/ministry-free/css/arrow-right.gif" alt="" class="clicker" />'+jQuery(this).html();
      	jQuery(this).html(htmlStr);
		jQuery(this).attr('id', 'li'+id);
		if(jQuery.cookie('li'+id) == 'active') {
			jQuery(this).addClass('active');
			jQuery(this).children('img:first').attr('src', baseurl+'/wp-content/themes/ministry-free/css/arrow-down.gif');
		}
		id += 1;
	});
	jQuery('li.MainCategory:has(.SubCategories) a').click(function() {
		jQuery.cookie(jQuery(this).parent().parent().attr('id'),'active', options);
	});
	jQuery('li.arrow:has(.SubCategories) a').click(function() {
		jQuery.cookie(jQuery(this).parent().attr('id'),'active', options);
	});
	jQuery('img.clicker').click(function() {
								  
		if(jQuery(this).parent().hasClass('active')) { 
			jQuery(this).parent().removeClass('active');
			jQuery(this).attr('src', baseurl+'/wp-content/themes/ministry-free/css/arrow-right.gif');
			jQuery.cookie(jQuery(this).parent().attr('id'),null, options);
		}
		else {
			jQuery(this).attr('src', baseurl+'/wp-content/themes/ministry-free/css/arrow-down.gif');
			jQuery(this).parent().addClass('active');
			jQuery.cookie(jQuery(this).parent().attr('id'),'active', options);
		}
		//jQuery(this).parents('li:has(.SubCategories)').addClass('active');
	});
	
});
