var section = 'home';
var html5_video = false;

function isiPad(){
    return (navigator.platform.indexOf("iPad") != -1);
}

function supports_video() {
	return !!document.createElement('video').canPlayType;
}

function supports_h264_baseline_video() {
	if (!supports_video()) { return false; }
	var v = document.createElement("video");
	return v.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"');
}

function supports_ogg_theora_video() {
	if (!supports_video()) { return false; }
	var v = document.createElement("video");
	return v.canPlayType('video/ogg; codecs="theora, vorbis"');
}

function supports_webm_video() {
	if (!supports_video()) { return false; }
	var v = document.createElement("video");
	return v.canPlayType('video/webm; codecs="vp8, vorbis"');
}

function test_html5() {
	var h264 = supports_h264_baseline_video();
	var ogg = supports_ogg_theora_video();
	var webm = supports_webm_video();
	if (h264 == '' && ogg == '' && webm == '') {
		html5_video = false;
	} else {
		html5_video = true;
	}
}

function home() {
	$('#home').fadeIn();
	$('#title2').fadeIn();
	$('#enter_button').fadeIn();
}

function changeSection(target) {
	
	if (target == 'app') return;//finchè non c'è la sezione app altrimenti blocca il menu

	if (section == target) return;
	blockPage();
	
	if (target == 'creation') {
		point = 8;
		if (isiPad()) {
			var video = document.getElementsByTagName('video')[0];
			video.play();
			setTimeout(function(){ video.pause(); }, 200);
		}
	}
	
	if (target == 'spot') {

		eval(target+'("'+section+'");');
		section = target;
		$.unblockUI();
		
	} else {
		
		switch (section) {
			case 'home':
				$('#title2').fadeOut();
				$('#enter_button').fadeOut();
				break;
			case 'creation':
				point = 8;
				if (html5_video) {
					var video = document.getElementsByTagName('video')[0];
					video.pause();
					video.currentTime = 0.01;
				}
				break;
		}
		
		$('#'+section).fadeOut({duration: 600, easing: 'easeOutQuint', complete: function() {
			eval(target+'();');
			if (isiPad()) {
				resizeHandler();
			}
			section = target;
			$.unblockUI();
		}});

	}

}

function changeLanguage() {
	$('#language').fadeIn();
}

test_html5();
