var available_langs = [
	{passion:'paragliders',langs:['en','it','de','fr','es','jp','kr']},
	{passion:'paramotor',langs:['en','it','de','fr','es','jp']},
	{passion:'speed',langs:['en','it','de','fr','es','jp']},
	{passion:'landkites',langs:['en','it','de','fr','es','pt']},
	{passion:'snowkites',langs:['en','it','de','fr','es','pt']},
	{passion:'kitesurf',langs:['en','it','de','fr','es','pt','nl']}
];

function show_flags(passion) {
	flags = jQuery('.passion_flags.' + passion).height(); 
	flags = 280-flags;
	jQuery('.passion_flags_wrap.' + passion).animate({top:flags+'px'},'slow','easeOutExpo');
}

function hide_flags(passion,timer) {

	if(timer==false) {
		jQuery('.passion_flags_wrap.' + passion).animate({top:'280px'}, 400,'swing');
	}
	else {
		switch(passion) {
			case 'paragliders':
				tparagliders = setTimeout('hide_flags(\''+passion+'\',false);',500);
				break;
			case 'paramotor':
				tparamotor = setTimeout('hide_flags(\''+passion+'\',false);',500);
				break;
			case 'speed':
				tspeed = setTimeout('hide_flags(\''+passion+'\',false);',500);
				break;
			case 'landkites':
				tlandkites = setTimeout('hide_flags(\''+passion+'\',false);',500);
				break;
			case 'snowkites':
				tsnowkites = setTimeout('hide_flags(\''+passion+'\',false);',500);
				break;
			case 'kitesurf':
				tkitesurf = setTimeout('hide_flags(\''+passion+'\',false);',500);
				break;
		}
	}
}

function over_flags(passion) {

	switch(passion) {
		case 'paragliders':
			clearTimeout(tparagliders);
			break;
		case 'paramotor':
			clearTimeout(tparamotor);
			break;
		case 'speed':
			clearTimeout(tspeed);
			break;
		case 'landkites':
			clearTimeout(tlandkites);
			break;
		case 'snowkites':
			clearTimeout(tsnowkites);
			break;
		case 'kitesurf':
			clearTimeout(tkitesurf);
			break;
	}
}

jQuery(document).ready(function() {

	jQuery('.passion_flags.paragliders').hover(function() { over_flags('paragliders'); }, function() { hide_flags('paragliders',true); } );
	jQuery('.passion_image_shadow.paragliders').click(function() { 
	
		if(has_cookie) go_to_lang('paragliders',latest_lang);
		else {
			show_flags('paragliders');
		}

	});
	
	jQuery('.passion_tittle.paragliders').click(function(event) { 
	
		event.preventDefault();
		if(has_cookie) go_to_lang('paragliders',latest_lang);
		else {
			show_flags('paragliders');
			tparagliders = setTimeout('hide_flags(\'paragliders\',false);',2000);
		}

	});
	
	jQuery('.passion_flags.paramotor').hover(function() { over_flags('paramotor'); }, function() { hide_flags('paramotor',true); } );
	jQuery('.passion_image_shadow.paramotor').click(function() { 
	
		if(has_cookie) go_to_lang('paramotor',latest_lang);
		else show_flags('paramotor');

	});

	jQuery('.passion_tittle.paramotor').click(function(event) { 
	
		event.preventDefault();
		if(has_cookie) go_to_lang('paramotor',latest_lang);
		else {
			show_flags('paramotor');
			tparamotor = setTimeout('hide_flags(\'paramotor\',false);',2000);			
		}

	});

	jQuery('.passion_flags.speed').hover(function() { over_flags('speed'); }, function() { hide_flags('speed',true); } );
	jQuery('.passion_image_shadow.speed').click(function() { 
		
		if(has_cookie) go_to_lang('speed',latest_lang);
		else show_flags('speed');

	});
	
	jQuery('.passion_tittle.speed').click(function(event) { 
	
		event.preventDefault();
		if(has_cookie) go_to_lang('speed',latest_lang);
		else {
			show_flags('speed');
			tspeed = setTimeout('hide_flags(\'speed\',false);',2000);						
		}

	});
	
	jQuery('.passion_flags.landkites').hover(function() { over_flags('landkites'); }, function() { hide_flags('landkites',true); } );
	jQuery('.passion_image_shadow.landkites').click(function() { 
		
		if(has_cookie) go_to_lang('landkites',latest_lang);
		else show_flags('landkites');

	});
	
	jQuery('.passion_tittle.landkites').click(function(event) { 
	
		event.preventDefault();
		if(has_cookie) go_to_lang('landkites',latest_lang);
		else {
			show_flags('landkites');
			tlandkites = setTimeout('hide_flags(\'landkites\',false);',2000);						
		}

	});
	
	jQuery('.passion_flags.snowkites').hover(function() { over_flags('snowkites'); }, function() { hide_flags('snowkites',true); } );
	jQuery('.passion_image_shadow.snowkites').click(function() { 
	
		if(has_cookie) go_to_lang('snowkites',latest_lang);
		else show_flags('snowkites');
		
	});
	
	jQuery('.passion_tittle.snowkites').click(function(event) { 
	
		event.preventDefault();
		if(has_cookie) go_to_lang('snowkites',latest_lang);
		else {
			show_flags('snowkites');
			tsnowkites = setTimeout('hide_flags(\'snowkites\',false);',2000);			
		}

	});
	
	jQuery('.passion_flags.kitesurf').hover(function() { over_flags('kitesurf'); }, function() { hide_flags('kitesurf',true); } );
	jQuery('.passion_image_shadow.kitesurf').click(function() { 

		if(has_cookie) go_to_lang('kitesurf',latest_lang);
		else show_flags('kitesurf');
	
	});
	
	jQuery('.passion_tittle.kitesurf').click(function(event) { 
	
		event.preventDefault();
		if(has_cookie) go_to_lang('kitesurf',latest_lang);
		else {
			show_flags('kitesurf');
			tkitesurf = setTimeout('hide_flags(\'kitesurf\',false);',2000);			
		}

	});
	
});

function go_to_lang(passion,lang) {
	
	for (p=0;p<available_langs.length;p++){
		if(available_langs[p].passion==passion) {
			for (l=0;l<available_langs[p].langs.length;l++){
				if(available_langs[p].langs[l]==lang) {
					window.location.href='/'+passion+'/'+latest_lang+'/'; 
					return;
				}
			}
			window.location.href='/'+passion+'/en/'; 
			return;
		}
	}

	window.location.href='/'; 
}