/*
 * jQuery PilihRadio plugin
 * Version 0.1  (22/11/2007)
 * @requires jQuery v1.1.3
 *
 * Examples at: http://didats.net/jquery-plugin-pilihradio-style-your-radio-button.html
 * Copyright (c) 2007 Didats Triadi.
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 */

jQuery.fn.pilihradio = function(image_folder_url) {
	// image
	tick = "tick.png";
	cross = "cross.png";
	
	var obj = $(this);
	$(this).find("input[@type=radio]").each(function() {
		// hide all
		$(this).css({display:"none"});
		
		var img;
		if($(":checked",this).val() == null) img = cross;
		else img = tick;
		
		// add a new element after the object
		$(this).after('<img src="'+image_folder_url+img+'" alt="'+$(this).attr("value")+'" class="radio" />');
		
	});
	$(this).find("img.radio").click(function() {
		var name = $(this).parent().find("input[@type=radio]").attr("name");
		
		//alert($(this).parent().text());
		
		obj.find("input[@name="+name+"]").each(function() {
			$(this).removeAttr("checked");
			$(this).parent().find("img.radio").removeAttr("src");
			$(this).parent().find("img.radio").attr({src: image_folder_url+cross});
		});
		
		$(this).parent().find("input[@name="+name+"]").attr({checked:"checked"});
		
		if($(this).parent().find("input[@type=radio]").attr("checked") == true) {
			$(this).attr({src:image_folder_url+tick});
		}
		else {
			$(this).attr({src:image_folder_url+cross});
		}
	});
};