$(document).ready(function(){
    /********************************************
    ********************************************/

    /* Setzt den Focus auf das Input-Feld mit der Klasse "focusMe" beim Aufruf der Seite */
    $('input.focusMe').focus();

    /********************************************
    ********************************************/

    /* Alle internen Links weich scrollen lassen 
    $('a[@href^="#"]').click(function() {
        var parts        = this.href.split('#');
        var scrolltarget = '#' + parts[\1];
        $(scrolltarget).ScrollTo(800);
        return false;
    });
    */

    /********************************************
    ********************************************/

    /* Hat ein Link eine Klasse namens confirm, bekommt er via Javascript eine Frage, die in rel steht */
    $('.confirm').click(function() {
        return confirm($(this).attr('rel'));
    });
    $('a.bestellen').click(function() {
        return confirm('Wollen Sie diesen Artikel in Ihren Warenkorb legen?');
    });
    $('a.bestellen_en').click(function() {
        return confirm('Do you want to add this article to your cart?');
    }); 
    /********************************************
    ********************************************/

    /* Download-Links führen als URL den Dateinamen selbst. Damit der Linksklick funktioniert (Download startet, Seite wechselt aber nicht zur Datei),
    muss der in "rel" angegebene Link eingetragen werden als href */
    /*
    $('a.download').click(function() {
        var new_url = $(this).attr('rel');
        $(this).attr('href', new_url);
        return true;
    });
    */

    /********************************************
    ********************************************/

    /* Aktive Input-Felder */
    $('input').focus(function(){
        $(this).parent().addClass('active');
    });
    $('input').blur(function(){
        $(this).parent().removeClass();
    });

    /********************************************
    ********************************************/

    /* Markieren von Tabellenzeilen ermöglichen */
    $('table tbody tr').click(function() {
        $(this).toggleClass('marked');
    });
    $('ol.markable li').click(function() {
        $(this).toggleClass('marked');
    });

    /********************************************
    ********************************************/

    /* Misc */
    $('.shakeMe').Shake(3);

    $('#message').each(function(){
        setTimeout('showMessage()', 1500);
        setTimeout('hideMessage()', 7000);
    });

    /********************************************
    ********************************************/

    $('select.submit').change(function() {
        this.form.submit();
    });

    /********************************************
    ********************************************/
    /* E-Mails umwandeln: <a href="mailto:box [at-no-spam] server.tld">title</a> */
    $('a[@href^=mailto]').each(function(){
        var to_replace = '=at-no-spam=';
        var link       = $(this).attr('href').replace(to_replace, '@');
        var address    = $(this).html().replace(to_replace, '@');

        $(this).html(address);
        $(this).attr('href', link);
    });

});

function showMessage(element) {
    $('#message').slideDown('slow');
}
function hideMessage(element) {
    $('#message').fadeOut(2000);
}

