$(document).ready(function(){
	tooltip();						   
		
/* Footer 
------------------------------*/
var Duration = 150; //time in milliseconds
	  $('#footer1 div').hover(function() {
		$(this).stop(true, true).animate({ marginTop: '0px' }, Duration);
	  }, function() {
		$(this).stop(true, true).animate({ marginTop: '20px' }, Duration);           
	  });

/* Social Media Icons
------------------------------*/
var Duration = 150; //time in milliseconds
	  $('.tw').hover(function() {
		$(this).stop(true, true).animate({ marginLeft: '7px' }, Duration);
		$('.tw span').css({ display: 'block'});
		$('.tw span').stop(true, true).animate({ right: '45px'});
	  }, function() {
		$(this).stop(true, true).animate({ marginLeft: '10px' }, Duration);
		$('.tw span').css({ display: 'none'});
		$('.tw span').stop(true, true).animate({ right: '40px'});
	  });
	  $('.hy').hover(function() {
		$(this).stop(true, true).animate({ marginLeft: '7px' }, Duration);
		$('.hy span').css({ display: 'block'});
		$('.hy span').stop(true, true).animate({ right: '45px'});
	  }, function() {
		$(this).stop(true, true).animate({ marginLeft: '10px' }, Duration);
		$('.hy span').css({ display: 'none'});
		$('.hy span').stop(true, true).animate({ right: '40px'});
	  });
	  $('.fb').hover(function() {
		$(this).stop(true, true).animate({ marginLeft: '7px' }, Duration);
		$('.fb span').css({ display: 'block'});
		$('.fb span').stop(true, true).animate({ right: '45px'});
	  }, function() {
		$(this).stop(true, true).animate({ marginLeft: '10px' }, Duration);
		$('.fb span').css({ display: 'none'});
		$('.fb span').stop(true, true).animate({ right: '40px'});
	  });

/* Submenu 
------------------------------*/
  $('.portfolio').hover(function() {
	$('.submenu').animate({ width: '130px'}, 250);
	$('.submenu li').css({ display: 'block'});
	$('#submenuline').animate({ left: '755px'}, 250); 
  }, function() {
	$('.submenu').stop(true, true).animate({ width: '0px'}, 250); 
	$('.submenu li').css({ display: 'none'});
	$('#submenuline').stop(true, true).animate({ left: '625px'}, 250); 
  });
  

/* Arrow 
------------------------------*/
  $('#Arrow').css({ top: '157px'});

  $('li.home a').click(function() {
	$('#Arrow').stop(true, true).animate({ top: '157px' }, 800);
  });
  $('li.portfolio a, li.p_fotografie a, li.p_photoshoppen a, li.p_overige a').click(function() {
	$('#Arrow').stop(true, true).animate({ top: '237px' }, 800);
  });
  $('li.overmij a').click(function() {
	$('#Arrow').stop(true, true).animate({ top: '317px' }, 800);
  });
  $('li.contact a').click(function() {
	$('#Arrow').stop(true, true).animate({ top: '397px' }, 800);
  });



/* Laatste Tweet 
------------------------------*/
	var animSpeed = 150;
	  $('.tTip').hover(function() {
		$('.tinyTip').stop(true, true).fadeIn(animSpeed);
	  }, function() {
		$('.tinyTip').stop(true, true).fadeOut(animSpeed);
	  });
});


/* Tooltip 
------------------------------*/

this.tooltip = function(){		
		xOffset = 10;
		yOffset = 20;			
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};



/* Scroll 
------------------------------*/
var $CURRENT_PAGE_ID = "#pageOne";	// global ID for the current page.

function setupPages() {
	var windowHeight = $(window).height() - $("#header").outerHeight(true) - $("#contentfooter").outerHeight(true) - 20;
	$(".page").css({
		'min-height': windowHeight + 'px'
	});
}

function goToPage(pageId, animate) {
	if (animate === undefined) animate = true;

	var pageMap = { '#one': '#pageOne', '#two': '#pageTwo', '#five': '#pageFive', '#six': '#pageSix', '#seven': '#pageSeven', '#three': '#pageThree', '#four': '#pageFour' };
	var page = $(pageMap[pageId]);
	if (animate) {
		$('#pages-inner').animate({
			top: '-'+page.position().top+'px'
		}, 800);
		$("#pages").animate({
			height: page.height()+'px'
		}, 800);
	} else {
		$('#pages-inner').css({ top: '-'+page.position().top+'px' });
		$('#pages').css({ height: page.height()+'px' });
	}
	
	$("#links a").removeClass("selected");
	$("#links a[href='"+pageId+"']").addClass("selected");
	
	$CURRENT_PAGE_ID = pageMap[pageId];
}

$(document).ready(function() {
	setupPages();
	$("#pages-inner").css({
		overflow: 'hidden',
		position: 'relative'
	});
	$('#pages').css({ 
		overflow: 'hidden', 
		position: 'relative'
	});

	var links = $("#links a");
	links.each(function(i) {
		$(this).click(function (e) {
			goToPage($(this).attr('href'), true);
			e.preventDefault();
		});
	});

	$(window).bind("resize", function(e) {
		setupPages();				
		var page = $($CURRENT_PAGE_ID);
		$('#pages-inner').css({ top: '-'+page.position().top+'px' });
		$('#pages').css({ height: page.height()+'px' });
	});

	var requestedAnchor = window.location.hash;
	if (requestedAnchor == '' || requestedAnchor == '#')
		requestedAnchor = '#one';
	
	$('html, body').scrollTop(0);
	goToPage(requestedAnchor, false);
});
