htmlbody = $('html,body');

function goToByScroll(dataslide) {
		htmlbody.animate({
				scrollTop: $(dataslide).offset().top-104
		}, 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');
		}
	}, { offset: -300 });
	
	$('.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);
		$('.registration-area').css("opacity", "1");
		$('#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++) {
		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 : 8,
		itemsDesktop : [1200,8],
		itemsDesktopSmall : [991,5],
		itemsTablet: [767,2],
		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,
		itemsDesktop : [1200,4],
		itemsDesktopSmall : [991,3],
		itemsTablet: [767,2],
		autoPlay: 3700,
		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,
		itemsDesktop : [1200,3],
		itemsDesktopSmall : [991,2],
		itemsTablet: [767,1],
		autoPlay: 3700,
		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
	});

});