$(function(){
    // hide all more info div's onload
    $("li.moreinfo").hide();

    // trigger on text with class "showmoreinfo"
    $("li.showmoreinfo").click(
        function() {
			var bookmark = this.id;
            if ( $("#"+bookmark+"_moreinfo").css("display") == 'none' ) {
                $("li.moreinfo").slideUp(1500);                   // hide all more information div's
				$("li.open").removeClass('open');
				
                $("#"+bookmark+"_moreinfo").slideDown(1500);
         // show the more information div
				$(this).addClass('open');
            }
            else {
                $("#"+bookmark+"_moreinfo").slideUp(1500)         // hide more information
				$(this).removeClass('open');
            }
            $.scrollTo("p#"+bookmark);                      // scroll to bookmark
        }
    );

    // show more info bookmark?
    showBookmark();

    // trigger on arrows
    $("img.hidemoreinfo").click(
        function(){
            var moreinfoli = $(this).parents('li.moreinfo');
            $(moreinfoli).hide();
        }
    );
});

function showBookmark() {
    var url = window.location.href;
    var bookmarkStart = url.indexOf("#");

    // another option -- doesn't require exact the same id-name for the paragraph
    if ( bookmarkStart != -1 ){
        var bookmark = url.substr(bookmarkStart + 1);
        var pid = $("a[name="+bookmark+"]").parent("p").attr("id");     // look for a regular bookmark tag inside a paragraph
        if ( ! pid ) {
            pid = bookmark;                                 // assume the paragraph has an id with the same name as the bookmark
        }

        $("p#"+pid).click();                                // force click to trigger the click action
    }
}
