/*
	  __     _           _  ___ __  
	 / /___ | | ___ ___ | || | '\ \ 
	/ |/ ._>| |<_-</ ._>| || |-  | \
	\ |\___.|_|/__/\___.|_||_|   | /
	 \_\                        /_/ 
			
** Twevelopers
** Copyright Matteo Cargnelutti [aka GeekArlier] - 2010
** http://elseif.eu | mail@elseif.eu
**
** Tous droits reservés.
**
** twevelopers_script.js
**
*/

$(document).ready(function(){

    /*
    ** Détails du design
    */
	//Fade in des notifications
	$('.notif').fadeIn(1000,function(){});
});

//--------------------------------------------------
// Flagging
//--------------------------------------------------
function flag(content_id)
{
	//Icone de chargement
	$('#t'+content_id+' .flag img').attr('src','views/img/loading.gif');
	
	//Ajax call
	$.post('../../controlers/ajax_controlers/flag.php', {flag: content_id},

	//Fin de l'oppération
	function success(data)
	{
		$('#t'+content_id+' .flag').html('<img src="views/img/flag_16.png" alt=""/> Signalé !');
	});
}


//--------------------------------------------------
// Suppression d'un tweet
//--------------------------------------------------
function del_tweet(content_id)
{
	//Icone de chargement
	$('#t'+content_id+' .delete img').attr('src','views/img/loading.gif');
	
	//Ajax call
	$.post('../../controlers/ajax_controlers/delete_content.php', {id: content_id},

	//Fin de l'oppération
	function success(data)
	{
		$('#t'+content_id+' .delete').html('<img src="views/img/delete_16.png" alt=""/> Supprimé !');
	});
}


//--------------------------------------------------
// Envoi d'un tweet
//--------------------------------------------------
function send_tweet()
{
	var tweet = $('input[name=new_tweet_content]').val();
	
	if(tweet.length > 0 && tweet.length <= 140)
	{
		//Icone de chargement
		$('#tweet_module h3').html('<img src="views/img/loading.gif" alt=""/> En cours...');
		$('#tweet_module button').hide();
		
		//Ajax call
		$.post('../../controlers/ajax_controlers/send_tweet.php', {tweet: tweet},

		//Fin de l'oppération
		function success(data)
		{
			$('#tweet_module').fadeOut('fast',function(){});
				$('input[name=new_tweet_content]').val('');
				$('#tweet_module button').show();
				$('#tweet_module h3').html('<img src="views/img/mini_tweet_16.png" alt=""/> Tweeté !');
			$('#tweet_module').fadeIn('fast',function(){});
		});
	}
	else
	{
		alert('Votre message doit faire entre 1 et 140 caractères, merci !');
	}
}

function tweet_module_toggle()
{
	if($('#tweet_module').css('left') == '-475px')
	{
		//Apparition du bloc (par la gauche, défilement)
		var i = 475;
		$('#tweet_module').css('left','-475px');

		$.timer(1, function(timer)
		{	
			$('#tweet_module').css('left','-'+i+'px');
			
			i = i-10;
			
			if(i == 0)
			{
				timer.stop();
			}
		});
	}
	else
	{
		$('#tweet_module').hide();
		$('#tweet_module').css('left','-475px');
		$('#tweet_module').fadeIn('slow',function(){});
	}
}


//--------------------------------------------------
// Suppression du compte utilisateur (confirmation)
//--------------------------------------------------
function confirm_my_account_deletion()
{
	if(confirm('Voulez-vous vraiment détruire votre compte ainsi que toutes vos contributions ?'))
	{
		document.forms['delete_my_account'].submit();
	}
}

