var tope = 0;
function slideshow1() {
    tope = tope - 27 ;
    if ( (tope + ($('#slideshow_container').height()) - 27 - 27) < 0) tope = 0;
    $('#slideshow_container').css('top', parseInt(tope)+'px');
}



$(document).ready(function(){
    setInterval("slideshow1()", 5000);
    $('#quickConnect').hover(function(){
        $('#slideHandler').stop(true,true).slideDown(200);
    }, function() {});
    $('#recherche').hover(function(){
        $('#slideHandler').stop(true,true).slideUp(200);
        $('#quickConnect .feedback').html('').hide();
    }, function() {});

    $('#mcLoginGo').click( function() {
        if ( $("#mc_login input[name=login]").val() != '' && $("#mc_login input[name=password]").val() != '' ) {
            $('#quickConnect .feedback').show().html('<div class="loading">Chargement</div>');
            $('#quickConnect .feedback').load('module/mycomintoo/login.php?home=1', {
                login: $("#mc_login input[name=login]").val(),
                password: $("#mc_login input[name=password]").val()
            });
        }
    });

    $('#recup_pass').click(function () {
        if ( $('#mail_recup').val() != '' ) {
            $('#quickConnect .feedback').show();
            var a = $('#mail_recup').val();
            $('#quickConnect .feedback').html('<div class="loading">Chargement</div>');
            $('#quickConnect .feedback').load('module/mycomintoo/recup_account.php?mail='+a, function(){
                $('#quickConnect .feedback a').remove();
            });

        } else $('#mail_recup').addClass('false');
    });

    $('#mc_menu a:not(#mc_create)').click( function() {
        $('#'+$(this).attr('rel')).slideDown(200);
        $('#mc_menu').slideUp(200);
    });

    $('#mc_create').nyroModal({ 
        minWidth: 700,
        minHeight: 520,
        bgColor: '#ffffff'
    });

    $("#recherche input[type=text]").keypress(function (e) {
        $("#recherche input").removeClass('false');
        if (e.which == 13) {
            $("#recherche").submit();
            return false;
        }
    });

    $('#recherche input[name=search]').click(function () {
        if ( $(this).val() == 'appartement 50m² bastille') {
            $(this).val('').css('font-style', 'normal');
        }
    });

    $('#recherche input[name=localite]').click(function () {
        if ( $(this).val() == '75011 PARIS           ') {
            $(this).val('').css('font-style', 'normal');
        }
    });

    $("input[name=localite]").autocomplete("./js/autocomplete/search.php", {
        minChars: 2,
        max: 40
    });

    $('#avancee').click(function () {
        $('#recherche').hide();
        $('#recherche_avancee').show();
    });

    $('#simplifie').click(function () {
        $('#recherche_avancee').hide();
        $('#recherche').show();
    });

    $('#estimerGo').click (function() {
        $('#recherche').attr('action','/Estimer').submit();
    });
    
    $('#recherche').submit(function () {
        $('#recherche input[name=type_transac]').val($('#transac input:checked').val());

        if ( $('#recherche input[name=search]').val().length < 2 ) {
            $('#recherche input[name=search]').stop(true,true).effect("highlight", { 
                color : 'red'
            }, 1000).focus();
            return false;
        }
        if ( $('#recherche input[name=localite]').val().length < 2 ) {
            $('#recherche input[name=localite]').stop(true,true).effect("highlight", { 
                color : 'red'
            }, 1000).focus();
            return false;
        }

        $('#popUp').show();
    });


    $('#recherche_avancee').submit(function () {
        if ( $('#recherche_avancee input[name=localite]').val().length < 2 ) {
            $('#recherche_avancee input[name=localite]').stop(true,true).effect("highlight", { 
                color : 'red'
            }, 1000).focus();
            return false;
        }
        var str = '';

        if ( $('#adv_tb .chkbox_checked').attr('rel') != '' ) str = $('#adv_tb .chkbox_checked').attr('rel');
        if ( $('#adv_annonceur .chkbox_checked').attr('rel') != '' ) str += ' '+$('#adv_annonceur .chkbox_checked').attr('rel')+' ';

        // prix
        if ( $('input[name=prix_min]').val().length > 0 ) { 
            if ( $('input[name=prix_max]').val().length > 0 ) {
                str += ' entre '+$('input[name=prix_min]').val()+' et '+$('input[name=prix_max]').val()+'€ ';
            } else str += ' > '+$('input[name=prix_min]').val()+'€ ';
        } else if ( $('input[name=prix_max]').val().length > 0 ) {
            str += ' < '+$('input[name=prix_max]').val()+'€ ';
        }
        //surface
        if ( $('input[name=surf_min]').val().length > 0 ) {
            if ( $('input[name=surf_max]').val().length > 0 ) {
                str += ' entre '+$('input[name=surf_min]').val()+' et '+$('input[name=surf_max]').val()+' m² ';
            } else str += ' > '+$('input[name=surf_min]').val()+' m² ';
        } else if ( $('input[name=surf_max]').val().length > 0 ) {
            str += ' < '+$('input[name=surf_max]').val()+' m² ';
        }
        if (str == '') { 
            str = 'indifférent';
        }

        $('#recherche_avancee input[name=search]').val(str);
    });

    $('#adv_tb a, #adv_annonceur a').click(function () {
        if ($(this).attr('class') == 'chkbox') {
            $(this).parent().find('a').addClass('chkbox');
            $(this).parent().find('a').removeClass('chkbox_checked');
            $(this).removeClass('chkbox');
            $(this).addClass('chkbox_checked');
        }
        return false;
    });

});