(function($){
    $.fn.swapArrows = function() {
        this.each(function(){
            if($(this).attr('src')==='/images/up.jpg'){
                $(this).attr('src', '/images/down.jpg');
            }else{
                $(this).attr('src', '/images/up.jpg');
            }
        });
        return this;
    }
})(jQuery)

$(document).ready(function(){

    // Alert messages in the private area
    $('.alert').effect("highlight", {}, 4000).slideToggle('slow',function(){$(this).remove()});
    $('.notice').effect("highlight", {}, 4000);

    // Eliminamos todos los elementos de la clase noIE
    if(jQuery.browser.msie){
        $('.noIE').remove();
    }

    $("input.submit").hover(
        function(){$(this).toggleClass('over')},
        function(){$(this).toggleClass('over')}
    );

    var user = $("#area-clientes #username");
    user.attr('value','Usuario');
    user.focus(function(){$(this).attr('value','')});
    user.blur(function(){
        if($(this).attr('value')===''){$(this).attr('value','Usuario');}
    });

    var pass = $("#area-clientes #password");
    pass.attr('value','password');
    pass.focus(function(){$(this).attr('value','')});
    pass.blur(function(){
        if($(this).attr('value')===''){$(this).attr('value','password');}
    });


    var options = {
        target:        '#output',   // target element(s) to be updated with server response
        beforeSubmit:  showRequest,  // pre-submit callback
        success:       showResponse,  // post-submit callback

        // other available options:
        url:       '/ajaxlogin',         // override for form's 'action' attribute
        //type:      type        // 'get' or 'post', override for form's 'method' attribute
        dataType:  'script'        // 'xml', 'script', or 'json' (expected server response type)
        //clearForm: true        // clear all form fields after successful submit
        //resetForm: true        // reset the form after successful submit

        // $.ajax options can be used here too, for example:
        //timeout:   3000
    };

    // bind form using 'ajaxForm'
    $('#login-form').ajaxForm(options);

    // Cargamos los acordeones del content
    $(".accordion").each(function(){
        $(this).find('h3').siblings().hide();
        $(this).find('h3').addClass('down');
        $(this).find('h3').click(function(){
            $(this).toggleClass('down');
            $(this).toggleClass('up');
            $(this).siblings().slideToggle();
        });

        $(this).find('h3').hover(
            function(){$(this).toggleClass('underlined')},
            function(){$(this).toggleClass('underlined')}
        );
    });

});

// pre-submit callback
function showRequest(formData, jqForm, options){
    $('#loader').html('<img src="/images/ajax-loader.gif" />');
    $('#output').empty();
    return true;
}

// post-submit callback
function showResponse(responseText, statusText){
    $('#loader').empty();
}