htmlbody = $('html,body');

function goToByScroll(dataslide) {
		htmlbody.animate({
				scrollTop: $(dataslide).offset().top
		}, 1200, 'linear');
		 $.sidr('close', 'sidr-main');
}

jQuery(document).ready(function ($) {
	
	//chromeSmoothScroll.init();
	
	$('#responsive-menu-button').sidr({
		name: 'sidr-main',
		source: '.nav'
	});
	
	$(document).on('click', '.nav li a', function (e) {
			e.preventDefault();
			dataslide = $(this).attr('href');
			goToByScroll(dataslide);
	});
	$(document).on('click', '.sidr-inner li a', function (e) {
			e.preventDefault();
			dataslide = $(this).attr('href');
			goToByScroll(dataslide);
	});
	$(document).on('click', '.go-down', function (e) {
			e.preventDefault();
			goToByScroll('.intro-menu');
	});
	
	function goDownArrowPositioning () {
		var goDownPosition = $(window).height()-90;
		$('.go-down').css("top", goDownPosition+"px");
	}
	goDownArrowPositioning();
	$(window).resize(function() {
		goDownArrowPositioning();
	});
	
	// Go down arrows show/hide
	$('#countdown').waypoint(function(direction) {
		$('.go-down img').removeClass('animated');
		$('.go-down img').removeClass('fadeOut');
		$('.go-down img').removeClass('fadeIn');
		$('.go-down img').addClass('animated');
		if (direction == "down") {
			$('.go-down img').addClass('fadeOut');
			$('.intro-slogan h3').addClass('animated');
			$('.intro-slogan h3').addClass('flipInX');
		} else {
			$('.go-down img').addClass('fadeIn');
		}
	});
	
	$('.intro-menu').waypoint(function(direction) {
		if (direction == "down") {
			$('.intro-menu').addClass('fixed');
		} else {
			$('.intro-menu').removeClass('fixed');
		}
	});
	
	setTimeout(function() {
		$('#intro-night').fadeOut(1500);
		$('.digitalnight-logo-img').fadeIn(800);
		$('#digitalnight-logo-night').fadeOut(1500);
	}, 1800);
	
	$('.social-item').each(function(index){
		var timing = 3000+index*150;
		setTimeout(function() {
			$('.social-item_'+(index+1)).addClass('animated');
			$('.social-item_'+(index+1)).addClass('flipInX');
		}, timing);
	});
	
	
	$('.contact-button').magnificPopup({
		type:'inline',
		fixedContentPos: false,
		fixedBgPos: true,

		overflowY: 'auto',
		
		closeOnBgClick: true,
		closeBtnInside: false,
		preloader: false,
		
		midClick: true,
		removalDelay: 300,
		mainClass: 'my-mfp-slide-bottom'
	});
	
	function blurAnimationWaypoint (selector, op, os) {
		$(selector).waypoint(function(direction) {
			$('#intro-blur').css({opacity: op});
		}, { offset: os });
	}
	
	for (i = 0; i < 11; i++) {
		// console.log(i + ' - ' + (1/10)*(i) + ' - ' + (10+i*4))
		blurAnimationWaypoint('#bgd-trigger', (1/10)*(i), (5+i*5)+'%');
	}
	
	// Image slider
	$("#image_carousel").owlCarousel({
		navigation : true,
		navigationText: [
			"<span class='nav-button nav-button-left'><img src='images/slide-arrow-left.png' alt='left' /></span>",
			"<span class='nav-button nav-button-right'><img src='images/slide-arrow-right.png' alt='right' /></span>"
		],
		slideSpeed : 300,
		paginationSpeed : 400,
		autoPlay: 4000,
		singleItem:true,
		transitionStyle : "fadeUp"
	});
	
	// Event countdown plugin
	var austDay = new Date("July 25, 2014 20:00:00");
	$('#countdown').countdown({until: austDay, layout: '<div class="col-xs-6 col-sm-3 counter-box counter-box_1"><div class="counter-label">Dana</div><div class="counter-item counter-days">{dn}</div></div><div class="col-xs-6 col-sm-3 counter-box counter-box_2"><div class="counter-label">Sati</div><div class="counter-item counter-hours">{hn}</div></div><div class="col-xs-6 col-sm-3 counter-box counter-box_3"><div class="counter-label">Minuta</div><div class="counter-item counter-minutes">{mn}</div></div><div class="col-xs-6 col-sm-3 counter-box counter-box_4"><div class="counter-label">Sekundi</div><div class="counter-item counter-seconds">{sn}</div></div>'});
	$('#year').text(austDay.getFullYear());
	
	// Sponsors Carousel
	var sponzori = $("#sponzori-slider");
	sponzori.owlCarousel({
		items : 6, //10 items above 1200px browser width
		itemsDesktop : [1200,5], //5 items between 1200px and 993px
		itemsDesktopSmall : [991,4], // betweem 992px and 601px
		itemsTablet: [767,2], //2 items between 600 and 0
		autoPlay: 2500,
		navigation: true,
		navigationText: [
			"<span class='nav-button scroller-button-left'><img src='images/slide-arrow-left-dark.png' alt='left' /></span>",
			"<span class='nav-button scroller-button-right'><img src='images/slide-arrow-right-dark.png' alt='right' /></span>"
		],
		pagination: false,
		paginationSpeed: 1500,
		stopOnHover: false
	});
	
	// Partners Carousel
	var partneri = $("#partneri-slider");
	partneri.owlCarousel({
		items : 4, //10 items above 1200px browser width
		itemsDesktop : [1200,4], //5 items between 1200px and 993px
		itemsDesktopSmall : [991,3], // betweem 992px and 601px
		itemsTablet: [767,2], //2 items between 600 and 0
		autoPlay: 2500,
		navigation: true,
		navigationText: [
			"<span class='nav-button scroller-button-left'><img src='images/slide-arrow-left-light.png' alt='left' /></span>",
			"<span class='nav-button scroller-button-right'><img src='images/slide-arrow-right-light.png' alt='right' /></span>"
		],
		pagination: false,
		paginationSpeed: 1500,
		stopOnHover: false
	});
	
	// Program Carousel
	var program = $("#program-slider");
	program.owlCarousel({
		items : 3, //10 items above 1200px browser width
		itemsDesktop : [1200,3], //5 items between 1200px and 993px
		itemsDesktopSmall : [991,2], // betweem 992px and 601px
		itemsTablet: [767,1], //2 items between 600 and 0
		autoPlay: 2500,
		navigation: true,
		navigationText: [
			"<span class='nav-button scroller-button-left'><img src='images/slide-arrow-left-dark.png' alt='left' /></span>",
			"<span class='nav-button scroller-button-right'><img src='images/slide-arrow-right-dark.png' alt='right' /></span>"
		],
		pagination: false,
		paginationSpeed: 1500,
		stopOnHover: false
	});

});