// Social Media Toolbar

// This toolbar has three modes of display:
// Open:	Fully opened and expanded, viewer can see recent tweets and social media links - not stored as a state in webstateManager
// Closed:	Still visible, but viewer can only see the top "Facebook" area - uses code "c" in webstateManager
// Hidden:	No longer visible, with the exception of the tab - uses code "h" in webstateManager

$(function() {
	$("#social-media-toolbar #toolbar-tab a").click(function(e) {
		e.preventDefault();
		toggleSMT();
	});

	$("#social-media-toolbar a#hide-bar").click(function(e) {
		e.preventDefault();
		hideSMT();
	});

    // get the value from the webstate cookie for the social media toolbar (smt) key
    var cookieValue = webstateManager.getWebstateValue("smt");

    // only valid starting states are hidden and closed
    // default to closed state
    var clazz = "closed";

    // if the value is hidden, use that value
    if (cookieValue == "h") {
        clazz = "hidden";
    }

    // Set the toolbar class to value determined above
    $("#social-media-toolbar").attr("class", clazz);
});

function toggleSMT() {

	// I'll animate my content closed
	$("#social-media-toolbar .content").animate({
		"height": "toggle"
	}, 500);

	// Class-setting logic: If I was open before, I must be closed now
	if ($("#social-media-toolbar").hasClass("open")) {
		$("#social-media-toolbar").attr("class","closed");
        // store the closed value in the webstateManager for next visit
        webstateManager.setWebstateValue("smt","c");
        twitterWidget.stop();
	}

	// Class-setting logic: If I was closed (or hidden) before, I must be open now
	else {
		$("#social-media-toolbar").attr("class","open");
        twitterWidget.start();
	}
}

function hideSMT() {

	// If the user wants to hide me:
	// I'll hide my content, I'll put a "hidden" class on myself, and I'll remember to stay discreet
	$("#social-media-toolbar").attr("class", "hidden");
	$("#social-media-toolbar .content").css("display","none");
    // store the hidden value in the webstateManager for next visit
    webstateManager.setWebstateValue("smt","h");
    twitterWidget.stop();
}

// JavaScript Document
