/* 
CC petervermaercke.be
*/

var diff = 0;
var jobs = [];
var current_job = "";
var soft = ["a","e","i","o","u","h"];
var interval = 4000;

try{Typekit.load('nvo4wsm', {afterLoad: init_js()});}catch(e){}

function getJob() {
	if( jobs.length <= 0 ) { $.getJSON("http://petervermaercke.be/services/api/job_desc/", function(data) { jobs = data.jobs; switchJob(); return; }); } else { switchJob(); }
}

function switchJob() {
	do { current_job = jobs[Math.floor((jobs.length)*Math.random())]; diff =  (jobs.indexOf($('#job_desc').html())) - (jobs.indexOf(current_job)); } while ( !diff )	
	$('#art').html( ($.inArray(current_job.slice(0, 1).toLowerCase(), soft) > -1) ? 'an' : 'a' );
	$('#job_desc').html(current_job).addClass('highlight').delay(500).queue(function () { $(this).removeClass('highlight'); $(this).dequeue(); });
}

function init_js() {
	$(document).ready(function(){
		current_job = $('#job_desc').text();
		setInterval("getJob()",interval);
		$('h1 > a').html('Peter VRMRCK');
		$('h2 > a').addClass('highlight');
		$('#flash').mouseover(function(){
			$(this).attr('src','/assets/img/ninja.png').delay(50).queue(function () {
				$(this).attr('src', '/assets/img/lightning.png'); $(this).dequeue(); 
			});
		});
		$('footer').delay(1500).slideDown();
		$('h2 > a').each(function(index) {
			$(this).delay(800 + index++ * 100).queue(function () { $(this).removeClass('highlight'); $(this).dequeue(); });
		}).tipsy({fade: true,gravity:'s'});
	});
}
