(function($){
	"use strict";
    
    
    
function init() {    //sliderSetup(removePreloaderBgd);

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

		$("#blogers-carousel").each(function(){
			$(this).owlCarousel({
				items : 3,
                itemsDesktop : [1199,3], //5 items between 1000px and 901px
                itemsDesktopSmall : [979,2], // betweem 900px and 601px
                itemsTablet: [600,1], //2 items between 600 and 0
                itemsMobile: [479,1],
				navigation : true,
				navigationText: [
				"<i class='icon-chevron-left icon-white'></i>",
				"<i class='icon-chevron-right icon-white'></i>"
				],
				slideSpeed : 300,
				paginationSpeed : 400,
        singleItem:false
			});
		});
		
		$("#about-carousel").each(function(){
			$(this).owlCarousel({
				singleItem:true,
				transitionStyle : "fade",
				pagination: false,
				navigation : false,
				navigationText: [
				"<i class='icon-chevron-left icon-white'></i>",
				"<i class='icon-chevron-right icon-white'></i>"
				],
				slideSpeed : 500,
				paginationSpeed : 500,
			});
		});
    
    $("#blog-slider").each(function(){
			$(this).owlCarousel({
				singleItem:true,
				transitionStyle : "goDown",
				navigation : true,
				autoPlay: false,
				navigationText: [
				"<i class='icon-chevron-left icon-white'></i>",
				"<i class='icon-chevron-right icon-white'></i>"
				],
				slideSpeed : 300,
				paginationSpeed : 400,
			});
		});
    
		/*** Homepage isotop init ***/
		$(function(){
			var $smw = $('#smw-isotope');
			$smw.imagesLoaded(function(){
				if ($(window).width() < 768) {
					$smw.isotope({
						layoutMode: 'masonryHorizontal',
						itemSelector: '.grid-item',
						masonryHorizontal: {
							rowHeight: 300,
							gutter: 10
						}
					});
				} else {
					$smw.isotope({
						layoutMode: 'masonryHorizontal',
						itemSelector: '.grid-item',
						masonryHorizontal: {
							rowHeight: 350,
							gutter: 10
						}
					});	
				}
			});
		});

		/*** Blog isotop *****/
		$(function(){
			var $container = $('#blog_items');
			$container.imagesLoaded(function(){
				$container.isotope({
					masonry: {
						columnWidth: '.blog_box'
					},
					itemSelector : '.blog_box'
				});
				//setTimeout(function(){$('.blog_block_main .container').animate({opacity: "1"}, 1000, "swing");});
			});
			
		//		$container.infinitescroll({
		//
		//			navSelector  : '.wp-pagenavi',    // selector for the paged navigation 
		//
		//			nextSelector : 'a.nextpostslink',  // selector for the NEXT link (to page 2)
		//
		//			itemSelector : '.blog_box',     // selector for all items you'll retrieve
		//
		//			loading: {
		//
		//					finishedMsg: 'Prikazani su svi postovi',
		//
		//					msgText: "Učitavam još postova...",
		//
		//					img: 'http://i.imgur.com/qkKy8.gif'
		//
		//				}
		//
		//			},
		//
		//			// call Isotope as a callback
		//
		//			function(newElements) {
		//
		//				var $newElems = $(newElements);
		//
		//				$newElems.css("opacity",0);
		//
		//				$newElems.imagesLoaded(function(){
		//
		//					$container.isotope('appended', $newElems );
		//
		//					$newElems.css("opacity",1);
		//
		//				});
		//
		//			}
		//
		//		);
		});
    
    
        /****** search btn event ***********/
    
        $("a.search").click(function(){
            $(".search-area").show(); // toggle("slow")           

        });
        $(".search-submit.btn").click(function(){
            $(".search-area").hide();
        });
  

        /****** instragram grid ****************/
        jQuery('#smw-isotope').find('.grid-item').each(function(i,e){if(i%12)$(e).addClass('big');});
				
				/*** About tabs ***/
				$('#about a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
					console.log($(this).data('image'));
					var image_item = $(this).data('image'),
							owl = $("#about-carousel").data('owlCarousel');
					owl.goTo(image_item);
				});
				
				/*** Youtube video popup ***/
				$('.popup-youtube').magnificPopup({
					disableOn: 700,
					type: 'iframe',
					mainClass: 'mfp-fade',
					removalDelay: 160,
					preloader: false,
			
					fixedContentPos: false
				});
				
				/*** Horizontal Nice Scroll ***/
				$("#smw-scroll").niceScroll({
					cursorcolor: "#3f66b0",
					cursoropacitymin: 0, // change opacity when cursor is inactive (scrollabar "hidden" state), range from 1 to 0
					cursoropacitymax: 0, // change opacity when cursor is active (scrollabar "visible" state), range from 1 to 0
					cursorwidth: "12px", // cursor width in pixel (you can also write "5px")
					cursorborder: "0px solid #fff", // css definition for cursor border
					cursorborderradius: "0px", // border radius in pixel for cursor
					touchbehavior: true,
					background: "#fff",
					enablemousewheel: false,
					railpadding: { top: 0, right: 0, left: 0, bottom: 5 }
				});
				// Click SMW arrow right
				$(".smw-next").on("click", function () {
					var isotope_left = $("#smw-isotope").offset().left,
							isotope_width = $("#smw-isotope").width(),
							container_width = $("#smw-scroll").width(),
							remaining = isotope_width + isotope_left,
							diff_remaining = remaining - container_width,
							scroll_step = 0;
					
					if ((diff_remaining) > 0) {
						if ((diff_remaining) < 250) {
							scroll_step = diff_remaining;
						} else {
							scroll_step = 250;
						}
					}
					console.log(Math.abs(isotope_left)+scroll_step);
					$("#smw-scroll").getNiceScroll()[0].doScrollLeft(Math.abs(isotope_left)+scroll_step, 1000);			
				});
				
				// Click SMW arrow left
				$(".smw-prev").on("click", function () {
					var isotope_left = $("#smw-isotope").offset().left,
							scroll_step = 0;
					
					if ((isotope_left) < 0) {
						if (Math.abs(isotope_left) < 250) {
							scroll_step = Math.abs(isotope_left);
						} else {
							scroll_step = 250;
						}
					}
					$("#smw-scroll").getNiceScroll()[0].doScrollLeft(Math.abs(isotope_left)-scroll_step, 1000);			
				});

								
				/*** Scroll Spy ***/
				$('body').scrollspy({ target: '#navbar' });
				$('[data-spy="scroll"]').each(function () {
					var $spy = $(this).scrollspy('refresh');
				})
				
				/*** Main menu navigation ***/
				$('#navbar .navbar-nav a').on('click', function() {
					var clicked = $(this).attr('href');
					if (clicked == "#blog-slider") {
						window.location.href = 'http://my.serbia.travel/blogs';
					} else {
						$("html, body").animate({ scrollTop: $(clicked).offset().top }, 1400);
					}
					return false;
				});
				
				/*** Strelica na dole scroll ***/
				$('.page-scroll').on('click', function() {
					$("html, body").animate({ scrollTop: $('#about').offset().top }, 1400);
					return false;
				});
	}

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