$(function(){		
	$('input[type="radio"]').addClass('radio');
	$('input[type="checkbox"]').addClass('radio');
	$('table.certifications input#add-certification, table.certifications input.edit-certification, table.certifications input.remove-certification')
		.css({'opacity':'0.8'})
		.hover(function(){
			$(this).css({'opacity':'1'});
		},function(){
			$(this).css({'opacity':'0.8'});
		});
	// <select> Toggler for Certifications
	$('.toggledItems').each(function(){
		$('li:not(:first)',this).hide();
	});
	$('select.toggler').live('change',function(){
		$val = $(this).val();
		$toggledItems = $(this).parent().next().find('.toggledItems');
		$toggledItems.find('li').each(function(index){
			var $order = index+1;
			if($val == $order) {
				$toggledItems.find('li').hide();
				$(this).fadeIn();
			} else if($val == '0') {
				$toggledItems.find('li:not(:first)').hide();
			}
		});
	});
	
	// Cancel Function
	$('input#cancel').click(function(){
		var $href = $(this).attr('href');
		window.location = $href;
		return false;
	});

	// Add Another <textarea>
	$('input[value="ADD"]').click(function(){
		var $location = $(this).parent('tr');
		var $num = $target.size() + 1;
		$(this).parent().clone().insertAfter($(this));
		return false;
	});
	
	$('a.add-another-link').click(function(){
		// Vars (set these)
		var $location = $(this).prev();
		var $target = $('textarea.jobdesc');
		var $name = 'job_description_';
		var $num = $target.size() + 1;
		// Function
		$location.clone().insertAfter($location).addClass('cloned').attr('id',$name + $num).attr('name',$name + $num);
		return false;
	});
	
	$('#job_other_degree').hide();
	$('select#job_degree').change(function(){
		if($(this).val() == 'other') {
			$('#job_other_degree').fadeIn();
		} else {
			$('#job_other_degree').hide();
		}
	});
	
	// Smart Salary <select>
	$('select.low').live('change',function(){
		$value = $(this).val();
		$('select.high option').show();
		$('select.high option').each(function(){
			if(Number($(this).val()) <= Number($value)){
				$(this).hide();
			}
		});
	});
	
	// Add Another <textarea>
	$('a.add-another-link').live('click',function(){
		// Vars (set these)
		var $location = $(this).prev();
		var $target = $('textarea.jobdesc');
		var $name = 'job_description_';
		var $num = $target.size() + 1;
		// Function
		$location.clone().insertAfter($location).addClass('cloned').attr('id',$name + $num).attr('name',$name + $num);
		return false;
	});
	// Autotab for phone fields
	if ($('.phone').length > 0) {
		$.getScript('js/jquery.autotab.js',function(){ 
			// Phone
			$('input[name=phone_a]').autotab({ target: 'phone_b', maxlength: 3, format: 'numeric' });
			$('input[name=phone_b]').autotab({ target: 'phone_c', previous: 'phone_a', maxlength: 3, format: 'numeric' });
			$('input[name=phone_c]').autotab({ previous: 'phone_b', maxlength: 4, format: 'numeric' });
			// Contact Phone
			$('input[name=c_phone_a]').autotab({ target: 'c_phone_b', maxlength: 3, format: 'numeric' });
			$('input[name=c_phone_b]').autotab({ target: 'c_phone_c', previous: 'c_phone_a', maxlength: 3, format: 'numeric' });
			$('input[name=c_phone_c]').autotab({ previous: 'c_phone_b', maxlength: 4, format: 'numeric' });
			// Job Phone
			$('input[name=j_phone_a]').autotab({ target: 'j_phone_b', maxlength: 3, format: 'numeric' });
			$('input[name=j_phone_b]').autotab({ target: 'j_phone_c', previous: 'j_phone_a', maxlength: 3, format: 'numeric' });
			$('input[name=j_phone_c]').autotab({ previous: 'j_phone_b', maxlength: 4, format: 'numeric' });
			// Edit Job Phone
			$('input[name=contact_phone_a]').autotab({ target: 'contact_phone_b', maxlength: 3, format: 'numeric' });
			$('input[name=contact_phone_b]').autotab({ target: 'contact_phone_c', previous: 'j_phone_a', maxlength: 3, format: 'numeric' });
			$('input[name=contact_phone_c]').autotab({ previous: 'contact_phone_b', maxlength: 4, format: 'numeric' });
		});
	}
	$('p.switch label:not(#apply-email)').hide();
	$('select[name="application_type"]').change(function(){
		$('p.switch label').hide();
		$('#application_method').hide().fadeIn();
		if($(this).val() == 'E') {
			$('#apply-email').fadeIn();
		} else if($(this).val() == 'F') {
			$('#apply-fax').fadeIn();
		} else {
			$('#apply-hyperlink').fadeIn();
		}
	});
	
	// Blocks (originally developed for use with Testimonials Editor Component) */
	$('.blocks').each(function(){
		$(this).find('li:even').addClass('odd');
	});
	
	// Tooltips
	if ($('.ttip').length > 0) {
		$.getScript('/js/jquery.simpletip-1.3.1.pack.js',function(){ 
			// Get & Store Tooltip Content
			tooltipData = new Array();
			$('.ttip-bubble').each(function(){
				var html = $(this).html();
				tooltipData.push(html);
			});
			$('.ttip').each(function(i){
				$(this).simpletip({ 
					fixed: true, 
					position: 'right',
					content: tooltipData[i]
				}).removeAttr('title');
			});
			
		});
	}
});
