$(document).ready(function() {

   $('a.friend ').click(function (e) {

        e.preventDefault(); //prevent the link from doing default behaviour

        var subject =''; //the emails subject

        var body = '';  //the emails body

        // Eingefügt von Jacob - 05.12.2008
        //var title_str = $('h2').text();
        subject += 'DHPG Link'+ '\n';

        //subject += 'DHPG - ' + str.replace(/&auml;/g,"ä") + '\n';
        //$('h2').text()
        body += 'This Article would be interesting for you:\n' +
                "Link: " + window.location;

       window.location = "mailto:?subject="+escape(subject)+"&body="+escape(body); //escape encodes html entities



   });//end tell friend


    // go for the good old toggling

    //make it reusable by abstracting the header click element
    var list_header = $('div#list1 h3,div#list2 h3');  
    var open_header = $('div#list1 h3#open_partner,div#list2 h3#open_team,#pers_ansprechp div#list1 h3');
    //var open_header = $('div#list1 h3,div#list2 h3');
    //initially hide the element directly after the h3
    list_header.next().hide();
    open_header.next().show();

    //append the click events for individual open/closing
    list_header.click(function() {
        toggleElement(this);
    });
    //go for the open/close all
    $('.open_all').click(function (e) {
        //prevent the default link behavior, not needed if img is used
        e.preventDefault();
        //for each list element call toggle function
        open_all(list_header);
    });

    //go for the close all
    $('.close_all').click(function (e) {
        //prevent the default link behavior, not needed if img is used
        e.preventDefault();
        //for each list element call toggle function
        close_all(list_header);
    });

    //end toggling

   //set date
   var currentTime = new Date();
   var month = currentTime.getMonth() + 1;
   var day = currentTime.getDate();
   var year = currentTime.getFullYear();
   $('#date').text(day + "." + month + "." + year);

   //append change event to language select
   $('#tablelang').change(function () {
        parent.frames.top.location.href = this.value;
   });
 });

 /**
 * utility function to toggle elements
 * detects wether an elements is visible and if so closes it
 * the opening goes the other way round
 * @param String - a dome element h3.myClass / #myId / ..
 */
function toggleElement(el)
{
    if($(el).next().is(':visible'))
    {//already open, close it

        hideElement(el);
    }
    else
    {//closed .. so open it
        showElement(el);
    }
}

function close_all(el)
{
    $(el).each(function(){

        if($(this).next().is(':visible'))
        {
            hideElement(this);
        }
    });
}

function open_all(el)
{
    $(el).each(function(){

        if($(this).next().is(':hidden'))
        {
            showElement(this);
        }
    });
}

/**
* shows the element next/after to the given element
* adds a class "open" to the element
*/
function showElement(el)
{
    $(el).next().slideDown('slow');
    $(el).addClass('open');
}
/**
* hides the element next/after to the given element
* removes open class from element
*/
function hideElement (el)
{
    $(el).next().slideUp('slow');
    $(el).removeClass('open');
}
