/*
 *	@titre: news.
 *	@description: javascript news - dream on.
 *	@auteur: neov - http://www.neov.net.
 *	@creation: 20091118.
 *	@modification: -
 *	@required: jQuery 1.3.2
 *
 */
 
var timeout = null;

$(
	function()
	{
		
		// textarea resizer.
		$('.comment-textarea').TextAreaResizer();
		
		// liste archive
		$('.news-archives >p >a').click(
			function()
			{
				$(this).toggleClass('active');
				$('.liste-archive').slideToggle({queue:false, duration:gtime, easing:"sineEaseOut"});
				$('.liste-archive .liste-inner').jScrollPane({
					showArrows:			true, 
					scrollbarWidth: 	19, 
					arrowSize: 			11, 
					scrollbarMargin:	5,
					dragWidth:			9
				});
				return false;
			}
		);
		
		// onglet news
		
		$('.detail-news .onglet a').each(
			function(index) {
				$(this).click(
					function()
					{
						$('.detail-news .onglet a').toggleClass('active');
						$('.detail-news .col-wrapper > div').hide();
						$('.detail-news .col-wrapper > div').eq(index).show();
						
						return false;
					}
				)
			}
		);
		
		// validation commentaire News
		$('.commentaires-content .right-col form [type=submit]').click(
			function ()
			{
				bErreur = tmt_validateForm($("#commentaireNews").get(0));
                if (bErreur){
                    var iNewsId = $("#idNews").val();
                    var zTextComment = $("#comment-comment").val();
                    var zNomComment = $("#comment-nom").val();
                    var zMailComment = $("#comment-mail").val();
                    var zSiteWebComment = $("#comment-web").val();  
                    
                    $('.commentaires-content .right-col .comments').hide();
				   	$('.commentaires-content .right-col .merci').show();                    
                    
                    $.ajax({
                        type:"POST",
                        url:j_basepath+"ajax.php",
                        data:"module=news&action=newsFo:commenterNews&iNewsId=" + iNewsId + "&zTextComment=" + zTextComment + "&zNomComment=" + zNomComment + "&zMailComment=" + zMailComment + "&zSiteWebComment=" + zSiteWebComment,
                        dataType:"json",
                        async:false,
                        success:function(resultat){
                            $("#comment-comment").val(resultat.msgcommentaire);
                            $("#comment-nom").val(resultat.msgnom);
                            $("#comment-mail").val(resultat.msgmail);
                            $("#comment-web").val(resultat.msgweb);                                    				   	
                               
                            if (timeout) clearTimeout(timeout);
							timeout = setTimeout(function(){
                    								$('.commentaires-content .right-col .merci').hide();	
                    								$('.commentaires-content .right-col .comments').show();											
                    								}, 5000
                                                );
								                           
                        }                    
                    });
                    
                }				
				return false;
			}
		);
		
		
		//validation envoi ami
		$('.envoi-ami form [type=submit]').click(
            function(){
                bErreur = tmt_validateForm($("#envoiAmi").get(0));
                if (bErreur){
                    var iNewsId = $("#idNews").val();
                    var zMailExpediteur = $("#envoi-mail").val();
                    var zNomExpediteur = $("#envoi-nom").val();
                    var zNomDestinataire = $("#envoi-nom-ami").val();
                    var zMailDestinataire = $("#envoi-mail-ami").val();
                    $('.envoi-ami').hide();
                    $('.post-it-message').show();                    
                    $.ajax({
                        type:"POST",
                        url:j_basepath+"ajax.php",
                        data:"module=news&action=newsFo:envoyerAmi&iNewsId=" + iNewsId + "&zMailExpediteur=" + zMailExpediteur + "&zNomExpediteur=" + zNomExpediteur + "&zNomDestinataire=" + zNomDestinataire + "&zMailDestinataire=" + zMailDestinataire,
                        dataType:"json",
                        async:false,
                        success:function(resultat){                            
                            $("#envoi-mail").val(resultat.mailexpediteur);
                            $("#envoi-nom").val(resultat.nomexpediteur);
                            $("#envoi-nom-ami").val(resultat.nomdestinataire);
                            $("#envoi-mail-ami").val(resultat.maildestinataire);                                                      
                            
                            if (timeout) clearTimeout(timeout);
							timeout = setTimeout(function(){
                    								$('.post-it-message').hide();	
                    								$('.envoi-ami').show();											
                    								}, 5000
                                                );                              
                        }
                    });
                    
                }
                return false;
            }
        );
		
        /*
		$('.commentaires-content .right-col form [type=submit]').click(
		function ()
			{
				   	//$('.commentaires-content .right-col .comments').hide();
				   	//$('.commentaires-content .right-col .merci').show();

                    bErreur = tmt_validateForm($("#commentaireNews").get(0));
                    if (!bErreur){
                        alert ("non");
                    } else {
                        alert ("oui");
                    }				   	
				   	return false;
			}
		) 
		*/
		
	}
	
	
);

function displayError(){
    return true;
}
