$(document).ready(function() {
	
	// centre the content li all times
	$('#content ul li').css("width", ( $(window).width()));
	$('#content ul li').css("height", ( $(window).height()));
	$(window).resize(function() { 
		$('#content ul li').css("width", ( $(window).width()));
		$('#content ul li').css("height", ( $(window).height()));
	});
	
	// centre the divs all times
	$('#content > ul > li > div').css("left", ( $(window).width() - $('#content > ul > li > div').width() ) / 2+$(window).scrollLeft() + "px");
	$('#content > ul > li > div').css("top", ( $(window).height() - $('#content > ul > li > div').height() ) / 2+$(window).scrollTop() + "px");
	$(window).resize(function() { 
		$('#content ul li div').css("left", ( $(window).width() - $('#content ul li div').width() ) / 2+$(window).scrollLeft() + "px");
		$('#content ul li div').css("top", ( $(window).height() - $('#content ul li div').height() ) / 2+$(window).scrollTop() + "px");
	});
	
	// center the  nav
	$('#nav').css("left", ( $(window).width() - $('#nav').width() ) / 2+$(window).scrollLeft() + "px");
	$('#nav').css("top", ( $(window).height() - $('#nav').height() ) / 2+$(window).scrollTop() + "px");
	$(window).resize(function() { 
		$('#nav').css("left", ( $(window).width() - $('#nav').width() ) / 2+$(window).scrollLeft() + "px");
		$('#nav').css("top", ( $(window).height() - $('#nav').height() ) / 2+$(window).scrollTop() + "px");
	});

	// localscroll
	$.localScroll.defaults.axis = 'xy';
		
	$.localScroll.hash({
		target: '#content',
		queue:true,
		duration:1500
	});

	$.localScroll({
		target: '#content',
		queue:true,
		duration:1700,
		hash:true,
		onBefore:function( e, anchor, $target ){
		},
		onAfter:function( anchor, settings ){
		}
	});
	
	$('.profile_splash ul').innerfade({ animationtype: 'fade', speed: 750, timeout: 4000, type: 'random', containerHeight: '296px' });
	
	// football form
   	$('.football_form').live('submit', function() {
   	
   		var team_name = $(this).find('input').eq(0).val();
   		var managers_name = $(this).find('input').eq(1).val();
   		var contact_number = $(this).find('input').eq(2).val();
   		var email = $(this).find('input').eq(3).val();
   		var affiliation_number = $(this).find('input').eq(4).val();
   		
   		alert('Team: name: ' + team_name + ', Managers Name: ' + managers_name + ', Contact Number: ' + contact_number + ', Email: ' + email + ', Affiliation Number: ' + affiliation_number);
   		
   		var str = '';
		var res = true;
		
		// check all is present and correct
		
		if(team_name == 'NS') {
			str += '- Please Select Team Name.\n';
			res = false;
		}
		
		if(managers_name == '') {
			str += '- Please Enter Managers Name.\n';
			res = false;
		}
		
		if(contact_number == '') {
			str += '- Please Enter Contact Number.\n';
			res = false;
		}
		
		if(email == '') {
			str += '- Please Enter E-mail Address.\n';
			res = false;
		}
		
		if(affiliation_number == '') {
			str += '- Please Enter Affiliation Number.\n';
			res = false;
		}
		
		if(str != '') { 
		
			//alert(str); 
			
		} else {
		
			//// send ajax request
			var fields = $(this).serialize();
			var path = this.action;
			//alert(path);
			$.ajax({
				type: "POST",
				url: path,
				data : fields,
				//dataType : "xml",
				success: function(msg) {
					alert('Team registered - Many Thanks');
					$('.submit').attr('disabled', 'disabled');	
					// window.refresh();
									
				}, error: function(){ alert('Failed for some reason'); }
			});
		
		}
	
		return false;
	
   	});
   	
   	//// ajax video
   	$('a.ajax').bind('click', function() {
   		var video = $(this).attr('href');
		//alert(video);
		$.ajax({
			type: "POST",
			url: 'ajax-video.php',
			data : video,
			success: function(content) {
				//alert(content);
				$('#video_holder').empty();
				$('#video_holder').html(content);
								
			}, error: function(){ alert('Failed for some reason'); }
		});
		return false;
   	});
	
	
	
});
