function customRadio(eRadio, icons, hide_label)
{
	this.radio = eRadio;
	this.name = this.radio.getAttribute("name");
	this.id = this.radio.getAttribute("id");
	this.img = null;
	this.link = null;
	this.label = null;
	this.status = this.radio.checked;
	this.statusString = this.status.toString();
	this.hide_label = false;
	if(typeof hide_label!="undefined")
	{
		if(hide_label)
		{
			this.hide_label = true;
		}
	}
	this.radioImages = null;
	
	imageStore = [];
	// if a set of icons were passed through
	if(typeof icons!="undefined")
	{
		this.radioImages = icons;
		for(key in this.radioImages)
		{
			temp = new Image();
			temp.src = this.radioImages[key];
			imageStore.push( temp );
		}
	}
	else
	{
		this.radioImages = {"false":"radiobutton.gif", "true":"radiobutton_checked.gif"};
	}
	this.radioAlts = {"false":"unselected", "true":"selected"};
	var scope = this;

	if(!window.customRadios)
	{
		window.customRadios = {list: new Array()};
	}
	if(!window.customRadios[this.name])
	{
		window.customRadios[this.name] = [];
		window.customRadios.list.push(this.name);
	}
	window.customRadios[this.name].push(this);

	labels = document.getElementsByTagName("label");
	for(var i=0, limit=labels.length; i<limit; i++)
	{
		if(labels[i].htmlFor == this.id)
		{
			this.label = labels[i];
			i = limit;
		}
	}

	this.img = document.createElement("img");
	this.img.setAttribute("src", this.radioImages[this.statusString]);
	this.img.setAttribute("alt", this.radio.getAttribute("alt"));
	this.img.setAttribute("align", "absmiddle");
	this.link = document.createElement("a");
	this.link.setAttribute("href", "");
	this.link.className = "customradio";
	this.label.setAttribute("align", "absmiddle");

	// actions
	core.addEvent(this.radio, "click", function() { scope.select(true); scope.additionalAction(); });
	this.link.onclick = function(e) { scope.radio.click(); core.cancelEvent(e); return false; };
	this.link.onmouseover = function(e) { scope.swapImage(true); };
	this.link.onmouseout = function(e) { scope.swapImage(false); };
	this.link.onfocus = function(e) { scope.swapImage(true); };
	this.link.onblur = function(e) { scope.swapImage(false); };
	this.label.onclick = function(e) { scope.radio.click(); core.cancelEvent(e); return false; };

	this.link.appendChild(this.img);

	if(this.hide_label)
	{
		this.label.style.position = "absolute"
		this.label.style.left = "-9000px";
	}
	this.radio.style.position = "absolute"
	this.radio.style.left = "-9000px";
	core.insertAfter(this.link, this.radio);

	this.copyaction = function(func)
	{
		if(typeof func == "function")
		{
			func();
		}
		else if(typeof func == "string")
		{
			eval(func);
		}
	}

	this.select = function(checked)
	{
		// if this radiobutton is being selected, make sure all others are deselected
		if(checked && !scope.status)
		{
			var radioList = window.customRadios[this.name];
			for(var i=0, limit=radioList.length; i<limit; i++)
			{
				if(radioList[i].status)
				{
					radioList[i].select(false);
					radioList[i].swapImage(false);
					i = limit;
				}
			}
			scope.status = true;
			scope.swapImage(false);
		}
		else if(!checked)
		{
			scope.status = false;
		}
		scope.statusString = scope.status.toString();
	}

	this.swapImage = function(highlight)
	{
		// if this radiobutton is being selected, make sure all others are deselected
		if(!highlight && !scope.status)
		{
			scope.img.setAttribute("src", scope.radioImages['false']);
		}
		else
		{
			scope.img.setAttribute("src", scope.radioImages['true']);
		}
	};

	this.additionalAction = function()
	{
		if(document.getElementById("wishlist_signature")!=null && document.getElementById("wishlist_shadow")!=null)
		{
			scope.showSender();
		}
		if(document.getElementById("topaz-book")!=null)
		{
			scope.showRecipe();
		}
	}
	this.showSender = function()
	{
		// show the signature and shadow of the elf sending the letter
		var signature = document.getElementById("wishlist_signature");
		var shadow = document.getElementById("wishlist_shadow");
			var hiddenElf = document.getElementById("hidden_elf_name");
	
			if(signature!=null && shadow!=null)
			{
				var newSignature = document.createElement("img");
				newSignature.setAttribute("src", "images/wishlist/signature_"+scope.radio.getAttribute("value")+".gif");
				newSignature.setAttribute("alt", scope.radio.getAttribute("value"));
				signature.replaceChild(newSignature, signature.firstChild);
				hiddenElf.value = scope.radio.getAttribute("value");
				shadow.style.backgroundImage = 'url("images/wishlist/shadow_'+scope.radio.getAttribute("value")+'.jpg")';
				try {
					var backendDiv = document.getElementById("elfSignature");
					backendDiv.style.display = 'none';
				} catch (err) {
				//do nothing
				}
			}
	};
	this.showRecipe = function()
	{
		// show the appropriate recipe in the book
		var book = document.getElementById("topaz-book");
		var selectedValue = scope.radio.getAttribute("value");
		var selectedAlt = scope.radio.getAttribute("alt");
		
		var recipes = {'buttons':{'image':'images/topaz/book_madeleines.jpg', 'title':'Owl Madeleines', 'link':'pdfs/CAD_recipe_OwlMadeleines.pdf'},
									'flake':{'image':'images/topaz/book_fruitcake.jpg', 'title':'Forest Fruitcake', 'link':'pdfs/CAD_recipe_ForestFruitCake.pdf'},
									'fingers':{'image':'images/topaz/book_cake.jpg', 'title':'Chimney Christmas Cake', 'link':'pdfs/CAD_recipe_ChimneyXmasCake.pdf'},
									'drink':{'image':'images/topaz/book_biscuits.jpg', 'title':'Christmas Tree Biscuits', 'link':'pdfs/CAD_recipe_XmasTreeBiscuits.pdf'}
									}

		var recipeLink = document.createElement("a");
		recipeLink.setAttribute("href", recipes[selectedValue]['link']);
		recipeLink.setAttribute("title", "Click here to download Topaz's recipe for "+recipes[selectedValue]['title']);
		recipeLink.setAttribute("target", 'recipe_'+selectedValue);
		var recipeImage = document.createElement("img");
		recipeImage.setAttribute("src", recipes[selectedValue]['image']);
		recipeImage.setAttribute("alt", recipes[selectedValue]['title']);
		recipeLink.appendChild(recipeImage);
		book.replaceChild(recipeLink, book.firstChild);
	};
}
