/**
 * @author Eugene Neymark
 * Jquery plugin to do the expand / collapse functions 
 * it takes options as parameter to specify the following:
 * 
 * expander - the class ".expando" for the element that will be the expand/collapse
 * button, e.g. + - icon
 * 
 * toggle is the css class to be applied for collapsed state. 
 * expandAll - is the class for expand all sections button.
 * 
 * 
 */
;(function($){
$.fn.expandOrCollapse = function(options) {
	var settings = $.extend({
		mode: "classNames",
		cssForHide: {'display' : 'none'},
		cssForShow: {'display' : 'block'},
		cssButton: {'background-image':'none', 'padding-left':'0px'},
		expander : ".expando",
		toggle : "collapsed",
		expandAll : ".expandAll"
		},options||{});
	
	$(document).ready(function() {
		$().find(settings.expander).each(function(){
				$(this).click(function(){
					$(this).toggleClass(settings.toggle);
					if(settings.mode == "classNames") {
						//$(this).toggleClass(settings.toggle);
						$().find("." + this.id).toggleClass(settings.toggle);
					} else if(settings.mode == "cssProps") {
						if($(this).hasClass(settings.toggle))
							$().find("." + this.id).hide();
						else
							$().find("." + this.id).show();	
					}
					else
					{
						if($(this).hasClass(settings.toggle))
							$().find("." + this.id).css(settings.cssForHide);
						else
							$().find("." + this.id).css(settings.cssForShow);
						//$(this).css(settings.cssProp);
					}

					
				});
			});
		

		$().find(settings.expandAll).each(function(){
			$(this).click(function(){
				var collapseAll = $(this);
				collapseAll.toggleClass(settings.toggle);
				$().find("." + this.id).each(function(){
						if(collapseAll.hasClass(settings.toggle))
							$(this).addClass(settings.toggle);
						else 
							$(this).removeClass(settings.toggle);	
					});
				})
		});

		
	});	
};

})(jQuery);
