function showWriteShout(){
	$("#writeShout").animate({"height": "toggle"}, { duration: 200 });
}
function showWriteWhy(){
	$("#writeWhy").animate({"height": "toggle"}, { duration: 200 });
}
function like(id) {
$.ajax({
   type: "POST",
   url: "/inc/ajax.php",
   data: "like=" + id,
   success: function(str){
   		$("#likes"+id).text(str);
   }
 });
}
function toggleLayer(id) {
	$("#"+id).toggle();
}
$(function(){
	if($("#lineup").length > 0){
		$("#toggleLineup").click(function () { $('#lineup').toggle("slow");	});
		$("#lineup .player").draggable({ containment:'parent', grid:[10,10], opacity:0.7 });
		$("#lineup .player").draggable({
			stop: function(event, ui) {
				var pos = $("#lineup .player").index(this);
				$("#lineup :input.position").eq(pos).val($(this).position().top+","+$(this).position().left);
			}
		});
	}
	if($("#twitterFeed").length > 0){ $("#twitterFeed").load('/inc/ajax.php?twitterFeed=1'); }
	if($("#chelseaFeed").length > 0){ $("#chelseaFeed").load('/inc/ajax.php?chelseaFeed=1'); }
	if($("#teamtalkFeed").length > 0){ $("#teamtalkFeed").load('/inc/ajax.php?teamtalkFeed=1'); }
	if($("#skysportsFeed").length > 0){ $("#skysportsFeed").load('/inc/ajax.php?skysportsFeed=1'); }
	if($("#goalFeed").length > 0){ $("#goalFeed").load('/inc/ajax.php?goalFeed=1'); }
	if($("#youtubeFeed").length > 0){ $("#youtubeFeed").load('/inc/ajax.php?youtubeFeed=1'); }
	if($("#flickrFeed").length > 0){ $("#flickrFeed").load('/inc/ajax.php?flickrFeed=1'); }
	var loader=$('#loader');
	var pollcontainer=$('#poll');
	loader.fadeIn();
	//Load the poll form
	$.get('/inc/ajaxPoll.php', '', function(data, status){
		pollcontainer.html(data);
		animateResults(pollcontainer);
		pollcontainer.find('#viewresult').click(function(){
			//if user wants to see result
			loader.fadeIn();
			$.get('/inc/ajaxPoll.php', 'result=1', function(data,status){
				pollcontainer.fadeOut(1000, function(){
					$(this).html(data);
					animateResults(this);
				});
				loader.fadeOut();
			});
			//prevent default behavior
			return false;
		}).end()
		.find('#pollform').submit(function(){
			var selected_val=$(this).find('input[name=poll]:checked').val();
			if(selected_val!=undefined){
				//post data only if a value is selected
				loader.fadeIn();
				$.post('/inc/ajaxPoll.php', $(this).serialize(), function(data, status){
					$('#formcontainer').fadeOut(100, function(){
						$(this).html(data);
						animateResults(this);
						loader.fadeOut();
					});
				});
			}
			//prevent form default behavior
			return false;
		});
		loader.fadeOut();
	});
	function animateResults(data){
		$(data).find('.bar').hide().end().fadeIn('fast', function(){
			$(this).find('.bar').show();
		});
	}
	$("#username").blur(function()	{
		if($(this).val()) {
			//remove all the class add the messagebox classes and start fading
			$("#usernameMessage").removeClass().addClass('messageBox').text('Tjekker...').fadeIn(1000);
			//check the username exists or not from ajax
			$.post("/inc/ajax.php",{ username:$(this).val() } ,function(data) {
				//if username not avaiable
				if(data=='no') {
					//start fading the messagebox
					$("#usernameMessage").fadeTo(200,0.1,function() {
						//add message and change the class of the box and start fading
						$(this).html('Brugernavnet er optaget eller ugyldigt').addClass('messageBoxError').fadeTo(900,1);
					});
				} else {
					//start fading the messagebox
					$("#usernameMessage").fadeTo(200,0.1,function() {
						//add message and change the class of the box and start fading
						$(this).html('Brugernavnet er ledigt').addClass('messageBoxOk').fadeTo(900,1);
					});
				}
			});
		}
	});
	$("#email").blur(function()	{
		if($(this).val()) {
			$("#emailMessage").html("").removeClass().addClass('messageBox');
			//check if the email is valid
			$.post("/inc/ajax.php",{ email:$(this).val() } ,function(data) {
				//if email not valid
				if(data=='no') {
					//start fading the messagebox
					$("#emailMessage").fadeTo(200,0.1,function() {
						//add message and change the class of the box and start fading
						$(this).html('Ugyldig email').addClass('messageBoxError').fadeIn(200).fadeTo(100,1);
					});
				} else {
					$("#emailMessage").html("&nbsp;").addClass('messageBoxOk').fadeIn(200).fadeTo(100,1);
				}
			});
		}
	});
	$("#password2").blur(function()	{
		if($(this).val()) {
			$("#passwordMessage").html("").removeClass().addClass('messageBox');
			//check if passwords are similar
			if($("#password").val() == $("#password2").val()) {
				$("#passwordMessage").html("&nbsp;").addClass('messageBoxOk').fadeIn(200).fadeTo(100,1);
			} else {
				//start fading the messagebox
				$("#passwordMessage").fadeTo(200,0.1,function() {
					//add message and change the class of the box and start fading
					$(this).html('De to adgangskoder er ikke ens').addClass('messageBoxError').fadeIn(200).fadeTo(100,1);
				});
			}
		}
	});
	$("#auth").blur(function()	{
		if($(this).val()) {
			$("#authMessage").html("").removeClass().addClass('messageBox');
			//check if the email is valid
			$.post("/inc/ajax.php",{ auth:$(this).val() } ,function(data) {
				//if auth not valid
				if(data=='no') {
					//start fading the messagebox
					$("#authMessage").fadeTo(200,0.1,function() {
						//add message and change the class of the box and start fading
						$(this).html('Kontrolkoden er forkert').addClass('messageBoxError').fadeIn(200).fadeTo(100,1);
					});
				} else {
					$("#authMessage").html("&nbsp;").addClass('messageBoxOk').fadeIn(200).fadeTo(100,1);
				}
			});
		}
	});
});
function deleteAvatar() {
	$.ajax({
		type: "GET",
		url: "/inc/ajax.php",
		data: "mode=deleteAvatar",
		success: function(){
			$("#avatar").fadeTo(200,0.1,function() {
				$(this).attr("src","/images/avatar.gif").fadeIn(200).fadeTo(100,1);
				$("#deleteLink").fadeOut(100);
			});
		}
	});
}
