$(document).ready(function()
{
    initLytebox();
    
    if($('ul#slider-list').length > 0)
    {
        $('ul#slider-list').Imagebar();
    }

    // Abschicken der Suchmaske    
    $('#offer-submit').click(function()
    {
        $.post("ajax.php?interface=rental_list", $('#form_offers').serialize(), function(data)
        {
            $('#rental-list').html(data);
        });
    });
    
    // Nachladen der Stadtteile
    $('#offer-city').change(function()
    {
        $.post("ajax.php?interface=rental_districts&id=" + $(this).attr('value'), $('#form_offers').serialize(), function(data)
        {
            $('#offer-district').html(data);
            $('#offer-district').removeAttr('disabled');
        });
    });

    // Details eines Objekts einblenden    
    $('ul.rental-list li a').live("click", function()
    {
        $.post("ajax.php?interface=rental_details&id=" + $(this).attr('rel'), function(data)
        {
            var width = $('#rental-search').width();
            
            if(width > 0)
            {
                $('#rental-details').html(data);
                
                $('#rental-search').animate({width: 0}, 1500, function()
                {
                    $('#rental-tools').width(0);
                    $('#rental-tools').show();
                    $('#rental-tools').animate({width: "35px"}, 1000, function()
                    {
                        $('#rental-details').fadeIn(1500);
                        
                        myLytebox.initialize();  
                    });    
                });
            }
            else
            {
                $('#rental-details').fadeOut(1500, function()
                {
                    $(this).html(data);    
                    $(this).fadeIn(1500);
                    
                    myLytebox.initialize();                    
                });
            }
        });
        
        return false;
    });

    // Details ausblenden    
    $('#rental-tools-search').click(function()
    {
        $('#rental-details').fadeOut(1500, function()
        {
            $(this).html("");
            
            $('#rental-tools').animate({width: 0}, 1000, function()
            {
                $(this).hide();
                $('#rental-search').animate({width: "340px"}, 1500);
            });    
        });
    });
    
    $('#rental-navigator a').live("click", function()
    {
        
        $.post("ajax.php?interface=rental_list&page=" + $(this).attr("rel"), function(data)
        {
            $('#rental-list').html(data);    
        });
        
        return false;    
    });
    
});


