(function($){  
  $.fn.toggler = function(options) {  
	// instead of selecting a static container with 
	// $("#rating"), we now use the jQuery context
	var self= this;
  
   self.defaults = {  
				target:null,
				flop:null,
				hide:1,
				speed:"slow",
				flopcallback:function(){
					self.options.flop.html( self.options.target.css("display") == 'none' ? "Show" : "Hide");
				},
			  toggler: function(){
					 if (self.state()==="0" ) {
							self.options.target.hide();
						self.options.target.fadeIn(self.options.speed);
						self.options.target.show();
					 } else {
							self.options.target.fadeOut(self.options.speed);
							self.options.target.hide();
					 }
					  //      self.options.target.toggle();
			  }
		};
   var options = $.extend(self.defaults, options);  
	state = function() {
		return self.defaults.target.css("display") == 'none' ? "0" : "1";

	};
	storestate = function() {
		$.cookie(self.attr("id"), self.state());
	}; 
	self.options=options;
	self.storestate=storestate;
	self.state=state;
	var cookieval=$.cookie(self.attr("id")) ;
	if(cookieval != undefined){
		if (cookieval=="1") {
			self.options.target.show();
		}else {
			self.options.target.hide();
		}
	} else {
		if(self.options.hide==1) {
			self.options.target.hide();
		}
	}
	storestate();
		
	options.flopcallback();
	// ... rest of the code ...
	self.click(function(e){ 
					self.options.toggler(); 
					self.storestate();
					self.options.flopcallback();   });
	// if possible, return "this" to not break the chain
//return this;
};
 })(jQuery);  
