$(document).ready(function() {
	
	/* Fighting the FOUT */
	/*
	(function(){
		// if firefox 3.5+, hide content till load (or 3 seconds) to prevent FOUT
		var d = document, e = d.documentElement, s = d.createElement('style');
		if (e.style.MozTransform === ''){ // gecko 1.9.1 inference
			s.textContent = 'body{visibility:hidden}';
			e.firstChild.appendChild(s);
			function f(){ s.parentNode && s.parentNode.removeChild(s); }
			addEventListener('load',f,false);
			setTimeout(f,3000); 
  		}
	})();
	*/
	
	/* Google Maps */
	try { initialize(); } catch(err) {}
	
	/* Catch */
	$('a.catch, a.tip').click(function(e){
		e.preventDefault();
	});
	
	/* uniform */
	try {
	$("select, input:checkbox, input:radio, input:file").uniform({fileBtnText: 'Upload CV', fileDefaultText: 'Selecteer bestand'});
	} catch(err) {}
	
	/* Tooltips */
	$(".tip").tipTip({'defaultPosition': 'top', 'keepAlive': false, 'delay': 200});

	/* Blur on search input, extendable to other inputs */
	$('body').find('input:text, textarea')
	.focus(function() {
		if ($(this).val() == $(this)[0].defaultValue) {
			if ($(this).hasClass('contact-textarea')) {
				if ($(this).val() == '...') { 
					$(this).val(''); 
				}
			} else {
				$(this).val('');
			}
		}
	})
	.blur(function() {
		if ($(this).val() == '') {
			$(this).val($(this)[0].defaultValue);
		}
	});
	
	/* pos */
	$('.sidebar h2 a').mouseover(function(){
		$(this).find('span').css({'background-color': '#f9c289', 'color': '#fff'});
	}).mouseout(function(){
		$(this).find('span').css({'background-color': '#efeaf1', 'color': '#603179'});
	});

	/* header menu */
	$('#header ul').hover(function() {
		$(this).find('ul').stop(true, true).fadeIn();
	}, function(){
		$(this).find('ul').stop(true, true).fadeOut();
	});
	$('#header h1').hover(function() {
		$('#header h1 #sub').stop(true, true).fadeIn();
	}, function() {
		$('#header h1 #sub').stop(true, true).fadeOut();
	});
	
	/* Activity timer */
	/* $(window).mousemove(function() {
		
		if ($('#header .top li').css('display') == 'none') {
			$('#header .top li').stop(true, true).fadeIn('slow', function(){
				setTimeout(function(){
					$('#header .top li').fadeOut('slow');
				}, 4000);
			}); 
		} else {
			setTimeout(function(){
				$('#header .top li').fadeOut('slow');
			}, 4000);
		}
	}); */

	/* Banner rotation */
	var ticker = function() {
		$('#banner ul li:first').fadeIn(300, function() {
			$(this).delay(5000).fadeOut(300, function(){
				$('#banner ul li:first').detach().appendTo('#banner ul').removeAttr('style');
				ticker();
			});
		});
	};
	ticker();

	/* Tweets rotation */
	//$('ul#tweets li:first').css({'display': 'block'});
	$('ul#tweets li:first').fadeIn();
	var tweets = function() {
		$('ul#tweets li:first').fadeIn(function() {
			$(this).delay(5000).fadeOut(function(){
				$('ul#tweets li:first').detach().appendTo('ul#tweets').removeAttr('style');
				tweets();
			});
		});
	};
	tweets();
	
	/* fix footer */
	//var offset = $('#footer').offset();
	var contentheight = 800;
	// console.log(contentheight);
	if ($('#vimeo').length) {
		contentheight = contentheight + 110;
		$('#scrollpane').height($('.gallery').height());
		$('#scroller-rail').height($('.gallery').outerHeight());
	}
	if ($(window).height() < contentheight) {
		$('#footer').css({'position': 'relative', 'bottom': 0});
	} else {
		$('#footer').css({'position': 'absolute', 'bottom': '20px'});
	}
	$(window).resize(function() {
		if ($(window).height() < contentheight) {
			$('#footer').css({'position': 'relative', 'bottom': 0});
		} else {
			$('#footer').css({'position': 'absolute', 'bottom': '20px'});
		}
	});

	/* Clone h3's to sidebar */
	$('.pages.view h3, .pages.view h2').each(function(){
		$(this).prepend('<a name="' + $(this).text().toLowerCase().replace(/\s+/g, '_') + '"></a>');
	});
	
});

