//##############################
// jQuery Custom Radio-buttons and Checkbox; basically it's styling/theming for Checkbox and Radiobutton elements in forms
// By Dharmavirsinh Jhala - dharmavir@gmail.com
// Date of Release: 13th March 10
// Version: 0.8
/*
 USAGE:
	jQuery(document).ready(function(){
		jQuery(":radio").behaveLikeCheckbox();
	}
*/

var elmHeight = "7.5";	// should be specified based on image size

// Extend JQuery Functionality For Custom Radio Button Functionality
jQuery.fn.extend({
dgStyle: function()
{
	// Initialize with initial load time control state
	jQuery.each(jQuery(this), function(){
		var elm	=	jQuery(this).children().get(0);
		elmType = jQuery(elm).attr("type");
		jQuery(this).data('type',elmType);
		jQuery(this).data('checked',jQuery(elm).attr("checked"));
		jQuery(this).dgClear();
	});
	jQuery(this).mousedown(function() { jQuery(this).dgEffect(); });
	jQuery(this).mouseup(function() { jQuery(this).dgHandle(); });	
},
dgClear: function()
{
	if(jQuery(this).data("checked") == true)
	{
		jQuery(this).css("backgroundPosition","center -"+(elmHeight*2)+"px");
		}
	else
	{
		jQuery(this).css("backgroundPosition","center 0");
		}	
},
dgEffect: function()
{
	if(jQuery(this).data("checked") == true){}
		//jQuery(this).css({backgroundPosition:"center -"+(elmHeight*3)+"px"});
	else
		jQuery(this).addClass('selected');
},
dgHandle: function()
{
	var elm	=	jQuery(this).children().get(0);
	if(jQuery(this).data("checked") == true)
		jQuery(elm).dgUncheck(this);
	else
		jQuery(elm).dgCheck(this);
	
	if(jQuery(this).data('type') == 'radio')
	{
		jQuery.each(jQuery("input[name='"+jQuery(elm).attr("name")+"']"),function()
		{
			if(elm!=this)
				jQuery(this).dgUncheck(-1);
		});
	}
},
dgCheck: function(div)
{
	jQuery(this).attr("checked",true);
	jQuery(div).data('checked',true).css({backgroundPosition:"center -"+(elmHeight*2)+"px"});
},
dgUncheck: function(div)
{
	jQuery(this).attr("checked",false);
	if(div != -1){
		jQuery(div).data('checked',false).css({backgroundPosition:"center 0"});
           
        }
	else
		jQuery(this).parent().data("checked",false).css({backgroundPosition:"center 0"});
}
});
