jQuery(document).ready(function() {
// When a link is clicked
        jQuery("a.tab").click(function () {

            // switch all tabs off
            jQuery(".active").removeClass("active");

            // switch this tab on
            jQuery(this).addClass("active");

            // slide all content up
            jQuery(".content").slideUp();

            // slide this content up
            var content_show = jQuery(this).attr("title");
            jQuery("#"+content_show).slideDown();

        });




    function nl2br(value) {
        return value.replace(/\n/g, "<br />");
    }

    function strip_tags(input){
        return input.replace(/<\/?[^>]+>/gi, '');
    }

    

    jQuery('#thinkarea').keyup(function(){
        var area=jQuery('#thinkarea').val();
        var count=251-area.length;
        count=count-1;
        jQuery('#charleft').html(count); 
        if (count>=0){    
            jQuery('#publish').show();
        } else {
            jQuery('#publish').hide();
        }
    });


    jQuery('#publish').click(function(){
        var thinkarea = jQuery('#thinkarea').val();
        thinkarea=strip_tags(thinkarea).substr(0,250);
        //jQuery('#frasepubblicata').css("border-left","1x solid #64D0FF");
        jQuery.post("/js/think.php", { thinkarea: thinkarea },
        function(taim){
            if (thinkarea!="") {
                jQuery('#frasepubblicata').slideUp(function(){
                    jQuery('#charleft').html("250");
                    jQuery('#frase').html(nl2br(thinkarea));
                    jQuery('#frasedata').html(taim);
                    jQuery('#frasepubblicata').css("border-left","1px solid #64D0FF"); 
                    jQuery('#frasepubblicata').slideDown(750);
                });
            }
            jQuery('#thinkarea').val("");
        });


    });
    jQuery('#unpublish').click(function(){
        var thinkarea = jQuery('#thinkarea').val();
        //jQuery('#frasepubblicata').css("border-left-color","#DAEEF8");
        jQuery('#thinkarea').val("");
        jQuery.post("/js/think.php", { thinkarea: thinkarea },
        function(taim){
            jQuery('#charleft').html("250");
            jQuery('#frasepubblicata').slideUp();
            jQuery('#frasepubblicata').css("border-left","none");
            jQuery('#frase').html("");
            jQuery('#frasedata').html("");
        });
    });

    jQuery('#delphoto').click(function(){
        //alert("a questo punto verrà cancellata la foto. ma non ancora");
        var delphoto = jQuery('#photoz').val();
        jQuery.post("/js/delphoto.php", { delphoto: delphoto },
        function(){
            jQuery('#fotoutente').slideUp(function(){
                jQuery('#fotoutente').html('<img src="/upload/users/default.jpg" width="50" />');
                jQuery('#fotoutente').slideDown();
            });
            jQuery('#photoz').slideUp(function(){
                jQuery('#photoz').html('<img src="/upload/users/default.jpg" width="50" align="absmiddle" />');
                jQuery('#photoz').slideDown();
            });       
        });       
     });


    jQuery("a.tab").click(function () {
            // switch all tabs off
            jQuery(".active").removeClass("active");
            // switch this tab on
            jQuery(this).addClass("active");
            // slide all content up
            jQuery(".content").slideUp();
            // slide this content up
            var content_show = jQuery(this).attr("title");
            jQuery("#"+content_show).slideDown();
    });

    jQuery(".msg_body,.msg_body2").hide();
    
    jQuery(".msg_head").click(function(){
        jQuery(this).next(".msg_body,.msg_body2").slideToggle(600);
    });


// aggiunta e rimozione utenti preferiti   

    jQuery("#fav > img").click(function(){
        var id=jQuery(this).attr("name");
        var id2=jQuery(this).attr("id");
        var id3=id2.substr(0,7);
        if (id3=='fav_del') {
            var newid="fav_add_"+id;
            jQuery(this).attr("src","/img/add.png");
            jQuery("#fav_add_"+id+"_text").show();
            jQuery(this).attr("id",newid);
            jQuery.post("/js/delfriend.php", { id: id },
            function(){
                //alert("cancellato "+id2+" ora"+newid+"controllo"+id3);
            });
        }
        
        if (id3=='fav_add') {
            jQuery(this).attr("src","/img/Recycle.png");
            jQuery("#fav_add_"+id+"_text").hide();
            var newid="fav_del_"+id;
            jQuery(this).attr("id",newid);
            jQuery.post("/js/addfriend.php", { id: id },
            function(){
                //alert("aggiunto "+id2+" ora"+newid);
            });
        }
        
    });

   
// switch tra INFO e VOX

    jQuery("#infobutton").click(function(){
        jQuery("#voxlist").slideUp(function(){
            jQuery("#infolist").slideDown();
            jQuery("#txth1vox").css("display","none");
            jQuery("#txth1info").css("display","inline");
        });
    });

    jQuery("#voxbutton").click(function(){
        jQuery("#infolist").slideUp(function(){
            jQuery("#voxlist").slideDown();
            jQuery("#txth1info").css("display","none");
            jQuery("#txth1vox").css("display","inline");
        });

    });

 



});

