Javascript into jQuery Widget.

Javascript into jQuery Widget.

Hi to all.

I am new to this and i really would like a help of some expert developer that for you might be a pretty easy task but for me it is really hard to achieve. I have a javascripts and i need it turned into a widget. I really don't know what im doing as i cannot turn into a widget.

The code is below: 

  1. /*

  2. CUSTOM FORM ELEMENTS

  3. Created by Ryan Fait
  4. www.ryanfait.com

  5. The only things you may need to change in this file are the following
  6. variables: checkboxHeight, radioHeight and selectWidth (lines 24, 25, 26)

  7. The numbers you set for checkboxHeight and radioHeight should be one quarter
  8. of the total height of the image want to use for checkboxes and radio
  9. buttons. Both images should contain the four staages of both inputs stacked
  10. on top of each other in this order: unchecked, unchecked-clicked, checked,
  11. checked-clicked.

  12. You may need to adjust your images a bit if there is a slight vertical
  13. movement during the different stages of the button activation.

  14. The value of selectWidth should be the width of your select list image.

  15. Visit http://ryanfait.com/ for more information.

  16. */

  17. var checkboxHeight = "53";
  18. var radioHeight = "25";
  19. var selectWidth = "190";


  20. /* No need to change anything after this */


  21. document.write('<style type="text/css">input.styled { display: none; } select.styled { position: relative; width: ' + selectWidth + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } .disabled { opacity: 0.5; filter: alpha(opacity=50); }</style>');

  22. var Custom = {
  23. init: function() {
  24. var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
  25. for(a = 0; a < inputs.length; a++) {
  26. if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className == "styled") {
  27. span[a] = document.createElement("span");
  28. span[a].className = inputs[a].type;

  29. if(inputs[a].checked == true) {
  30. if(inputs[a].type == "checkbox") {
  31. position = "0 -" + (checkboxHeight*2) + "px";
  32. span[a].style.backgroundPosition = position;
  33. } else {
  34. position = "0 -" + (radioHeight*2) + "px";
  35. span[a].style.backgroundPosition = position;
  36. }
  37. }
  38. inputs[a].parentNode.insertBefore(span[a], inputs[a]);
  39. inputs[a].onchange = Custom.clear;
  40. if(!inputs[a].getAttribute("disabled")) {
  41. span[a].onmousedown = Custom.pushed;
  42. span[a].onmouseup = Custom.check;
  43. } else {
  44. span[a].className = span[a].className += " disabled";
  45. }
  46. }
  47. }
  48. inputs = document.getElementsByTagName("select");
  49. for(a = 0; a < inputs.length; a++) {
  50. if(inputs[a].className == "styled") {
  51. option = inputs[a].getElementsByTagName("option");
  52. active = option[0].childNodes[0].nodeValue;
  53. textnode = document.createTextNode(active);
  54. for(b = 0; b < option.length; b++) {
  55. if(option[b].selected == true) {
  56. textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
  57. }
  58. }
  59. span[a] = document.createElement("span");
  60. span[a].className = "select";
  61. span[a].id = "select" + inputs[a].name;
  62. span[a].appendChild(textnode);
  63. inputs[a].parentNode.insertBefore(span[a], inputs[a]);
  64. if(!inputs[a].getAttribute("disabled")) {
  65. inputs[a].onchange = Custom.choose;
  66. } else {
  67. inputs[a].previousSibling.className = inputs[a].previousSibling.className += " disabled";
  68. }
  69. }
  70. }
  71. document.onmouseup = Custom.clear;
  72. },
  73. pushed: function() {
  74. element = this.nextSibling;
  75. if(element.checked == true && element.type == "checkbox") {
  76. this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px";
  77. } else if(element.checked == true && element.type == "radio") {
  78. this.style.backgroundPosition = "0 -" + radioHeight*3 + "px";
  79. } else if(element.checked != true && element.type == "checkbox") {
  80. this.style.backgroundPosition = "0 -" + checkboxHeight + "px";
  81. } else {
  82. this.style.backgroundPosition = "0 -" + radioHeight + "px";
  83. }
  84. },
  85. check: function() {
  86. element = this.nextSibling;
  87. if(element.checked == true && element.type == "checkbox") {
  88. this.style.backgroundPosition = "0 0";
  89. element.checked = false;
  90. } else {
  91. if(element.type == "checkbox") {
  92. this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
  93. } else {
  94. this.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
  95. group = this.nextSibling.name;
  96. inputs = document.getElementsByTagName("input");
  97. for(a = 0; a < inputs.length; a++) {
  98. if(inputs[a].name == group && inputs[a] != this.nextSibling) {
  99. inputs[a].previousSibling.style.backgroundPosition = "0 0";
  100. }
  101. }
  102. }
  103. element.checked = true;
  104. }
  105. },
  106. clear: function() {
  107. inputs = document.getElementsByTagName("input");
  108. for(var b = 0; b < inputs.length; b++) {
  109. if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className == "styled") {
  110. inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
  111. } else if(inputs[b].type == "checkbox" && inputs[b].className == "styled") {
  112. inputs[b].previousSibling.style.backgroundPosition = "0 0";
  113. } else if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className == "styled") {
  114. inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
  115. } else if(inputs[b].type == "radio" && inputs[b].className == "styled") {
  116. inputs[b].previousSibling.style.backgroundPosition = "0 0";
  117. }
  118. }
  119. },
  120. choose: function() {
  121. option = this.getElementsByTagName("option");
  122. for(d = 0; d < option.length; d++) {
  123. if(option[d].selected == true) {
  124. document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
  125. }
  126. }
  127. }
  128. }
  129. window.onload = Custom.init;
As you can see this is a code downloaded from a great website ryanfait but i cannot use it as it is i have to transform it into a widget.
Can anyone please help me out with this issue. 

Regards & Thanks
M