$(document).ready(function(){
/*	var stats = new Stats();

// Align top-left
stats.domElement.style.position = 'absolute';
stats.domElement.style.left = '50px';
stats.domElement.style.top = '250px';

$('body').append( stats.domElement );

setInterval( function () {

    stats.update();

}, 1000 / 60 );
	*/
	
            $(".container").hide();
            $(".container").delay(500).fadeIn(1000);
	
	$('input[placeholder], textarea[placeholder]').placeholder();
	
	var init;
	var static = false;
	var showMap = false;
	var activeMap = false;
  var latlng = new google.maps.LatLng(56.45956,-2.970999);
	var map;
	
 function initialize() {
	 
	 if(showMap == false){
	 var lastMapCenter; 
	 
    var myOptions = {
      zoom: 14,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
    panControl: false,
    zoomControl: false,
    scaleControl: false,
  mapTypeControl: false,
    streetViewControl: false
    };
		
    map = new google.maps.Map(document.getElementById("bodyWrap"), myOptions);
		var image = new google.maps.MarkerImage(
  '/images/image.png',
  new google.maps.Size(50,58),
  new google.maps.Point(0,0),
  new google.maps.Point(25,58)
);

var shadow = new google.maps.MarkerImage(
  '/images/shadow.png',
  new google.maps.Size(82,58),
  new google.maps.Point(0,0),
  new google.maps.Point(25,58)
);

var shape = {
  coord: [30,3,33,4,35,5,37,6,38,7,39,8,40,9,41,10,42,11,43,12,43,13,44,14,44,15,45,16,45,17,45,18,46,19,46,20,46,21,46,22,46,23,46,24,46,25,46,26,46,27,46,28,46,29,46,30,45,31,45,32,45,33,44,34,44,35,43,36,42,37,42,38,41,39,40,40,39,41,38,42,36,43,34,44,32,45,30,46,29,47,29,48,28,49,28,50,27,51,26,52,26,53,25,54,24,54,23,53,23,52,22,51,21,50,21,49,20,48,20,47,19,46,17,45,15,44,13,43,11,42,10,41,9,40,8,39,7,38,7,37,6,36,5,35,5,34,4,33,4,32,4,31,3,30,3,29,3,28,3,27,3,26,3,25,3,24,3,23,3,22,3,21,3,20,3,19,4,18,4,17,4,16,5,15,5,14,6,13,6,12,7,11,8,10,9,9,10,8,11,7,12,6,14,5,16,4,19,3,30,3],
  type: 'poly'
};

var marker = new google.maps.Marker({
  draggable: false,
  raiseOnDrag: false,
  icon: image,
  shadow: shadow,
  shape: shape,
  animation: google.maps.Animation.BOUNCE,
  map: map,
  position: latlng
});

		
	 }
		$('#bodyWrap').css('height', $(document).height()).fadeIn(1000);	
		$('section').fadeOut(100);		
		$('#playground').fadeOut(100);	
	 showMap = true;
	 activeMap = true;
		
		
  }
	
	function destroy(){
		$('#bodyWrap').fadeOut(1000);	
		$('#playground').fadeIn(1000);	
		$('section').fadeIn(1000);	
		activeMap = false;
	}

	$('.map').toggle(function(){ 
		initialize();
		$(this).find('.hover').show();
		static = true;
	}, function(){
		destroy();
		$(this).find('.hover').fadeOut();
		static = false;
	});
	
	$(window).resize(function() {
		if(activeMap == true){
			 var myOptions = {
				 center: latlng
			 }
			map.setOptions(myOptions);
			$('#bodyWrap').css('height', $(document).height())
		}
		
	});
	
	$('.social').mouseenter(function(){
		
		if(static == false){
		$(this).find('.hover').fadeIn();
		}
		
		
	}).mouseleave(function(){
		
		if(static == false){
		$(this).find('.hover').fadeOut();
		}
		
	});
	
	$(".tweet").tweet({
          username: "peterfitzearl",
          count: 1,
          loading_text: "loading tweets..."
        });
				
	$('.twitter').toggle(function(){
			
			$dark = $('.darkC');
			$light = $('.lightC');
			$tweet = $('.tweet');
		$(this).find('.hover').show();
		static = true;
			
			$dark.animate({'top' : '-165px'});
			$light.animate({'top' : '-170px'});
			$tweet.delay(1000).fadeIn(1000);
			
		},function(){
		$(this).find('.hover').fadeOut();
		static = false;
			$tweet.fadeOut(1000);
			$dark.delay(1000).animate({'top' : '-360px'});
			$light.delay(1000).animate({'top' : '-360px'});
			
		});
		
		$hideWord = function(){
			
			if($('.this').is(':visible')){
				$('.this').fadeOut();
			}
			
		}
		
		$hideVisible = function(){
						
			$('.visible').animate({'top' : '-5000px'}, 2000, 'easeInOutQuad');
			$('.visible').removeClass('visible');
			
		}
		/*
		$('#about').click(function(){
			
			$hideWord();
			$hideVisible();
			$('.about').animate({'top' : '0px'}, 2000, 'easeInOutQuad');
			$('.about').addClass('visible');
			
		});
		
		$('#contact').click(function(){
			
			$hideWord();
			$hideVisible();
			$('.contact').animate({'top' : '0px'}, 2000, 'easeInOutQuad');
			$('.contact').addClass('visible');
			
		});
		
		$('#work').click(function(){
			
			$hideWord();
			$hideVisible();
			$('.work').animate({'top' : '0px'}, 2000, 'easeInOutQuad');
			$('.work').addClass('visible');
			
		});
		
		$('#experiments').click(function(){
			
			$hideWord();
			$hideVisible();
			$('.experiments').animate({'top' : '0px'}, 2000, 'easeInOutQuad');
			$('.experiments').addClass('visible');
			
		});*/
		
		
		$('.this').delay(500).fadeIn(1000);
	
});
