$(document).ready(function() {
	// Select text
	$("#content .select, #header .promo .select").each(function() {
		var selectOptionText = $(this).children("select").find("option:selected").text();
		$(this).children('.select-label').text(selectOptionText);
	});
	$("#content select, #header .promo select").change(function() {
		var selectOptionText = $(this).find("option:selected").text();
		$(this).parent().children("span").text(selectOptionText);
	});
	
	// Checkbox
	$(".checkbox").click(function () {
		if (this.nodeName == 'LABEL') {
			var chk = $(this).children('span');
		} else {
			var chk = $(this);
		}
		var input = chk.children();
		
		if(chk.hasClass('checked')) {
			chk.removeClass('checked');
			input.removeAttr('checked');
		} else {
			chk.addClass('checked');
			input.attr('checked', 'checked');
		}
		
	});
	
// Radio button
 $(".radio").click(function () {
  var radio = $(this);
  var input = radio.children();
  var name = input.attr('name');
  var radioButtonsByName = $('input[name="'+name+'"]');
  
  radioButtonsByName.parent().removeClass('checked');
  radioButtonsByName.removeAttr('checked');
  
  radio.addClass('checked');
  input.attr('checked', 'checked');
  //return false;
 });	
	
	// Select all checkboxes which checked by default
	function select(e) {
		if (e.length > 0) {
			e.addClass('checked');
		}
		return false;
	}
	jQuery.each($("input:checked"), function () {select($(this).parent())});
	
	// Input field placeholders
	$('#sidebar fieldset input[type="text"]').focus(function () {
		if (typeof $(this).attr('placeholder') == 'undefined' || $(this).attr('placeholder') == $(this).val()) {
			$(this).attr('placeholder', $(this).val());
			$(this).val();
			$(this).attr('value', '');
		}
	}).blur(function () {
		if ($(this).val().length == 0) {
			$(this).attr('value', $(this).attr('placeholder'));
		}
	});
	
});
