jQuery.fn.not_exists = function()
{
  return jQuery(this).length==0;
}

jQuery.fn.jqcollapse = function(o) 
{
 // Defaults
 var o = jQuery.extend( 
 {
   slide: true,
   speed: 300,
   easing: ''
 },o);
 
 $(this).each(function()
 {
	 var e = $(this).attr('id');
  
	 $('#'+e+' li > ul').each(function(i) 
   {
	   var parent_li = $(this).parent('li');
	   var sub_ul = $(this).remove();
      
    // Create 'a' tag for parent if DNE
    if (parent_li.children('a').not_exists()) 
    {
      parent_li.wrapInner('<a/>');
    }

    parent_li.find('a').addClass('jqcNode').css('cursor','pointer').click(function() 
    {
      if(o.slide==true)
      {
        sub_ul.slideDown(o.speed, o.easing);
        //return false;
      } 
      else
      {
        sub_ul.toggle();
      }
    });
    
    parent_li.append(sub_ul);
	});
	
	//Hide all sub-lists
	 $('#'+e+' ul li ul').hide(); 
 });
 
 var link     = document.URL;
 var linkexpl = link.split('/');
 var current  = linkexpl[6];
 
 if(current)
 {
   $('#sub_menu li .'+current+' ul').slideDown(0, o.easing);
 }
};
