$(document).ready(function(){
	$('div','#column2-content-short,#column2-content-ourwork,#column2-content-ourapproach').hide().css({'position':'absolute'});
	
	$('.work-menu li a').click(function(){
		var toggle = $(this).attr('rel');
		showDiv(toggle);
		$('#picture_'+toggle).delay(2000).fadeToggle(600);
		$(this).blur();
		return false;
	});
	
	$('.page-menu li a').click(function(){
		$('.title-image img').fadeIn();
	});
	
	$('a').click(function(){
		$(this).blur();
	});
	
	$('#frmContact').submit(function(index, domEle) {
		
		var thisObj = this;
		
		$.ajax({
			url: "send_mail.php",
			global: false,
			type: "POST",
			data: "func=doContact&"+$(this).serialize(),
			cache: false,
			dataType: "json",
			beforeSend: function(result) {
				$(thisObj).find('.submit')
					.attr('orig', $(thisObj).find('.submit').val())
					.val('Please Wait...')
					.attr('disabled', 'disabled');
				$('#errorBar', thisObj).slideUp('fast');
				$(thisObj).find('.frmErr').remove();
			},
			success: function(data, textStatus) {
				
				if (data.success) {
					$(thisObj).html(data.success);
					setTimeout('window.parent.$.prettyPhoto.close();', 3000);
				}
				
				if(data.errors['token']) {
					
					alert(data.errors['token']);
					
				} else if (data.errors) {
					for (var i in data.errors) {
						$('#'+i, thisObj).closest('tr').find('td:last').append('<div title="'+data.errors[i]+'" class="frmErr" style="display: none;"></div>');
					}
					if (data.msg) {
						$('#errorBar', thisObj).html(data.msg).slideDown('fast');
					}
					$('.frmErr').fadeIn('slow');
					
					$(thisObj).find('.submit').val($(thisObj).find('.submit').attr('orig')).attr('disabled', '');
					
				} else if (data.alertMsg) {
					
					alert(data.alertMsg);
					$(thisObj).find('.submit').val('Try Again').attr('disabled', '');
					
				} else {
					
					alert(textStatus);
					
				}
			}
		});
		
        return false;
		
	});
	
	$('#frmContact2').submit(function(index, domEle) {
		
		var thisObj = this;
		
		$.ajax({
			url: "online_form.php",
			global: false,
			type: "POST",
			data: "func=doContact&"+$(this).serialize(),
			cache: false,
			dataType: "json",
			beforeSend: function(result) {
				$(thisObj).find('.submit')
					.attr('orig', $(thisObj).find('.submit').val())
					.val('Please Wait...')
					.attr('disabled', 'disabled');
				$('#errorBar', thisObj).slideUp('fast');
				$(thisObj).find('.frmErr').remove();
			},
			success: function(data, textStatus) {
				
				if (data.success) {
					$(thisObj).html(data.success);
					setTimeout('window.parent.$.prettyPhoto.close();', 3000);
				}
				
				if(data.errors['token']) {
					
					alert(data.errors['token']);
					
				} else if (data.errors) {
					for (var i in data.errors) {
						$('#'+i, thisObj).closest('tr').find('td:last').append('<div title="'+data.errors[i]+'" class="frmErr" style="display: none;"></div>');
					}
					if (data.msg) {
						$('#errorBar', thisObj).html(data.msg).slideDown('fast');
					}
					$('.frmErr').fadeIn('slow');
					
					$(thisObj).find('.submit').val($(thisObj).find('.submit').attr('orig')).attr('disabled', '');
					
				} else if (data.alertMsg) {
					
					alert(data.alertMsg);
					$(thisObj).find('.submit').val('Try Again').attr('disabled', '');
					
				} else {
					
					alert(textStatus);
					
				}
			}
		});
		
        return false;
		
	});
		
});

function showDiv(d) {
	$('div','#column2-content-short,#column2-content-ourwork,#column2-content-ourapproach').fadeOut();
	$('#'+d).fadeIn();
}
