$(function(){
	$('.container').html('');
	var htext = $('h1').text();
	var defaultgallery = 'news';
	var gID = '0';
	switch (htext){
		case "WFX World Football Experience":
		defaultgallery = 'profootball'
		gID = '2'
		break;
		case "WFX News":
		defaultgallery = 'news'
		gID = '0'
		break;
		case "WFX Pathways":
		defaultgallery = 'profiles'
		gID = '3'
		break;
		case "WFX Elite Training Schedule":
		defaultgallery = 'preparation'
		gID = '1'
		break;
		case "WFX Team Globo":
		defaultgallery = 'teamglobo'
		gID = '4'
		break;
	}
	$('#galleryselection option:eq('+gID+')').attr('selected','selected');
	$('.container').load('/contents/gallery/'+defaultgallery);
	
	$(this).ajaxComplete(function(request, settings){
		 var itemWidth = $('.screen .item').size() * $('.screen .item').width();
		$('.screen .slideshow .container').width(itemWidth);
	});

	var gallery = ['news','preparation','profootball','profiles','teamglobo'];
	var gName = 'news';
	$('#galleryselection option').each(function(gIndex){
		$(this).click(function(){
		$('.container').html('');
		$('.container').load('/contents/gallery/'+gallery[gIndex]);
		gName = gallery[gIndex];
		});
	});

	var $prev = $('.screen .prev'), $next = $('.screen .next');
	$('.screen .slideshow').serialScroll({
		items:'.item',
		prev:$prev,
		next:$next,
		easing: 'linear',
		duration:8000,
		force:false,
		lazy:true,
		interval:1,
		cycle:false,
		constant:false,
		onBefore:function( e, elem, $pane, $items, pos ){
			if (pos == $items.length - 2) {
				$('.container').html();
				$('#galleryselection option').each(function(nID){
				$.get('/contents/gallery/'+gallery[gID], {}, function(data){
					$('.container').append(data);
				});
			});
			$('.screen .slideshow').trigger('start');
			}
		}
	});

	
	$('.screen').mouseover(function(){
		$('.screen .slideshow').trigger('stop');
	});
	$('.screen').mouseout(function(){
		$('.screen .slideshow').trigger('start');
	});
	
	$('#contactform').hide();

	$('#map1 area').each(function(cID){
		$(this).click(function(){
			$('#contact_location option:eq('+cID+')').attr('selected','selected');
			$('#contactform').show();
			$('#contactmap').hide();
			return false;
		});
	});
	
});

