new WOW().init();

jQuery(document).ready(function($) {
	
$(window).bind('load', function() {
	$('#loader').fadeOut(700);
});

$(function () {
  $('[data-toggle="tooltip"]').tooltip()
})


var person = localStorage.getItem('person');


/*============================================
		     Navigation 
==============================================*/

$('.nav-toggle').on('touchstart click', function(e) {
	e.preventDefault();
	$( this ).toggleClass( 'active' );
});

$('#nav').affix({
	//offset: {top: $('.intro').height()-$('.navbar').height()}
});	

$(function dw_hidenav() {
	var headerHeight = $('.navbar').height();
	$(window).on('scroll', { previousTop: 0 },
		function() {
		var currentTop = $(window).scrollTop();
		if (currentTop < this.previousTop) {
			if (currentTop > 0 && $('.navbar').hasClass('fixed')) {
					$('.navbar').addClass('visible');
					$('.site-title a').removeClass('light');
				} else {
					$('.navbar').removeClass('visible fixed');
					$('.site-title a').addClass('light');
				}
		} 
		else {
			$('.navbar').removeClass('visible');
			if (currentTop > headerHeight && !$('.navbar').hasClass('fixed')) $('.navbar').addClass('fixed');
		}
		this.previousTop = currentTop;
		}  
	);
});


/*============================================
		      Carousel 
==============================================*/

$('#caro-lead').carousel({
	interval: 5777,
	wrap: true,
	pause: false
});

function dw_caro(){
	$('#caro-lead').carousel({
		interval: 5777,
		wrap: true,
		pause: false
	});
	var vidout = document.getElementById('tv');
    vidout.play();
}

$('#caro-lead').on('slide.bs.carousel', function(event) {
	$('.carousel-caption').fadeIn(600);
	var consta = $(event.target);
	setTimeout(function() {
		if (consta.find('.item.active').data('id') === 1) {	
			$('#tv').removeClass('unblur').addClass('blur');
			var anistars = new DrawFillSVG({elementId: 'sites'});
			anistars.replay();
			$('#tv').delay(100).queue(function(pauseit){
				var vidin = document.getElementById('tv');
			    vidin.pause();
			    pauseit();
			});
		}
		if (consta.find('.item.active').data('id') === 2) {	
			$('#tv').removeClass('unblur').addClass('blur');
			var anibrain = new DrawFillSVG({elementId: 'brain'});
			anibrain.replay();
			$('#tv').delay(100).queue(function(pauseit){
				var vidin = document.getElementById('tv');
			    vidin.pause();
			    pauseit();
			});
		}
		if (consta.find('.item.active').data('id') === 3) {	
			$('.leader').delay(100).queue(function(closeit){
				dw_caro_hide();
			    closeit();
			});
		}
	}, 10);
});

function dw_caro_hide(){
    $('.leader').fadeTo(500,0, function() {

		$('#caro-lead').carousel('pause');
    })
}

$('#caro-lead').on('slid.bs.carousel', function() {
	$('.carousel-caption').fadeOut(600);
	$('#tv').delay(3200).queue(function(playit){
		$('#tv').addClass('unblur').removeClass('blur');
		var vidout = document.getElementById('tv');
	    vidout.play();
	    playit();
	});
});

$('.caro-grad').appear();
$('.caro-grad').one('appear', dw_appear);
function dw_appear() {
	$('#caro').carousel({
		interval: 5555,
		wrap: false,
		pause: false
	});
	var anima = new DrawFillSVG({elementId: 'sv'});
	anima.replay();
};

$(document).bind('keyup', function(e) {
    if(e.which === 39){
		//$('#caro-lead').carousel('next');
		$('#caro').carousel('next');
    }
    else if(e.which === 37){
		//$('#caro-lead').carousel('prev');
		$('#caro').carousel('prev');
    }
});



/*============================================
		      SVG Animate
==============================================*/

$('#caro').on('slid.bs.carousel', function() {
	$('.active .animac').removeClass('hide-svg fade-svg');
	var animac = new DrawFillSVG({elementId: 'svg-mac'});
	var animac1 = new DrawFillSVG({elementId: 'svg-imac'});
	var animac2 = new DrawFillSVG({elementId: 'svg'});
	animac.replay();
	animac1.replay();
	animac2.replay();
});

$('#caro').on('slide.bs.carousel', function() {
	$('.active #svg-imac.bg').attr('class', 'svg screen');
	$('.active .animac').addClass('fade-svg').delay(1000).queue(function(hideit){
	    $(this).addClass('hide-svg');
	    hideit();
	});
});

$('#caro').on('slid.bs.carousel', function() {
	$('.active #svg-imac.screen').delay(2500).queue(function(screenit){
	    $(this).attr('class', 'bg');
	    screenit();
	});
});


/*============================================
		      Form
==============================================*/

$('#commentform').validate({
	rules: {
		author: {
			required: true,
			minlength: 2
		},
		email: {
			required: true,
			email: true
		},
		comment: {
			required: true,
			minlength: 3
		}
	},
	messages: {
		author: 'Please enter in your name.',
		email: 'Please enter a valid email address.',
		comment: 'Nothing to Say?'
	},
	errorElement: 'div',
	errorPlacement: function(error, element) {
		element.before(error);
	} 
});


/*============================================
		      SmoothState 
==============================================*/


		
/*============================================
		      Calendar
==============================================*/	

$('.calendar').fullCalendar ({
	firstDay : 1,
	height: 345,
	events: [
			{
				title: 'Project',
				start: '2014-09-27',
				end: '2014-10-02'
			},
			{
				title: 'Conf',
				start: '2014-10-11',
				end: '2014-10-13',
				borderColor: 'red'
			},
			{
				title: 'off',
				start: '2014-10-13',
				end: '2014-10-16'	
			},
			{
				title: 'Contract',
				start: '2014-10-16',
				end: '2014-10-31'
			},
			{
				title: 'Contract',
				start: '2014-11-03',
				end: '2014-11-22'
			},
			{
				title: 'Project',
				start: '2014-12-01',
				end: '2014-12-06'
			},
			{
				title: 'Project',
				start: '2014-12-08',
				end: '2014-12-13'
			},
			{
				title: 'Holiday',
				start: '2014-12-22',
				end: '2015-01-05',
				borderColor: 'red'
			},
			{
				title: 'Project',
				start: '2015-01-06',
				end: '2015-01-25'
			},
			{
				title: 'Project',
				start: '2015-01-27',
				end: '2015-02-14'
			},
			{
				title: 'Holiday',
				start: '2015-02-14',
				end: '2015-02-19',
				borderColor: 'red'
			},
			{
				title: 'Project',
				start: '2015-02-19',
				end: '2015-03-07'
			},
			{
				title: 'Contract',
				start: '2015-03-10',
				end: '2015-04-04',
				borderColor: 'blue'
			},
			{
				title: 'Holiday',
				start: '2015-04-04',
				end: '2015-04-11',
				borderColor: 'red'
			},
			{
				title: 'Contract',
				start: '2015-04-11',
				end: '2015-05-16',
				borderColor: 'blue'
			},
			{
				title: 'Contract',
				start: '2015-05-19',
				end: '2015-08-16',
				borderColor: 'blue'
			},
			{
				title: 'Project',
				start: '2015-08-18',
				end: '2015-08-29'
			},
			{
				title: 'Project',
				start: '2015-09-01',
				end: '2015-09-24'
			},
			{
				title: 'Holiday',
				start: '2015-09-25',
				end: '2015-10-03',
				borderColor: 'red'
			},
			{
				title: 'Contract',
				start: '2015-10-06',
				end: '2015-11-28',
				borderColor: 'blue'
			},
			{
				title: 'Holiday',
				start: '2015-12-22',
				end: '2016-01-05',
				borderColor: 'red'
			}
	]
});


		
});