jQuery.fn.wstylize = function() {

		var is_ie6 = $.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent);
		var is_ie = (jQuery.browser.msie);

		function stylize_input_checkbox() {

			if (is_ie6) return;

			var html_winput_checkbox_wrapper = '<div class="winput_checkbox"></div>';

			$("input[type=checkbox].wstylize").each(function(i) {

					var checkbox = $(this);

					checkbox.wrap(html_winput_checkbox_wrapper);

					var wrapper = checkbox.parents(".winput_checkbox");


					checkbox.css("display","none");
					//checkbox.css("position","relative");
					//checkbox.css("left","400px");



					if (checkbox.attr("checked") != undefined) {
							wrapper.toggleClass("winput_checkbox_checked");
					}


					checkbox.change(function() {

						wrapper.toggleClass("winput_checkbox_checked");
					});

			});

		}


		function input_default_value_event() {

			$(":text.wstylize,:password.wstylize").each(function(i) {


				var input_field = $(this);

				input_field.addClass('inactive');

				input_field.focus(function() {
					if ($(this).hasClass('inactive')) {
						$(this).data("defaultValue",$(this).val());
						$(this).val("");
						$(this).toggleClass('inactive')
					}
				});


				input_field.blur(function() {
					if ($(this).val() == "") {
						$(this).addClass('inactive');
						$(this).val($(this).data("defaultValue"));
					}
				});

			});

		}

		function stylize_input_text() {

			input_default_value_event();

			if (is_ie6) return;

			var html_winput_text_wrapper = '<div class="winput_text"><div class="winput_inside"></div></div>';
			var html_winput_text_button_reset = '<div class="wbutton_micro_reset"></div>';

			$(":text.wstylize,:password.wstylize").each(function(i) {

				$(this).wrap(html_winput_text_wrapper);
				$(this).removeClass('wstylize');

				var wrapper = $(this).parents(".winput_text");
				var input_field = $(this);

				wrapper.width(input_field.width());

				if ($(this).hasClass("wparam-reset-button")) {

					wrapper.width(input_field.width()+16);
					input_field.before(html_winput_text_button_reset);

					var reset_button = wrapper.find('.wbutton_micro_reset')

					reset_button.click(function() {
						input_field.attr('value','');
						$(this).css('display','none');
						input_field.trigger('focus');
						return false;
					});
					input_field.keyup(function() {
						if (input_field.attr('value') == undefined)
							reset_button.css('display','none');
						else if (reset_button.css('display') == 'none')
								reset_button.css('display','');
					});
					input_field.keyup();
				}

			});


		}

		function stylize_input_button() {

			if (is_ie6) {
				$(".winput_button").removeClass("winput_button");
				return;
			}

			if (is_ie) {
				$(".winput_button").css("width","auto");
				$(".winput_button").css("overflow","visible");
				$(".winput_button span").css("margin-top","1px");
			}

		}


		function stylize_thumb() {


			var thumbs = $("img.wthumb");

			if(is_ie6) {
				return;
			}

			thumbs.each(function(i) {
				var img = $(this);
				var img_url = img.attr('src');

				var img_bg = img.css('background-image').replace(/url\((.*)\)/,'$1');
				// for IE
				img_bg = img_bg.replace(/"(.*)"/, '$1');

				img.css('background-image','url('+img_url+')');
				img.attr('src',img_bg);
			});

		}

		stylize_input_button();
		stylize_input_text();
		stylize_input_checkbox();
		stylize_thumb()
}



$(document).ready(function() {
	jQuery.fn.wstylize();
});
