/*
	accordion plugin by Alexey Doronin
	inspired by Vladimir Yunev's accordion plugin
	examples:
		$('#ul-element').accordion();
		$('.ul-elements').accordion();
*/
function stopDefault(e)						//	e = e || window.event;
{
	if ( e && e.preventDefault )			// Prevent the default browser action (W3C)
		e.preventDefault();
	else
		window.event.returnValue = false;	// A shortcut for stoping the browser action in IE
	return false;
}
function stopBubble(e)						//	e = e || window.event;
{
	if ( e && e.stopPropagation )			// If an event object is provided, then this is a non-IE browser
		e.stopPropagation();				// and therefore it supports the W3C stopPropagation() method
	else									// Otherwise, we need to use the Internet Explorer
		window.event.cancelBubble = true;	// way of cancelling event bubbling
}

jQuery.fn.accordion = function(){
	function update(ul){
		$('li:not(.active)', ul).css('cursor', 'pointer');
		$('li.active', ul).css('cursor', '');
		$('li ul', ul).hide(300);
		$('li.active ul', ul).show(300);
	}

    return	this.each(function(){
		var	ul	= $(this);
		var	id	= $(this).attr('id');
		if (!id)
		{
			id	= 'accordion'+Math.round(Math.random()*1000);
			$(this).attr('id',id);
			ul	= $('#'+id);
		}
		update(ul);

		$('li', ul).click(function(){
			if ($(this).parent().attr('id')!=id)
				return	false;
			if ($(this).hasClass('active')){
				$(this).removeClass('active').find('ul').hide(300);
			} else {
				$('li', ul).removeClass('active');
				$(this).addClass('active');
				update(ul);
			}
		});
		$('li a', ul).click(function(e){
			var	href	= $(this).attr('href');
			if (href){
				window.location	= href;
				return	true;
			}
//console.log('test');
			stopBubble(e);
		});
	});
};