/*
	accordion 2 plugin by Alexey Doronin
	examples:
		jQuery('#ul-element').accordion();
		jQuery('.ul-elements').accordion();
*/
jQuery.fn.accordion = function(){
	function update(ul){
		jQuery(ul).find(' > li:not(.active)').css('cursor', 'pointer');
		jQuery(ul).find(' > li.active').css('cursor', '');
		jQuery(ul).find('ul').hide(300);
		jQuery(ul).find(' > li.active  > ul').show(300);
	}

    return	this.each(function(){
		var	ul	= jQuery(this);
		var	id	= jQuery(this).attr('id');
		if (!id){
			id	= 'accordion'+Math.round(Math.random()*1000);
			jQuery(this).attr('id',id);
		}
		jQuery(ul).find('li').each(function(){
			if (jQuery(this).find('ul').length){
//				jQuery(this).css('margin-left','-14px');
				jQuery(this).find('a:eq(0)').prepend('<img src="/wp-content/themes/cscn/img/arrow-e-12.png" class="arrow" />');
			}
		});
		update(ul);

		jQuery('ul img.arrow').click(function(){
			var	li	= jQuery(this).parent().parent();
			var	pul	= jQuery(li).parent();
			if (jQuery(li).hasClass('active')){
				jQuery(li).removeClass('active');
				jQuery(li).find(' > ul').hide(300);
				jQuery(this).attr('src','/wp-content/themes/cscn/img/arrow-e-12.png');
			} else {
				jQuery(pul).find('li').removeClass('active');
				jQuery(pul).find('li').find('img.arrow').attr('src','/wp-content/themes/cscn/img/arrow-e-12.png');
				jQuery(li).addClass('active');
				jQuery(this).attr('src','/wp-content/themes/cscn/img/arrow-s-12.png');
				update(pul);
			}
			return	false;
		});
	});
};
