// on dom ready
$(function() {
	
	// i6 fix to enforce max-
	$('div.list .item .item-image img').each(function(i) {
			if ($(this).width() > 120) $(this).css('width','120px');
		});
	
	// hide the content of association
	$('#ass_find .item-content').hide();
	$('#ass_find .item-view').each(function() {
		$(this).click(function(e) {
			$(this).parents().eq(0).next().next().toggle();
			if ($(this).parents().eq(0).next().next().is(':visible')) {
				var career_link = $(this).find('a');
				career_link.text('Click here to hide career and qualifications summary ');
				// hit the view page to increment the view count.
				$.ajax({url: career_link.attr('href')});
			} else $(this).find('a').text('Click here for career and qualifications summary ');
			e.preventDefault();
			return false;
		});
	});
	
	// show/hide default value of input element with the toggle class
	$('input:text.toggle').bind({
		focus: function() {
			if (!this.oldvalue || this.value == this.oldvalue) {
				this.oldvalue = this.value;
				this.value = '';
			}
		},
		blur: function() {
			if (this.value == '') this.value = this.oldvalue;
		}
	});
	
	// fading effects on the social bookmark images
	$('#col-right-social li').css('opacity', 0.75).hover(function() {
		$(this).stop().fadeTo(200, 1);
	}, function() {
		$(this).stop().fadeTo(200, 0.75);
	});
	
	// remove message box after few seconds (if any)
	if ($('p.message').size()) {
		var t = setTimeout(function() {
			$('p.message').slideUp(500, function() {
				$(this).remove();
			});
		}, 5000);
	};
	
	// do basic required field check on form prior submission
	$('form').submit(function(event) {		
		// loop through required field
		$(':input.required', this).each(function() {
			// empty value?
			if (!this.value) {
				alert($(this).addClass('error').prevAll('label').eq(0).text()+' is a required field!');
				event.preventDefault();
				return false;
			};
			// email check?
			if ($(this).is('.email') && this.value.search(/^[^@]+@[^@]+.[a-z]{2,}$/i) == -1) {
				alert($(this).addClass('error').prevAll('label').eq(0).text()+' is not a valid Email adress!');
				event.preventDefault();
				return false;
			};
		});
	});
	
	// is there any hyperlinks to open in a new window
	$('a.new_window').click(function(e) {
		e.preventDefault();
		window.open($(this).attr('href'));
	});
});

