
(function($) {
	
	$.onedotRollover = {
		stuck: "",
		defaults: { over_lbl: "-over" },
		stick: function(id) {
			unstick();
			stick(id);
		},
		unstick: unstick
	}
	
	
	// create the new functions
	$.fn.extend({
		onedotRollover: function(settings) {
			settings = $.extend({}, $.onedotRollover.defaults, settings);

			// return this object so it can be chained
			return $(this).each(function() {
				// save the image properties
				var img = $('img', this).attr("src");
				var ext = img.substr(img.length-3, 3)
				var base = img.substr(0, img.length-4);
				this.states = {
					over: base + settings.over_lbl + "." + ext,
					out: img
				}
	
				// preload the over state
				var temp = new Image();
				temp.src = this.states.over
	
				// assign the rollover functionality
				$(this).hover(over, out);
				
				// fix thepng action
				$('img', this).ifixpng();
			});
		}
	});


	// ******************** Public Functions *********************//
	



	// ******************** Private Functions *********************//
	// stick an image with the id
	function stick(id) {
		var img = $("#"+id);
		var elm = img.get(0);
		
		// if the object exists
		if(elm != undefined) {
			// change it to the over state
			elm.src = elm.states.over;
			
			// remember we're stuck
			$.onedotRollover.stuck = img;
			
			// prevent mouse input
			img.unbind("mouseover").unbind("mouseout");
		}
	};


	// unstick the current image
	function unstick() {
		
		if($.onedotRollover.stuck != "") {
			var img = $("#" + $.onedotRollover.stuck);
			var elm = img.get(0);
			
			// change it to the out state
			elm.src = elm.states.out;
			
			// remember that we're not stuck
			$.onedotRollover.stuck = "";
			
			// give it back the functionality
			img.hover(over, out);
		}

	};


	// log function for testing
	function log(s) {
		window.console.log(s);
	}

	// change to the over state
	function over() {
		$('img', this).attr("src", this.states.over);

		// fix thepng action
		$('img', this).ifixpng();
	};
	
	
	// change to the off state
	function out() {
		$('img', this).attr("src", this.states.out);

		// fix thepng action
		$('img', this).ifixpng();
	};





	// ******************** Defaults *********************//
	$.fn.onedotRollover.defaults = {
		over_lbl: "-over"
	};



})(jQuery);