$(document).ready(function() {


    var options = {
        target: '#contact_alert',
        beforeSubmit:  showRequest,
        success:       showResponse,
        error:          showError

    };
    $('#FeedbackFormular').ajaxForm(options);
});

$.fn.clearForm = function() {
    return this.each(function() {
        var type = this.type, tag = this.tagName.toLowerCase();
        if (tag == 'form')
            return $(':input', this).clearForm();
        if (type == 'text' || type == 'password' || tag == 'textarea')
            this.value = '';
        else if (type == 'checkbox' || type == 'radio')
            this.checked = false;
        else if (tag == 'select')
            this.selectedIndex = -1;
    });
};


$(function() {

    $("html").removeClass("no-js");


    // enable circular scrollables with a click handler
    $(".scroll").scrollable({ circular: false }).click(function() {

    });

    var
            speed = 1000,   // animation speed
            $wall = $('#wrapper').find('.wrap')
            ;

    $wall.masonry({
        columnWidth: 50,
        // only apply masonry layout to visible elements
        itemSelector: '.box:not(.invis)',
        animate: true,
        animationOptions: {
            duration: 750,
            easing: 'linear',
            queue: false
        }
    });

    $('.filtering-nav a').click(function() {
        var colorClass = '.' + $(this).attr('class');

        if (colorClass == '.all') {
            // show all hidden boxes
            $wall.children('.invis')
                    .toggleClass('invis').fadeIn(speed);
        } else {
            // hide visible boxes
            $wall.children().not(colorClass).not('.invis')
                    .toggleClass('invis').fadeOut(speed);
            // show hidden boxes
            $wall.children(colorClass + '.invis')
                    .toggleClass('invis').fadeIn(speed);
        }
        $wall.masonry();

        return false;
    });


    // hides the slickbox as soon as the DOM is ready
    // (a little sooner than page load)
    $('#contact_pop').hide();
    // shows the slickbox on clicking the noted link


    // toggles the slickbox on clicking the noted link
    $('.email').click(function() {
        $('#contact_pop').slideToggle(400);
        return false;
    });


    var $elem = $('.home');


    $('#none-filtering').click(
            function (e) {
                $('html, body').animate({scrollTop: $elem.height()}, 800);
            }
    );


    $("#twitter").getTwitter({
        userName: "socialoroe",
        numTweets: 2,
        loaderText: "Loading tweets...",
        slideIn: true,
        showHeading: true,
        headingText: "Aktuelle Tweets",
        showProfileLink: true
    });


});

function showRequest(formData, jqForm, options) {
    $('#contact_message').show();
    $('#contact_alert').hide();
    $('#contact_message').html('Ihr Nachricht wird übermittelt.....');
    $('#FeedbackFormular').hide();
    $('#submitbutton').hide();
    return true;
}
function showResponse(responseText, statusText, xhr, $form) {
    if (responseText != 'gesendet') {
        $('#FeedbackFormular').show();
        $('#contact_alert').show();
        $('#contact_message').hide();
        $('#contact_alert').html(responseText);
        $('#submitbutton').show();
    } else {

        $('#contact_message').show();
        $('#contact_message').html('Ihre Nachricht wurde gesendet.');


    }
}
function showError() {
    $('#FeedbackFormular').show();
    $('#contact_message').hide();
    $('#contact_alert').show();
    $('#contact_alert').html('Fehler beim &uuml;bermitteln der Nachricht, bitte versuchen Sie es später erneut.');
    $('#submitbutton').show();
}
