function openContent(obj,hgt) {

        $('#body-bg div.slider').css('width',0);
        $('#body-bg div.slider').css('height',hgt);
        $('#body-bg div.slider').html('');

        $('#body-bg div.slider').animate({
                width: '816px'
            }, {
                duration: 500,
                specialEasing: {
                width: 'linear',
                height: 'easeOutBounce'
            },
            complete: function() {
                $(this).html(obj);
            }
        });
    }

    function openSection(obj) {
        $('#body-bg div.slider').animate({
                height: '416px'
            }, {
                duration: 500,

            complete: function() {
                $(this).html(obj);
            }
        });
    }

    $('.menu ul li a').live('click',function(){
        sect = $(this).attr('title');
        hgt = '416px';

        if (sect == 'prenotazioni') return false;

        if (sect == 'alloggi' || sect == 'photogallery')
            hgt = '84px';

        if (sect == 'offertespeciali')
            hgt = '160px';

        $.post("listener.php", { section: sect  },
           function(data){
             openContent(data,hgt);
        });
    })

    $('.structure-choose a').live('click',function(){
        sect = $(this).attr('title');

        $.post("listener.php", { section: sect  },
           function(data){
             openSection(data);
        });

    });

    $('.sr-lnk').live('click',function(){

        nsrc = $(this).attr('href');

        $('.cleft img').attr('src',nsrc);

        return false;


    });

    $('.languages a').live('click',function(){
        lan = $(this).attr('title');

        $.post("listener.php", { section: 'switchlan',language: lan  },
           function(data){
             window.location.reload();
        });
    })

    function moveR() {
        if (x == $('li').length) return false;
        else
        x++;
        $(".comment-slider").animate({left:-776 * x}, "fast")
    }

    function moveL() {

        if (x == 0) return false;
        else
            x--;
            $(".comment-slider").animate({left:-776 * x}, "fast")
    }


    x = 0;

    $('#next').live('click',function()
    {
        moveR();
    });

    $('#prev').live('click',function()
    {
        moveL();
    });

    function leave_comment() {
        $.post("listener.php", { section: 'leave_comment'  },
           function(data){
             openContent(data,'416px');
        });
    }

    $('#submit_comment').live('click',function(){

        var anagrafica = document.getElementsByName('anagrafica')[0].value;
        var email = document.getElementsByName('email')[0].value;
        var commento = document.getElementsByName('commento')[0].value;
        
        $.post("listener.php", { section: 'submit_comment',anagrafica: anagrafica, email: email, commento: commento },
           function(data){

             if (data == 'empty_fields')
                 $('.comment_form span:last').append('<br><span>devi compilare tutti i campi</span>')
             else
                $('.comment_form').html(data);
             return false;
        });
        
        return false;
    })
