
currentPosition = 0;
timeOut = true;
canScroll = true;

browserWidth = 0;

init = function() {

	moveMenu();
	

	$(window).scroll(function(e) {
		if (canScroll) {
			if ($(window).scrollTop() > 558) {
				$('#menu').css({top: -30, position:'fixed'});
			}
			if ($(window).scrollTop() < 558) {
				$('#menu').css({top: 527, position:'absolute'});
			}
		}
	});
	
	$('#menu li.principle').hover(
		function() {
			$(this).css({zIndex:2});
			$(this).find('div').show();
		},
		function() {
			$(this).css({zIndex:4});
			$(this).find('div').hide();
		}
	);

	animateBottle();

	// load youtube iframes
	setTimeout(function() {
		//http://www.youtube.com/watch?v=iLiAzhYKXKw shop
		// http://www.youtube.com/watch?v=hd7T-uXrCkk bus stop
		// http://www.youtube.com/watch?v=nT3t0s4p4to runner
		// http://www.youtube.com/watch?v=BWHk5ZWSF1A office
  	$('#iLiAzhYKXKw').html('<iframe class="youtube" width="400" height="244" src="http://www.youtube.com/embed/iLiAzhYKXKw?rel=0&wmode=transparent" frameborder="0" allowfullscreen></iframe>');
  	$('#hd7T-uXrCkk').html('<iframe class="youtube" width="400" height="244" src="http://www.youtube.com/embed/hd7T-uXrCkk?rel=0&wmode=transparent" frameborder="0" allowfullscreen></iframe>');
  	$('#nT3t0s4p4to').html('<iframe class="youtube" width="400" height="244" src="http://www.youtube.com/embed/nT3t0s4p4to?rel=0&wmode=transparent" frameborder="0" allowfullscreen></iframe>');
  	$('#BWHk5ZWSF1A').html('<iframe class="youtube" width="400" height="244" src="http://www.youtube.com/embed/BWHk5ZWSF1A?rel=0&wmode=transparent" frameborder="0" allowfullscreen></iframe>');
	}, 2500);
	// load facebook objects
	setTimeout(function() {
		(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=234483893274555"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));
	}, 3500);
	setTimeout(function() {
		$('.fb_like_container').show();
	}, 4500);
	
	setTimeout(function() {
		
		  (function() {
		    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
		    po.src = 'https://apis.google.com/js/plusone.js';
		    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
		  })();
		
	}, 4500);
	
	//alexs bit
	
	browserWidth = $(window).width();
	boxWidth = $('#copyright_box').width();
	copyrightBoxLeftMargin = (browserWidth - boxWidth) / 2;
	$('#copyright_box').css({marginLeft:copyrightBoxLeftMargin});
	
	$('#copyright_icon').click(function(){
		$('#copyright_box').animate({bottom:0}, 1000);
		$('#copyright_icon').animate({bottom:-100},1000);
	});
	
	$('#copyright_close').click(function(){
		$('#copyright_box').animate({bottom:-63}, 1000);
		$('#copyright_icon').animate({bottom:15},1000);
	});
	
}

animateBottle = function() {

	bottle = $("#gurus_hand_and_bottle-img");
	
	setTimeout(function() {
	  bottle.animate({left:'+=20'},100);
	  bottle.animate({left:'-=20'},100);
	  bottle.animate({left:'+=20'},100);
	  bottle.animate({left:'-=20'},100);
	  bottle.animate({left:'+=20'},100);
	  bottle.animate({left:'-=20'},100);
	  bottle.animate({left:'+=20'},100);
	  bottle.animate({left:'-=20'},100);
	}, 1500);
	
}

scrollPage = function(e) {
	if (e.id == '_intro') {
		$('#menu').animate({top: 527}, 1000, function(){
			$('#menu').css({position:'absolute'});
		});
	} else {
		$('#menu').css({position:'fixed'}).animate({top: -30}, 1000);
	}
}

moveMenu = function() {
		
	$('#menu li').each(function() {

		$(this).click(function(event) {
			canScroll=false;

			scrollPage(this);

			event.preventDefault();
			target = '#'+ this.id.split('_')[1];
			targetOffset = $(target).offset().top;

			$('html,body').animate({scrollTop: targetOffset}, 1000, function() {
				// location.hash = target;
				canScroll=true;
			});
			
		});

	});

}

$(function() {
	
	init();

});
