/*

 CUSTOM FORM ELEMENTS

 Created by Ryan Fait
 www.ryanfait.com

 The only things you may need to change in this file are the following
 variables: checkboxHeight, radioHeight and selectWidth (lines 24, 25, 26)

 The numbers you set for checkboxHeight and radioHeight should be one quarter
 of the total height of the image want to use for checkboxes and radio
 buttons. Both images should contain the four stages of both inputs stacked
 on top of each other in this order: unchecked, unchecked-clicked, checked,
 checked-clicked.

 You may need to adjust your images a bit if there is a slight vertical
 movement during the different stages of the button activation.

 The value of selectWidth should be the width of your select list image.

 Visit http://ryanfait.com/ for more information.

 */

var checkboxHeight = "25";
var radioHeight = "25";
var selectWidth = "190";

/* No need to change anything after this */

document.write('<style type="text/css">span.custom_styled input { display: none; } .disabled { opacity: 0.5; filter: alpha(opacity=50); }</style>');

var Custom = {
	init : function() {
		var inputs_ = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
		var inputs = [];
		for(var i = 0; i < inputs_.length; i++) {
			if(inputs_[i].parentNode.className == "custom_styled") {
				inputs.push(inputs_[i]);
			}
		}
		for( a = 0; a < inputs.length; a++) {
			span[a] = document.createElement("span");
			span[a].className = inputs[a].type;

			if(inputs[a].checked == true) {
				position = "0 -" + (checkboxHeight * 2) + "px";
				span[a].style.backgroundPosition = position;
			}
			inputs[a].parentNode.insertBefore(span[a], inputs[a]);
			inputs[a].onchange = Custom.clear;
			if(!inputs[a].getAttribute("disabled")) {
				span[a].onmousedown = Custom.pushed;
				span[a].onmouseup = Custom.check;
			} else {
				span[a].className = span[a].className += " disabled";
			}
		}
		document.onmouseup = Custom.clear;
	},
	pushed : function() {
		element = this.nextSibling;
		if(element.checked == true) {
			this.style.backgroundPosition = "0 -" + checkboxHeight * 3 + "px";
		} else {
			this.style.backgroundPosition = "0 -" + checkboxHeight + "px";
		}
	},
	check : function() {
		element = this.nextSibling;
		if(element.checked == true) {
			this.style.backgroundPosition = "0 0";
			element.checked = false;
		} else {
			this.style.backgroundPosition = "0 -" + checkboxHeight * 2 + "px";
			element.checked = true;
		}
	},
	clear : function() {
		var inputs_ = document.getElementsByTagName("input");
		var inputs = [];
		for(var i = 0; i < inputs_.length; i++) {
			if(inputs_[i].parentNode.className == "custom_styled") {
				inputs.push(inputs_[i]);
			}
		}
		for(var b = 0; b < inputs.length; b++) {
			if(inputs[b].checked == true) {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight * 2 + "px";
			} else {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			}
		}
	}
}
window.onload = Custom.init;

