var CoPayCheck = Class.create({
	
	initialize: function(item){
		//build the buttons for the copay checker
		this._loadButtons();
		this._setResponse();
	},
	
	_loadButtons: function(){ 
		//iterate over all a tags with a blank href
		jq$("#co-pay-check a").each(function(){ 
			//add a click event handler to the anchor element
			jq$(this).click(function(ev) {
				//get the parent tag
				ev.preventDefault();
				var parent = jq$(this).parent().parent();
				//set the classes of the children to not selected
				jq$(parent).children().each(function() {
					//iterate over the anchor tags, within the child div tags
					jq$(this).children().each(function(){
						jq$(this).attr("class", "");
					});					
				});
				//update the elements class
				jq$(this).attr("class", "selected");

				if (jq$("div.no-btn").children(".selected").length > 0)
				{
					//get the result tag
					var result = jq$("td.result")[0];
					//set all the response styles to display none
					jq$(result).children().each(function() {
						jq$(this).attr("style", "display: none;");
					});
					//set the yes response style to block
					jq$(result).children(".not-eligible").attr("style", "display: block;");
				}
				//if all answeres are yes, change to the yes response
				else if (jq$("div.yes-btn").children(".selected").length >= 5)
				{
					//get the result tag
					var result = jq$("td.result")[0];
					//set all the response styles to display none
					jq$(result).children().each(function() {
						jq$(this).attr("style", "display: none;");
					});
					//set the yes response style to block
					jq$(result).children(".eligible").attr("style", "display: block;");
				}
				else
				{
					//get the result tag
					var result = jq$("td.result")[0];
					//set all the response styles to display none
					jq$(result).children().each(function() {
						jq$(this).attr("style", "display: none;");
					});
					//set the yes response style to block
					jq$(result).children(".instructions").attr("style", "display: block;");
				}
			});
		});
	},
	
	_setResponse: function()
	{
		//get the result tag
		var result = jq$("td.result")[0];
		//set all the response styles to display none
		jq$(result).children().each(function() {
			jq$(this).attr("style", "display: none;");
		});
		//set the yes response style to block
		jq$(result).children(".instructions").attr("style", "display: block;");
	}	
});
