$(document).ready(function() {
	if ($("#map").length > 0) {
		var myOptions = {
			zoom: 4,
			center: new google.maps.LatLng(49.468124, 16.523438),
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		var map = new google.maps.Map($('#map')[0], myOptions);
		var marker = new google.maps.Marker({
			position: new google.maps.LatLng(47.837638, 35.14087),
			title: 'AZBiX IT Outsourcing Agency'
		});
		marker.setMap(map);
		var bounds = new google.maps.LatLngBounds();
	}
});

function doLightMenuItem(selector) {
	$('#main-menu-block-'+selector).css('backgroundPosition', 'center -124px');
}
function doDarkMenuItem(selector) {
	$('#main-menu-block-'+selector).css('backgroundPosition', 'center top');
}

$('#main-menu-item-company').mouseover(function() {
	doLightMenuItem('company');
});
$('#main-menu-item-company').mouseout(function() {
	doDarkMenuItem('company');
});
$('#main-menu-item-services').mouseover(function() {
	doLightMenuItem('services');
});
$('#main-menu-item-services').mouseout(function() {
	doDarkMenuItem('services');
});
$('#main-menu-item-benefits').mouseover(function() {
	doLightMenuItem('benefits');
});
$('#main-menu-item-benefits').mouseout(function() {
	doDarkMenuItem('benefits');
});
$('#main-menu-item-contact').mouseover(function() {
	doLightMenuItem('contact');
});
$('#main-menu-item-contact').mouseout(function() {
	doDarkMenuItem('contact');
});

$('#button-send-feedback').mouseover(function() {
	$('#button-send-feedback').css('color', '#000');
	$('#button-send-feedback').css('backgroundPosition', 'center -30px');
});
$('#button-send-feedback').mouseout(function() {
	$('#button-send-feedback').css('color', '#fff');
	$('#button-send-feedback').css('backgroundPosition', 'center top');
});
$('#button-send-feedback').click(function() {
	$.ajax({
		url: '/go/sendInTouch',
		type: 'post',
		data: ({
			name: $('#emailus-name').val(),
			email: $('#emailus-email').val(),
			text: $('#emailus-text').val()}),
		success: function(data) {
			var objAjaxRresponse = jQuery.parseJSON(data);
			if (objAjaxRresponse.error == '100') {
				$('#basic-modal-content').empty();
				$('#basic-modal-content').append('<h3>Server is unable to send your message at this time. Please, try again later.</h3>');
				$('#basic-modal-content').modal();
			}
			else if (objAjaxRresponse.error == '200') {
				var arrWrongFields = [];
				if (objAjaxRresponse.data.name) {
					arrWrongFields.push('Name');
				}
				if (objAjaxRresponse.data.email) {
					arrWrongFields.push('Email');
				}
				if (objAjaxRresponse.data.text) {
					arrWrongFields.push('Message');
				}
				$('#basic-modal-content').empty();
				$('#basic-modal-content').append('<h3>The following form fileds are not valid:</h3>');
				$('#basic-modal-content').append('<p>'+arrWrongFields.join(', ')+'</p>');
				$('#basic-modal-content').modal();
			}
			else {
				$('#emailus-name').val('');
				$('#emailus-email').val('');
				$('#emailus-text').val('');
				$('#basic-modal-content').empty();
				$('#basic-modal-content').append('<h3>Your message was sent. Thank you for the feedback.</h3>');
				$('#basic-modal-content').modal();
			}
		},
		error: function() {
			$('#basic-modal-content').empty();
			$('#basic-modal-content').append('<h3>Server is unable to send your message at this time. Please, try again later.</h3>');
			$('#basic-modal-content').modal();
		}
	});
});

$('#button-send-contactform').mouseover(function() {
	$('#button-send-contactform').css('color', '#000');
	$('#button-send-contactform').css('backgroundPosition', 'center -30px');
});
$('#button-send-contactform').mouseout(function() {
	$('#button-send-contactform').css('color', '#fff');
	$('#button-send-contactform').css('backgroundPosition', 'center top');
});
$('#button-send-contactform').click(function() {
	$.ajax({
		url: '/go/sendFeedback',
		type: 'post',
		data: ({
			name: $('#contactform-name').val(),
			company: $('#contactform-company').val(),
			email: $('#contactform-email').val(),
			text: $('#contactform-text').val()}),
		success: function(data) {
			var objAjaxRresponse = jQuery.parseJSON(data);
			if (objAjaxRresponse.error == '100') {
				$('#basic-modal-content').empty();
				$('#basic-modal-content').append('<h3>Server is unable to send your message at this time. Please, try again later.</h3>');
				$('#basic-modal-content').modal();
			}
			else if (objAjaxRresponse.error == '200') {
				var arrWrongFields = [];
				if (objAjaxRresponse.data.name) {
					arrWrongFields.push('Name');
				}
				if (objAjaxRresponse.data.company) {
					arrWrongFields.push('Company');
				}
				if (objAjaxRresponse.data.email) {
					arrWrongFields.push('Email');
				}
				if (objAjaxRresponse.data.text) {
					arrWrongFields.push('Message');
				}
				$('#basic-modal-content').empty();
				$('#basic-modal-content').append('<h3>The following form fileds are not valid:</h3>');
				$('#basic-modal-content').append('<p>'+arrWrongFields.join(', ')+'</p>');
				$('#basic-modal-content').modal();
			}
			else {
				$('#contactform-name').val('');
				$('#contactform-company').val('');
				$('#contactform-email').val('');
				$('#contactform-text').val('');
				$('#basic-modal-content').empty();
				$('#basic-modal-content').append('<h3>Your message was sent. Thank you for the feedback.</h3>');
				$('#basic-modal-content').modal();
			}
		},
		error: function() {
			$('#basic-modal-content').empty();
			$('#basic-modal-content').append('<h3>Server is unable to send your message at this time. Please, try again later.</h3>');
			$('#basic-modal-content').modal();
		}
	});
});
