(function($){
	"use strict";

	function menuResize () {
		if (($(window).scrollTop() < 300) && ($(window).width()>1199)) {
			$('.navbar-brand').removeClass('small-logo');
			$('.navbar-brand').addClass('big-logo');
			$('.navbar-nav > li > a').css("line-height", "81px");
			$('.glyphicon-search').css("line-height", "81px");
			$('#search-area').css("height", "81px");
			$('.search-field').css("height", "81px");
			$('.search-close').css("height", "81px");
		} else {
			$('.navbar-brand').removeClass('big-logo');
			$('.navbar-brand').addClass('small-logo');
			if ($(window).width()<768) {
				$('.navbar-nav > li > a').css("line-height", "40px");
				$('.glyphicon-search').css("line-height", "40px");
			} else {
				$('.navbar-nav > li > a').css("line-height", "50px");
				$('.glyphicon-search').css("line-height", "50px");
				$('#search-area').css("height", "50px");
				$('.search-field').css("height", "50px");
				$('.search-close').css("height", "50px");
			}
		}
	}

	function onFormSumbit(evt){
		evt.preventDefault();

		var form = document.getElementById('contactForm'),
		formData = {};

		for(var e=0; e < form.elements.length; e++){
			var inpName = form.elements[e].name,
			inpValue = form.elements[e].value;
			/* if(inpValue == ''){
				alert('Sva polja su obavezna');
				return false;
			} */
			formData[inpName] = inpValue;
		}

		$.ajax({
			method		: "POST",
			url			: "./mail.php",
			dataType	: "json",
			data		: JSON.stringify(formData),
			success		: function(data){
				console.log(data);
				alert(data.message);
			}
		})
		.done(function( msg ) {
			// alert( "Data Saved: " + msg );
		});

		return false;
	}

	function init() {    //sliderSetup(removePreloaderBgd);
		$(window).on('resize', menuResize).trigger('resize');
		$(window).on('scroll', menuResize);
		$('#contactForm').on('submit', onFormSumbit);

		$(".owl-carousel").each(function(){
			$(this).owlCarousel({
				items : $(this).data('items'),
				navigation : true,
				navigationText: [
				"<i class='icon-chevron-left icon-white'></i>",
				"<i class='icon-chevron-right icon-white'></i>"
				],
				slideSpeed : 300,
				paginationSpeed : 400
			});
		});
	}

	$(document).ready(init);
})(jQuery);