(function($) {

	"use strict";


/*	$(window).stellar({
    responsive: true,
    parallaxBackgrounds: true,
    parallaxElements: true,
    horizontalScrolling: false,
    hideDistantElements: false,
    scrollProperty: 'scroll'
  });*/


	var fullHeight = function() {

		$('.js-fullheight').css('height', $(window).height());
		$(window).resize(function(){
			$('.js-fullheight').css('height', $(window).height());
		});

	};
	fullHeight();

	// loader
	var loader = function() {
		setTimeout(function() { 
			if($('#ftco-loader').length > 0) {
				$('#ftco-loader').removeClass('show');
			}
		}, 100);
	};
	loader();

  var carousel = function() {
		$('.home-slider').owlCarousel({
	    loop:true,
	    autoplay: true,
	    margin:0,
	    animateOut: 'fadeOut',
	    animateIn: 'fadeIn',
	    nav:true,
	    dots: true,
	    autoplayHoverPause: false,
	    items: 1,
	    navText : ["<span class='ion-ios-arrow-back'></span>","<span class='ion-ios-arrow-forward'></span>"],
	    responsive:{
	      0:{
	        items:1
	      },
	      600:{
	        items:1
	      },
	      1000:{
	        items:1
	      }
	    }
		});

		$('.carousel-testimony').owlCarousel({
			center: true,
			loop: true,
			items:1,
			margin: 30,
			stagePadding: 0,
			nav: false,
			navText: ['<span class="ion-ios-arrow-back">', '<span class="ion-ios-arrow-forward">'],
			responsive:{
				0:{
					items: 1
				},
				600:{
					items: 2
				},
				1000:{
					items: 3
				}
			}
		});

		$('.carousel-stories').owlCarousel({
	    loop:true,
	    autoplay: true,
	    autoHeight: false,
	    margin:30,
	    nav:true,
	    dots: false,
	    autoplayHoverPause: false,
	    items: 1,
	    navText : ["<p><span class='fa fa-chevron-left'></span></p>","<p><span class='fa fa-chevron-right'></span></p>"],
	    responsive:{
	      0:{
	        items:1
	      },
	      600:{
	        items:1
	      },
	      1000:{
	        items:1
	      }
	    }
		});

	};
	carousel();

/*	$('nav .dropdown').hover(function(){
		console.log('aaa',$(this).prop('id'));
		var $this = $(this);
		// 	 timer;
		// clearTimeout(timer);
		$this.addClass('show');
		$this.find('> a').attr('aria-expanded', true);
		// $this.find('.dropdown-menu').addClass('animated-fast fadeInUp show');
		$this.find('.dropdown-menu').addClass('show');
	}, function(){
		var $this = $(this);
			// timer;
		// timer = setTimeout(function(){
			$this.removeClass('show');
			$this.find('> a').attr('aria-expanded', false);
			// $this.find('.dropdown-menu').removeClass('animated-fast fadeInUp show');
			$this.find('.dropdown-menu').removeClass('show');
		// }, 100);
	});*/
	$('nav .dropdown').click(function(){
		console.log('aaa',$(this).prop('id'));
		var $this = $(this);
		// 	 timer;
		// clearTimeout(timer);
		$this.addClass('show');
		$this.find('> a').attr('aria-expanded', true);
		// $this.find('.dropdown-menu').addClass('animated-fast fadeInUp show');
		$this.find('.dropdown-menu').addClass('show');
	}, function(){
		var $this = $(this);
			// timer;
		// timer = setTimeout(function(){
			$this.removeClass('show');
			$this.find('> a').attr('aria-expanded', false);
			// $this.find('.dropdown-menu').removeClass('animated-fast fadeInUp show');
			$this.find('.dropdown-menu').removeClass('show');
		// }, 100);
	});


	$('#dropdown04').on('show.bs.dropdown', function () {
//	  console.log('show');
	});

	// magnific popup
	$('.image-popup').magnificPopup({
    type: 'image',
    closeOnContentClick: true,
    closeBtnInside: false,
    fixedContentPos: true,
    mainClass: 'mfp-no-margins mfp-with-zoom', // class to remove default margin from left and right side
     gallery: {
      enabled: true,
      navigateByImgClick: true,
      preload: [0,1] // Will preload 0 - before current, and 1 after the current image
    },
    image: {
      verticalFit: true
    },
    zoom: {
      enabled: true,
      duration: 300 // don't foget to change the duration also in CSS
    }
  });

  $('.popup-youtube, .popup-vimeo, .popup-gmaps').magnificPopup({
    disableOn: 700,
    type: 'iframe',
    mainClass: 'mfp-fade',
    removalDelay: 160,
    preloader: false,

    fixedContentPos: false
  });


  var counter = function() {
		
		$('#section-counter').waypoint( function( direction ) {

			if( direction === 'down' && !$(this.element).hasClass('ftco-animated') ) {

				var comma_separator_number_step = $.animateNumber.numberStepFactories.separator(',')
				$('.number').each(function(){
					var $this = $(this),
						num = $this.data('number');
//						console.log(num);
					$this.animateNumber(
					  {
					    number: num,
					    numberStep: comma_separator_number_step
					  }, 7000
					);
				});
				
			}

		} , { offset: '95%' } );

	}
	counter();

	var contentWayPoint = function() {
		var i = 0;
		$('.ftco-animate').waypoint( function( direction ) {

			if( direction === 'down' && !$(this.element).hasClass('ftco-animated') ) {
				
				i++;

				$(this.element).addClass('item-animate');
				setTimeout(function(){

					$('body .ftco-animate.item-animate').each(function(k){
						var el = $(this);
						setTimeout( function () {
							var effect = el.data('animate-effect');
							if ( effect === 'fadeIn') {
								el.addClass('fadeIn ftco-animated');
							} else if ( effect === 'fadeInLeft') {
								el.addClass('fadeInLeft ftco-animated');
							} else if ( effect === 'fadeInRight') {
								el.addClass('fadeInRight ftco-animated');
							} else {
								el.addClass('fadeInUp ftco-animated');
							}
							el.removeClass('item-animate');
						},  k * 50, 'easeInOutExpo' );
					});
					
				}, 500);
				
			}

		} , { offset: '95%' } );
	};
	contentWayPoint();
	$('.appointment_date').datepicker({
	  'format': 'yyyy-mm-dd',
	  'autoclose': true
	});


	$('.appointment_time').timepicker();



})(jQuery);

var search = {
    searchOpen : 0,
    data : function(){
        return $('#kereso').serialize()+'&ko='+search.ko+'&sorrend='+$('#rendezes').val();
    },
    ko : false,
    pos : 0,
    reszletes : function(){
        if(search.searchOpen===0){
            search.searchOpen = 1;
        }else{
            search.searchOpen = 0;
        }
        $('.reszletesKeresoBef').toggle('slow');
    },
    hova : function(){
        return $('#uticel').val();
    },
    delInputText : function(){
        $('#kereso input[type="text"]').each(function(){
            $(this).val('');
        });
        $('#kereso select').each(function(){
            $(this).val('');
        });
    },
    kuld : function(e){
//		console.log(e);
		if(e!=undefined && e=='nem'){
			return false;
		}else{
			$.ajax({
				 type: "POST",
				 url: "/",
				 data: search.data()+"&keres=keres",
				 success: function(msg){
//					 console.log(msg);
					 document.location.href=msg;
				 }
			});
		}
        return false;
    },
    kuld1 : function(e){
		if(e!=undefined && e=='nem'){
			return false;
		}else{
//			console.log(2,search.data());
			$.ajax({
				 type: "POST",
				 url: "/",
				 data: search.data()+"&keres1=keres1",
				 success: function(msg){
	//console.log(msg);
					 document.location.href='http://varavilag.hu'+msg;
				 }
			 });
		}
        return false;
    },
    add : function(element){
        if(!element){
            $('#uticel').css({color:'red'});
            return false;
        }
        $('#uticel').val(element.getAttribute('megnev'));
        $('#uticel_seo').val(element.getAttribute('seo'));
        $('#keresKieg').html('');
        search.ko = true;
/*        if(search.searchOpen===0){
            search.kuld();
        }*/
        return false;
    },
    success : function(msg){
//		console.log($('#uticel').width());
//		console.log(oldal,$('#uticel').width());
		if(oldal=='/')
        	$('#keresKieg').html(msg).css({minWidth:$('#uticel').width()+43,top:($('#uticel').offset().top+$('#uticel').height()+6)+'px',left:$('#uticel').offset().left});
		else
        	$('#keresKieg').html(msg).css({minWidth:$('#uticel').width(),width:$('#uticel').width()+26,top:($('#uticel').offset().top+$('#uticel').height()+6)+'px',left:$('#uticel').offset().left});
 //       console.log(msg);
    },
    loc : function(url){
        location.href=url;
    },
    onkey : function(event){
//		console.log('aaa');
		$('#keresKieg').show();
        $('#uticel').css({color:'#0090bf'});
		var x = event.which || event.keyCode;
//		console.log(x);
		$('.acTiveDiv').removeClass('acTiveDiv');
		if (x == 13){
			if(search.pos>0){
                var text = $('#keresKieg div:nth-child('+search.pos+')').attr('megnev');
                $('#uticel').val(text);
                text = $('#keresKieg div:nth-child('+search.pos+')').attr('seo');
                $('#uticel_seo').val(text);
                search.ko = true;
            }
			$('#keresKieg').html('');
			search.pos = 0;
            
//            search.kuld();
			return false;
		}
		else if (x == 40) {
			var ossz = 0;
			$('#keresKieg div').each(function(){
				ossz++;
			});
			if(ossz>search.pos)
				search.pos++;
			$('#keresKieg div:nth-child('+search.pos+')').addClass('acTiveDiv');
			var text = $('.acTiveDiv').attr('megnev');
			$('#uticel').val(text);
			text = $('.acTiveDiv').attr('seo');
			$('#uticel_seo').val(text);
			search.ok=true;
		}else if (x == 38 && search.pos>0) {
			search.pos--;
			$('#keresKieg div:nth-child('+search.pos+')').addClass('acTiveDiv');
			var text = $('.acTiveDiv').attr('megnev');
			$('#uticel').val(text);
			text = $('.acTiveDiv').attr('seo');
			$('#uticel_seo').val(text);
			search.ok=true;
			if(search.pos===0){
				$('#keresKieg').html('');
				return false;
			}
		}else{
			if($('#uticel').val()===""){
                search.pos = 0;
                return false;
            }
			if(x == 8){
				search.pos = 0;
			}
            $.ajax({
				 type: "POST",
				 url: "/",
				 data: {"hova":search.hova()},
				 success: function(msg){
					 search.success(msg);
				 }
			});
			return false;
		}
		return false;
	}
};
function kalkulacioIndit(x){
//	console.log(x);
	//csomag_id/datum_tol/ellatas_id/szallas_torzs_id/szoba_csoport_id/data/utas_kezel
	//ff becsaliár ---> data
	//utaskezel = 0
  if(!x.akcio_id)
    x.akcio_id = 0;
  var adatok={csomag_id           : x.csomag_id,
              akcio_id            : x.akcio_id,
              datum               : x.datum,
              ellatas_id          : x.ellatas_id,
              szallas_id          : x.szallas_id,
              szcs_id             : x.szcs_id,
              data                : x.data,
              utaskezel           : x.utaskezel,
              partner_csoport_id  : x.partner_csoport_id,
              partner_id          : x.partner_id,
              partner_iroda_id    : x.partner_iroda_id,
              partner_user_id     : x.partner_user_id,
              szallas_idk         : x.szallas_idk,
              gcsoport_id         : x.gcsoport_id,
              csoport_id          : x.csoport_id,
			  /*teszt				  : x.teszt,*/
			  page				  : x.page
              };
	var url='';
/*	console.log('test',x.teszt);
	if(x.teszt*1==1){
	console.log('test',x.teszt);*/
		if(x.szallas_id*1>0)
			url = 'https://foglalas.trevolution.hu/web_foglalas_b13/foglalas.php?adatok='+JSON.stringify(adatok);
		else
			url = 'https://foglalas.trevolution.hu/web_foglalas_b13/foglalas_szn.php?adatok='+JSON.stringify(adatok);
/*	}else{
	//console.log('xx',x);
		if(x.szallas_id*1>0 || x.szcs_id*1>0)
			url = 'https://foglalas.trevolution.hu/web_foglalas_b9/foglalas.php?adatok='+JSON.stringify(adatok);
		else
			url = 'https://foglalas.trevolution.hu/web_foglalas_b9/foglalas_szn.php?adatok='+JSON.stringify(adatok);
	}*/
	$('#kaklDiv').attr('src',url).show();
	$('html,body').animate({
		scrollTop: $('#kaklDiv').offset().top-200
	},{
		complete : function(){
			
		}
	}, 'slow');
//	console.log(url);
//	$('html,body').animate({
//		scrollTop: $('#kaklDiv').offset().top-($(window).height()/10)
//	},{
//		complete : function(){
//			
//		}
//	}, 'slow');
}

var ajanlat = {
    formName : "form-1",
    kotelezoInput : ["vnev","unev","email","tel","mainap"],
    kotelezoCheck : ["GDPR","EDM"],
    hirlevelCheck : "",
    hilevelFelir : 0,
    emaiInput : "email",
    submit : ".SubmitBottomMenuButton",
    emailValid : function(email) {
        var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
        return re.test(email);
    },
    check : function(element){
        element.classList.toggle("elFogadPipaUres");
    },
    checkValid : function(){
        var hiba=0;
        var tomb = ajanlat.kotelezoCheck;
        if($('#'+ajanlat.hirlevelCheck).hasClass("elFogadPipaUres")===false){
            ajanlat.hilevelFelir = 1;
        }else{
            ajanlat.hilevelFelir = 0;
        }
        for(x=0;x<tomb.length;x++){
            if(!$('#'+tomb[x]).prop('checked')){
//console.log(tomb[x],$('#'+tomb[x]).prop('checked'));
                $('#'+tomb[x]).parent().addClass('error');
//								$('#'+tomb[x]).focus();
/*                $('html,body').animate({
                    scrollTop: $('#'+tomb[x]).offset().top-($(window).height()/15)
                }, 'slow');*/
                hiba++;
//                return hiba;
            }      
        }
        return hiba; 
    },
    formValid : function(){
        var hiba=0;
        var tomb = ajanlat.kotelezoInput;
        for(x=0;x<tomb.length;x++){
            if($('#'+tomb[x]).val()==""){
//console.log(tomb[x]);
                $('#'+tomb[x]).addClass('error');
/*								$('#'+tomb[x]).focus();
                $('html,body').animate({
                    scrollTop: $('#'+tomb[x]).offset().top-($(window).height()/15)
                }, 'slow');*/
                hiba++;
//                return hiba;
            }else{
                if(tomb[x] === ajanlat.emailInput){
                    var valid = ajanlat.emailValid($('#'+tomb[x]).val());
                    if(valid === false){
//console.log(tomb[x],'e');
                        $('#'+tomb[x]).addClass('error');
/*												$('#'+tomb[x]).focus();
                        $('html,body').animate({
                            scrollTop: $('#'+tomb[x]).offset().top-($(window).height()/15)
                        }, 'slow');*/
                        hiba++;
//                       return hiba;
                    }
                }else if(tomb[x] === 'mainap'){
									if($('#mainap').val()!=def_mainap){
//console.log(tomb[x],'m',mainap,$('#mainap').val());
										$('#'+tomb[x]).addClass('error');
/*										$('#'+tomb[x]).focus();
										$('html,body').animate({
												scrollTop: $('#'+tomb[x]).offset().top-($(window).height()/15)
										}, 'slow');*/
										hiba++;
//										return hiba;
									}else{
                                        if($('#mainap').val()!=def_mainap){
                                            $('#'+tomb[x]).addClass('error');
    										hiba++;
                                        }
									}
								}
            }
			console.log(hiba,tomb[x]);
        }
        return hiba;
    },
    kuld : function(form_szam){
			console.log(form_szam);
			$('.error').removeClass('error');
			if(form_szam==1 || form_szam==11){
				ajanlat.formName = "form-1";
				ajanlat.kotelezoInput = ["vnev","unev","email","tel","mainap"];
				ajanlat.kotelezoCheck = ["GDPR","EDM"];
			}else if(form_szam==2 || form_szam==12){
				ajanlat.formName = "form-2";
				ajanlat.kotelezoInput = ["vnev","unev","email","tel","kozlekedes","indulasihely","hova","indulas","erkezes","minej","maxej","felnott","mainap"];
				ajanlat.kotelezoCheck = ["GDPR","EDM"];
			}else if(form_szam==98){
				ajanlat.formName = "form-98";
				ajanlat.kotelezoInput = ["vnev","unev","email","tel"];
				ajanlat.kotelezoCheck = ["adatelfogad"];
			}
				var hiba = ajanlat.formValid();
        var hiba1 = ajanlat.checkValid();
        if(hiba === 0 && hiba1 === 0){
            data = $('#'+ajanlat.formName).serialize();
            if(ajanlat.hilevelFelir===1)
                data+='&hilevelFelir='+ajanlat.hilevelFelir;
            data+='&ajanlatKuld=ajanlatKuld';
            //$(ajanlat.submit).hide();
			console.log('most');
            $.ajax({
                type: "POST",
                url: '/',
                data: data,
                success: function(msg){
                    $('html,body').animate({
//                        scrollTop: $('#'+ajanlat.formName).offset().top-($(window).height()/10)
                    },{
                        complete : function(){
                            $('#'+ajanlat.formName).html(msg);
							fbq('track', 'Lead');
                        }
                    }, 'slow');
                    
               }
            });
        }
        return false;
    }

};
function Magazin_Select(){
	var hova = $('#MagazinSelect option:selected').val();
	if(hova!=='')
		document.location.href='/magazin/'+hova;
}
