//apply fonts
$(document).ready(function () {
	Cufon.replace('#header ul li a, .video h2 a, #twitter_div h2 a, #twitter_update_list li span, #content .left h2, #content h3, h2, h3, h4, h5, h6', {
		fontFamily: 'Alwyn',
		hover: true,
		hoverables: { a: true }
	});
});

//make the newsletter work
$(document).ready(function() {
    $(".newsletter form #submit").click(function(event) {
        event.preventDefault();
        var input = $(".newsletter #email");
        var val = input.val();
        
        input.attr("disabled", true);
        
        $("#status").html("Sending form data...");
        
        $.post("/foundation/newsletter", {email : val}, function(data, textStatus) {
            if (data.error != undefined) {
                input.attr("disabled", false);
                $("#status").html(data.error);
            } else {
                $(".newsletter form #submit").remove();
                input.remove();
                $("#status").html("Email successfully registered.");
            }
        }, "json");
    });
});

// Setup shadbowbox
Shadowbox.init({
	skipSetup: true,
	players: ['html']
});

// Add shadowboxes
$(window).load(function () {
	
	//dipdive video links
	$('a.dipdive').click(function(e) {
		e.preventDefault();
		
		//figure out the url
		var url = $(this).attr('href');
		url = url.replace('http://africaten.dipdive.com/media/','http://play.dipdive.com/i/');
		
		//make html
		var html = '<object width="637" height="577" data="'+url+'"><param name="movie" value="'+url+'"></param><param name="allowfullscreen" value="true"><param name="flashvars" value="autoPlayVideo=true" /></param><embed src="'+url+'" type="application/x-shockwave-flash" allowFullScreen="true" width="637" height="577" flashvars="autoPlayVideo=true"/></object>';

		//show shadbow box
		Shadowbox.open({
			content: html,
			player: "html",
			viewportPadding: 0,
			width: 637,
			height: 577 + 3
	    });
	});
	
	//cooliris links
	$('a.cooliris').click(function(e) {
		e.preventDefault();
		
		//get the set id
		var url = $(this).attr('href');
		var id = url.substr(url.indexOf('/sets/')+6);
		
		//open box
		Shadowbox.open({
			content: '<div id="wall"></div>',
			player: "html",
			viewportPadding: 0,
			width: 600,
			height: 400,
			options: {
				
				//show cooliris
				onFinish : function() {

					//add add embed
					var flashvars = {
					    feed: "api://www.flickr.com/?album="+id
						, showChrome: false
						, showSearch: false
					};
					var params = {
					    allowscriptaccess: "always"
					};
					swfobject.embedSWF("http://apps.cooliris.com/embed/cooliris.swf","wall"
						, "600", "400", "9.0.0", "", flashvars, params);
				}
			}
	    });	
	});
});


