/*
 * Author Raymond van Vuuren 2010
 * Url: http://www.babyblox.nl
 * Use and change, just place a link to my site
 */


(function ( $ )	{

				jQuery.fn.filterx = function (settings)	{
					settings = jQuery.extend({
							onclick: '',
							hover:'',
							classHover: 'hover',
							classSelected: 'selected',
							multiple: false
						}, settings);					

					
					return $(this).each(function() { 
						var container = $(this);
						if(container.hasClass("filterinit")) return;
						
						var old = container.height(); 
						var test = container.css("height", "auto").height();
						if(test>old) container.css("height", old);


						container.addClass("filterinit");
						if(settings.multiple == true || $(":checkbox", container).length > 0)	{
							settings.multiple = true;
						}
						$(":input", container).css("display", "none");
						$(":input:checked", container).parent().addClass(settings.classSelected);
						$(":input[type!=hidden]", container).parent().each(function() {
							$(this).mouseover(function() { 
								$(this).css("cursor", "pointer");
								$("div", container).removeClass(settings.classHover);
								$(this).addClass(settings.classHover);

								$(this).mouseout(function() {
									$(this).removeClass(settings.classHover);
								});

								if(typeof settings.hover == 'function') settings.hover(this);
							});

							$(this).click(function() {
								
								if($(this).hasClass(settings.classSelected) == false) {
									if(settings.multiple == false) { 
										$("."+settings.classSelected, container).removeClass(settings.classSelected);
										$("input", container).removeAttr('checked');
									}

									$(this).addClass(settings.classSelected);
									$("input", this).attr("checked", "checked");
								} else	{
									$(this).removeClass(settings.classSelected);
									$("input", this).removeAttr("checked");
								}
								if(typeof settings.onclick == 'function') settings.onclick(this);
							}); 
						});						
						
						
						
					});
					
					
					

					
					

				}
			}) (jQuery);
