/*
	jQuery One Show Hide v1.0 - http://www.onerutter.com/oneshowhide
	Copyright (c) 2010 Jake Rutter
	This plugin available for use in all personal or commercial projects under both MIT and GPL licenses.
	Modified by Carron Media Ltd, 2010.
*/

jQuery(document).ready(function() { 

	//Set the default values, use comma to separate the settings 
	var defaults = {  
		 numShown: 7,  
		 showText : 'more',  
		 hideText : 'less'  
	}  
            
	jQuery('#categories-2 ul').each(function() {  
		var o = defaults;  
		var obj = jQuery(this);
		
		// Determine the length of items here and calculate the number hidden
		var pLength = obj.children().length;
		var numHidden = pLength - o.numShown;
		var pList = obj.children();
	
		// Setup Show/Hide Link
		var shLink = "<a href='#' class='viewmore'>" + o.showText + "</a>";
		
		if (pLength > o.numShown) {
			jQuery(shLink).insertAfter(obj); 
		}
	
		pList.each(function(index){
			if (index < o.numShown) {
				jQuery(pList[index]).show(); 
			}		
			else {
				jQuery(pList[index]).hide().addClass('hidden');
			}    
		});

		// This is where I toggle the text
		jQuery("a.viewmore").live("click", function(e){
		
			if (jQuery(this).text() == o.showText) {
				jQuery(this).text(o.hideText);
			} else {
				jQuery(this).text(o.showText);
			}
			jQuery('.hidden').toggle();
			return false;
			
		});                
	
	});  
				
}); 

