﻿/*@cc_on
try { document.execCommand('BackgroundImageCache', false, true); } catch(e) {}
@*/

jQuery.fn.loginFocus = function() {
	var userId = this.find('input.intext:eq(0)'),
		userPass = this.find('input.intext:eq(1)');

	userId.focus(function() {
		$(this).removeClass('id');
	}).blur(function() {
		if ($(this).val().length <= 0) $(this).addClass('id');
	});
	userPass.focus(function() {
		$(this).removeClass('pass');
	}).blur(function() {
		if ($(this).val().length <= 0) $(this).addClass('pass');
	});
};
$(document).ready(function() {
	$('#user_login').loginFocus();
});

var CustomInput = {
	customRadio: function() {
		var radio = $('input[type="radio"].radio');
		$.each(radio, function(i) {
			$(this).css({ display: 'none' })
			.wrap('<span class="radio"></span>')
			.parent()
			.css({
				backgroundPosition: ($(this).is(':checked') != true) ? '0 0' : '0 -10px'
			}).click(function() {
				var thisInput = $(this).find('input:radio'),
					thisInputName = thisInput.attr('name');

				$.each($('input:radio[name=' + thisInputName + ']'), function() {
					$(this).parent().css({ backgroundPosition: '0 0' });
					$(this).attr("checked",false);
				});

				$(this).css({ backgroundPosition: '0 -10px' });
				thisInput.val([thisInputName]);
                thisInput.attr("checked",true);
			});
		});
	},
	customCheckbox: function() {
		var checkbox = $('input[type="checkbox"].checkbox');
		$.each(checkbox, function(i) {
			$(this).css({ display: 'none' })
			.wrap('<span class="checkbox"></span>')
			.parent()
			.css({
				backgroundPosition: ($(this).is(':checked') != true) ? '0 0' : '0 -13px'
			}).click(function() {
				var thisInput = $(this).find('input:checkbox'),
					thisInputName = thisInput.attr('name');

				if ($(this).find('input:checkbox').is(':checked')) {
					$(this).css({ backgroundPosition: '0 0' });
					$(this).find('input').attr('checked', false);
				} else {
					$(this).css({ backgroundPosition: '0 -13px' });
					thisInput.val([thisInputName]);
				}
			});
		});
	},
	customSelect: function() {
		var select = $('select.select');

		$.each(select, function(i) {
			var thisSelect = $(this),
				selectList,
				thisSelected,
				openState = false,
				selectWidth = thisSelect.outerWidth(),
				thisSelectList = thisSelect.find('option');

			var openStateFn = function() {
				selectList.remove();
				openState = false;
				$(document).unbind('click', openStateFn);
			};

			thisSelect.css({ display: 'none' })
				.wrap('<span class="select-box"></span>').parent().css({ width: selectWidth + 'px' })
					.append('<span class="selected">' + thisSelectList.filter(':selected').text() + '</span>').click(function() {
						if (openState == true) return;

						thisSelected = $(this);
						//thisSelected.after('<ul class="select-box-list"></ul>');
						selectList = $('<ul class="select-box-list"></ul>').appendTo('body');

						selectList.css({
							left: thisSelected.offset().left + 'px',
							top: thisSelected.offset().top + thisSelected.outerHeight() - 1 + 'px',
							width: thisSelected.width() + 'px'
						});

						$.each(thisSelectList, function(i) {
							$('<li>' + $(this).text() + '</li>').appendTo(selectList)
								.click(function() {
									openState = false;
									thisSelected.find('span').text(thisSelectList.eq(i).text());
									//thisSelect.val(thisSelectList.eq(i).val());
									thisSelect.change(function() {
										$(this).val(thisSelectList.eq(i).val());
									}).change();
									selectList.remove();
									return false;
								}).hover(function() { $(this).addClass('hover'); }, function() { $(this).removeClass('hover'); });
						});

						openState = true;
						$(document).bind('click', openStateFn);
						return false;
					});
		});
	}
};

$(document).ready(function() {
	CustomInput.customRadio();
});

