$(document).ready(function() {
    //Accordion
    $(".accordion-detail, #accordion-small").accordion({
        autoHeight: false
    });
    //Tabs
    $("#tabs, #tabs-heading").tabs();

    //social bookmarks
    $("#social ul").replaceWith("<ul><li><strong>Bookmark using:</strong></li><li><a href='http://del.icio.us/post?url=" + document.location.href + "&title=" + document.title + "' class='delicious'>Del.icio.us</a></li><li><a href='http://www.facebook.com/sharer.php?url=" + document.location.href + "&title=" + document.title + "' class='fb'>Facebook</a></li><li><a href='http://twitter.com/submit?url=" + document.location.href + "&title=" + document.title + "' class='tw'>Twitter</a></li><li><a href='http://www.stumbleupon.com/submit?url=" + document.location.href + "&title=" + document.title + "' class='su'>StumbleUpon</a></li><li><a href='http://digg.com/submit?url=" + document.location.href + "&title=" + document.title + "' class='digg'>Digg</a></li><li><a href='http://reddit.com/submit?url=" + document.location.href + "&title=" + document.title + "' class='reddit'>Reddit</a></li></ul>");


    //add print and email tab
    $("#additional").append('<div id="functab"><ul><li><a class="email" href="#" title="Email to a friend">Email to a friend</a></li><li><a class="print" href="#" title="Print this page">Print this page</a></li></ul></div>');
    //add print and email tab
    $("#functab").css("display", "block");

    //email
    $("#functab a.email").click(function() {
        mailpage();
        return false;
    })

    //print
    $("#functab a.print").click(function() {
        window.print();
        return false;
    })




    //board of directors

    //hide all divs with class of answer
    $("div.member").hide();
    $("#board-wrap").show();
    $("#board-wrap ul").show();

    /*
    get all div's that are links with the class of memberAnchor and run the function on each of them (.each is jquery specific) 
    using an array to add +1 each time it runs so matches up the board member and board member profile. Index increments each time the loop is run
    */
    $('a.memberAnchor').each(function(index) {

        //$(this) equals the current anchor
        $(this).click(function() {
            $("#member-wrap").removeClass("nojs");
            //Overlay on
            $("body").append('<div id="trans-overlay">&nbsp;</div>');
            //remove non javscript layout class

            //appending the close button 
            $("div.member-module").append('<div class="member-close"></div>');

            //hide all open divs with class of member
            // $("div.member").hide();

            //get the corrsponding div from array referenced by Index and show it
            $('div.member:eq(' + index + ')').show();

            $("div.member-close").click(function() {
                $("div#trans-overlay").remove();
                $("div.member").hide();
            });
            return false;

        });
    });


});



//email script

function mailpage() {
    //alert(document.title);
    mail_str = "mailto:?subject=Marks%20%26%20Spencer%20Annual%20Report%202009";
    mail_str += "&body=I%20thought%20you%20might%20be%20interested%20in%20this:%20" + location.href;
    location.href = mail_str;
}

//removes the outline from around any link
function unblur() {
    this.blur();
}

function blurLinks() {
    if (!document.getElementById) return;
    theLinks = document.getElementsByTagName("a");
    for (i = 0; i < theLinks.length; i++) {
        theLinks[i].onfocus = unblur;
    }
} 