if (typeof SSB == "undefined") var SSB = new Object();
if (typeof SSB.sing == "undefined") SSB.sing = new Object();

SSB.sing.videos = [ "zLxu0CEsDb4", "L55Yhfj2Uv8" ];

SSB.sing.wide_badge = "http://americanhistory.si.edu/starspangledbanner/_images/sing_badge_wide.gif";
SSB.sing.tall_badge = "http://americanhistory.si.edu/starspangledbanner/_images/sing_badge_tall.gif";
SSB.sing.permalink_title = "O Say Can You Sing?";
SSB.sing.permalink_url = "http://americanhistory.si.edu/starspangledbanner/sing-the-national-anthem.aspx";

SSB.setup_6300 = function ()
{
	console.log("SSB.setup_6300()");

	SSB.sing.emit_youtube(0, false);
	
	$("#featured li").each(function (i) {
		console.log("SSB.setup_6300()", i);
		
		$(this).find("img").bind("click", function () {
			SSB.sing.emit_youtube(i,true); return false;
		}).hover(function () {
			$(this).css("border", "1px solid #00549a");
		}, function () {
			$(this).css("border", "1px solid #ffffff");
		}).css("cursor", "pointer");
		
		$(this).find("a").bind("click", function () {
			SSB.sing.emit_youtube(i,true); return false;
		});
	});
}

SSB.setup_6600 = function () // sing sub-page
{
    $(".badge-url").bind("click", function() {
        $(this).select();
    });
	
	SSB.sing.bind_facebook();
	SSB.sing.bind_myspace();
}

SSB.sing.bind_facebook = function ()
{
	var u = SSB.sing.permalink_url; // location.href;
	var t = SSB.sing.permalink_title; // document.title;
	var href = "http://www.facebook.com/sharer.php?u=" + encodeURIComponent(u) + "&t=" + encodeURIComponent(t);

	$("a.share-facebook").attr("href", href).attr("target", "_blank").css("display", "block");
}

SSB.sing.bind_myspace = function ()
{
	var u = SSB.sing.permalink_url; // location.href;
	var t = SSB.sing.permalink_title; // document.title;
	var c = "<img src='" + SSB.sing.wide_badge + "' />";
	
	c = "<a href='" + u + "'>" + c + "</a>";
	
	var l = "2";
	var href = 'http://www.myspace.com/index.cfm?fuseaction=postto&t=' + encodeURIComponent(t) + '&c=' + encodeURIComponent(c) + '&u=' + encodeURIComponent(u) + '&l=' + l;

	$("a.share-myspace").attr("href", href).attr("target", "_blank").css("display", "block");
}

// http://code.google.com/apis/youtube/player_parameters.html
// http://code.google.com/apis/youtube/js_api_reference.html

SSB.sing.emit_youtube = function (which, autoplay) {
	var id = SSB.sing.videos[which];
	
	console.log("SSB.sing.emit_youtube()", which, id);

	if (swfobject.hasFlashPlayerVersion("6.0.65")) {
		var yturl = "http://www.youtube.com/v/" + id;
		
		yturl += "&enablejsapi=1&playerapiid=ytplayer"
		if (autoplay) yturl += "&autoplay=1"
		
		var expressInstall = "_swf/expressInstall.swf";
		var flashvars = { };
		var params = { menu: "false", scale: "noscale",  allowscriptaccess: "always", allowfullscreen: "true" };
		var attributes =  { };
		swfobject.embedSWF(yturl, "ytapiplayer", "425", "344", "9", expressInstall, flashvars, params, attributes);
	}
}

