// career gate. javascripts!

// career gate obj
var cg = {};

// on ready
$(document).ready(function() {
	// apply bindings
	cg.bind();
});

// apply bindings
cg.bind = function(context) {
	// program search form
	$('#program_search form', context).submit(function() {
		// search type selected <option>
		var $selected = $('#program_search_type option:selected');
		// if no selected value
		if (!$selected.attr('value')) {
			// notify
			alert('Please select a program.');
			// and no submit for you
			return false;
		}
		// else forward off
		document.location = $selected.attr('value');
		// and done
		return false;
	});
	// program search <select> decoy
	$('#program_search_type', context).each(function() {
		// the selected option
		var $selected = $(this).children(':selected');
		// decoy id
		var decoy_id = $(this).attr('id') + '_decoy';
		// decoy html
		var decoy_html = '<span id="' + decoy_id + '" class="' + $selected.attr('class') + '">' + $selected.text() + '</span>';
		// add js styles to <select>, add decoy id attr, add decoy after, and add on change listener
		$(this).addClass('program_search_type_js').attr('decoy_id', decoy_id).after(decoy_html).change(function() {
			// the selected option
			var $selected = $(this).children(':selected');
			// update decory text and class
			$('#' + $(this).attr('decoy_id')).text($selected.text()).removeClass().addClass($selected.attr('class'));
		});
	});
	// auto hide input text hints
	$('.input_text.auto_hide_hint', context).each(function() {
		// store original value, apply bindings
		$(this).attr('cg_orig_value', $(this).attr('value')).focus(function() {
			// on focus, if orig value, remove it
			if ($(this).attr('value') == $(this).attr('cg_orig_value')) $(this).attr('value', '').removeClass('auto_hide_hint');
		}).blur(function () {
			// on blur, if no value, put orig value back
			if ($(this).attr('value') == '') $(this).attr('value', $(this).attr('cg_orig_value')).addClass('auto_hide_hint');
		});
	});
};
