jQuery(function( $ ){
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		DD_belatedPNG.fix('.frame ,.col span');
	};
	$('.banners ul li:last-child').addClass( 'last' );

	
	$(".extLink").fancybox({
		 'width' : 550,
		 'height' : 400,
		 'autoScale' : false,
		 'transitionIn' : 'none',
		 'transitionOut' : 'none',
		 'type' : 'iframe'
	 });
	$.fn.change_slide = function(item) {
		$(this).each(function() {
			var cnt = $(this);
			var total = cnt.find(item).length;
			if (total > 1) {
				setInterval(function() {
					var current = cnt.find(item).index(cnt.find(item + ':visible'));
					if (current < total - 1) {
						current++;
					} else {
						current = 0;
					}
					cnt.find(item + ':visible').fadeOut("slow");
					cnt.find(item + ':eq(' + current + ')').fadeIn("slow");
				}, window.binfo*1000);
			}
		});
	}
	$('.content-area .holder').change_slide('.item');

	//contact form validation
	$('.validate').submit(function() {
			var valid = true;
			var errors = '';
			 
			$(this).find('.required').each(function() {
				if (!$(this).val().replace(/^\s*|\s$/, '') || $(this).val() == $(this).attr('title')) {
					$(this).addClass('field-error');
					errors += 'The "' + $(this).attr('title') + '" field is required\n';
					if (valid) {
						$(this).focus();
					}
					valid = false;
				} else {
					$(this).removeClass('field-error');
				}
			});
			
			$(this).find('.email').each(function() {
				var pattern = /^([A-Za-z0-9_\-\.\+])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
				
				if (!pattern.test($(this).val())) {
					$(this).addClass('field-error');
					errors += 'The email address you entered is not valid\n';
					if (valid) {
						$(this).focus();
					}
					valid = false;
				} else {
					$(this).removeClass('field-error');
				}
			});
			
			if (!valid) {
				alert(errors + '\n ');
			}
			
			return valid;
	});


	$(document).ready(function () {
		$('div.team a').hover(function () {
			var userInfo = $(this).next().html();
			var tooltipBox = $('<div class="tooltip"></div>'); 
			$(this).parent().append(tooltipBox); 
			$(tooltipBox).animate({'opacity' : 'toggle', 'top' : '80px' }, 200).html(userInfo).append('<div class="arrow"></div>'); 
		}, function(){
			$('div.tooltip').remove();
		});
	});

});
