$(function(){  //comienza document ready
	
	
	
	//Llamada fitText.js
	$("p.claim").fitText();
	
	
	//Carga videoflare
	fv = $("#video").flareVideo({
		poster: "landing_files/media/poster.jpg",
		flashSrc: "landing_files/media/FlareVideo.swf",
		autobuffer: false,
		preload: false,
		width: '100%'
		
	});
	fv.load([
	{
		src: 'http://www.aqualand.es/landing_files/media/video.mp4',
		type: 'video/mp4'
	},
	{
		src: 'landing_files/media/video.ogv',
		type: 'video/ogg; codecs="theora, vorbis"'
	}
	]);
	
	//Fix dimensiones video en IE
	if (navigator.appName === 'Microsoft Internet Explorer') {
		var vid = $('.flareVideo video'); 
		if (vid.length != 0) vid.width(vid.parent().width()).height(vid.parent().height());
	}


	//Averiguar ancho de pantalla
	var ancho = $(window).width();

	if (ancho > 799) {

		//Inicialización navegación
		var default_active = 0;
		var active = default_active;
		var busy = false;

		$('#info article').hide();
		$('.sublogo img').hide();
		
		displayPark(default_active);
		
		//Eventos
		$("#menu-park li a").hover (function (zEvent) { displayPark (zEvent); } );
		$("#list-menu-park li a").hover (function (zEvent) { displayPark (zEvent); } );

		$('.cerrar').click(function () {
			closePark();
		});
	
	} else if (ancho <= 480) {
	
		$('#info article').hide();
		$('.sublogo img').hide();
		$('#intro').hide();
		$('#slideshow').hide();
		$('#list-park #list-menu-park li.list-menu-item').hide();
	
	} else if (ancho >= 481 && ancho <=799){
		$('#info article').hide();
		$('.sublogo img').hide();
		$('#intro .vervideo').click(function () {
			$('#video').show("slow"); 
			fv.play();
		});
		$('#intro .cerrar').click(function () {
			$('#video').fadeOut('slow'); 
			fv.pause();
		});
	};
		
	





	//debug ancho de pantalla
	
/*	$('#page').before('<div id="dimensions" style="color: red; font-weight: bold; font-family: courier; font-size: 16px; margin-top: 100px; float:left; position:fixed;"></div>');
	display_dimensions();
	$(window).resize(function(){
			display_dimensions()
	});
*/


}); // termina document ready


//funciones 

function displayPark(zEvent) { 
	if (zEvent.type == 'mouseenter') {
		
		var selected = $(zEvent.currentTarget).attr ('park');
		active = selected;
		$('.menu-item.active-menu-item').removeClass('active-menu-item');
		$('.menu-item a[park="' + active + '"]').parent().addClass('active-menu-item');
		$('.list-menu-item.active-list-menu-item').removeClass('active-list-menu-item');
		$('.list-menu-item a[park="' + active + '"]').parent().addClass('active-list-menu-item');
		fv.pause();
		$('#logo img').hide();
		$('#intro, #slideshow, #info article[park!="' + active +'"], .sublogo img[park!="' + active +'"]').hide(0, function(){
			$('#info article[park="' + active +'"], .sublogo img[park="' + active +'"]').fadeIn('fast');
			$('#logo img').fadeIn('fast');
		});		

	}
}

function closePark() {
	active = 0;
	$('#info article').hide();
	$('.sublogo img').hide();
	$('#intro').fadeIn('normal');
	$('#slideshow').fadeIn('normal');
	$('.menu-item ').removeClass('active-menu-item');
	
}

 function display_dimensions() {
	$('#dimensions').html( $(window).width());
}

//Añade el play para dispositivos tactiles con safari
 window.onload = function (){
        document.getElementById('video').addEventListener("touchend", touchHandler, false);
    }
function touchHandler(e) {
	if (e.type == "touchend" || e.type == "touchcancel") {
		fv.play();	
	} else {
		// Nothing
	}
}

