var mobiledevice = 404;

$(document).ready(function() {

if(onMobileDevice()) {
	// Mobile Devices
	
} else {
	// ..and the rest
	loadMoby();
	loadSkills();
	randomThings();
}

});

function oniPhoneOS () {
	return onMobileDevice();
}

function onMobileDevice () {
	if (mobiledevice == 404) {
		// Let's see if we're dealing with a mobile device or something similar
		var uagent = navigator.userAgent.toLowerCase();
		if (uagent.search(/iphone/i) > -1) mobiledevice = true;
    	else if (uagent.search(/android/i) > -1) mobiledevice = true;
    	else if (uagent.search(/windows ce/i) > -1) mobiledevice = true;
    	else if (uagent.search(/blackberry/i) > -1) mobiledevice = true;
    	else if (uagent.search(/ipod/i) > -1) mobiledevice = true;
    	else if (uagent.search(/midp/i) > -1) mobiledevice = true;
    	else if (uagent.search(/htc/i) > -1) mobiledevice = true;
    	else if (uagent.search(/nokia/i) > -1) mobiledevice = true;
    	else if (uagent.search(/symbian/i) > -1) mobiledevice = true;
    	else if (uagent.search(/series60/i) > -1) mobiledevice = true;
    	else if (uagent.search(/opera mobi/i) > -1) mobiledevice = true;
    	else if (uagent.search(/opera mini/i) > -1) mobiledevice = true;
    	else if (uagent.search(/palm/i) > -1) mobiledevice = true;
    	else if (uagent.search(/up.browser/i) > -1) mobiledevice = true;
    	else if (uagent.search(/avantgo/i) > -1) mobiledevice = true;
    	else if (uagent.search(/docomo/i) > -1) mobiledevice = true;
    	else if (uagent.search(/minimo/i) > -1) mobiledevice = true;
    	else if (uagent.search(/netfront/i) > -1) mobiledevice = true;
    	else if (uagent.search(/portalmmm/i) > -1) mobiledevice = true;
    	else if (uagent.search(/kindle/i) > -1) mobiledevice = true;
    	else if (uagent.search(/nintendo/i) > -1) mobiledevice = true;
    	else if (uagent.search(/240x320/i) > -1) mobiledevice = true;
    	else if (uagent.search(/vodafone/i) > -1) mobiledevice = true;
    	else mobiledevice = false;
	}
	return mobiledevice;
}

function linkTextMessage () {
	if(oniPhoneOS()) document.write(' But since you\'re on your mobile phone, maybe you\'d rather <a href="sms:+31' + (2135361312 / 3.5) + '">send me a SMS</a>.');
}

function includeJS(jsFile)
{
  document.write('<script type="text/javascript" src="' + jsFile + '"></scr' + 'ipt>'); 
}

function loadMoby () {
$.getJSON("json.php?moby",
       function(data){
       	  var images = "";
          $.each(data.contents.results, function(i, result){
            images += "<a rel=\"moby\" id=\"mobypic" + result.post.id + "\" href=\"" + result.post.media.url_full + "\" title=\"" + result.post.title + "\" style=\"background: url('" + result.post.media.url_square + "');\"> </a> ";
          });   
          images += "<div class=\"break\"> </div>";
          $("#blockPhotoFeed .whiteBlock").html(images);
          
          // Fancybox
          $("#blockPhotoFeed a").fancybox({
			'titleShow'     : true,
			'titlePosition' : 'over',
			'transitionIn'	: 'fade',
			'transitionOut'	: 'fade',
			'easingIn'      : 'swing',
			'easingOut'     : 'swing',
			'enableEscapeButton': true,
 		    'centerOnScroll'	: true,
 		    'cyclic'		: 'true'
		  });
		  
		  // Auto-update? (om de 2 min)
		  setTimeout("loadMoby()", 120000);
        });
}

function loadSkills() {
$.getJSON("json.php?skls",
	function(data){
	$.each(data, function(i, item){
			$("#skills").append("<a href=\"" + item.link + "\" title=\"" + item.name + "\"><img class=\"skill" + item.perc + "\" src=\"css/icon/" + item.icon + "\" alt=\"" + item.name + "\" /></a>");
			$("#skills .skill" + item.perc).fadeTo("slow", (item.perc / 100));
			$("#skills a").fancybox({
				'width'				: '95%',
				'height'			: '85%',
 		        'autoScale'     	: true,
 		        'centerOnScroll'	: true,
 		        'transitionIn'		: 'fade',
				'transitionOut'		: 'fade',
				'type'				: 'iframe',
				'titleShow'			: true,
				'titlePosition'		: 'inside',
				'enableEscapeButton': true
			});
		});
	});
}

function randomThings() {
	// afsluiting
	random = Math.round( Math.random() * 3 ) + 1;
	$('#foot').css("background", "url('css/img/foot0" + random + ".png')");
}
