Cufon.replace('.bso #content h2', {fontFamily: 'Steinem', hover: true, textShadow: "#000 -1px -1px"});
Cufon.replace('.bso #sideContent h4', {fontFamily: 'Steinem', hover: true, textShadow: "#000 -1px -1px"});
Cufon.replace('.yvis h2, .yvis h3, .yvis h4, .yvisContent legend, #yvisNav li, #yvisBlog .siteLink a, #yvisHome .question, .yvisContent .question li a, .yvis #yvisResultsWrapper>p', {fontFamily: 'Robot!Head', hover: true});
Cufon.replace('#intro', {fontFamily: 'Gill Sans Light'});
$(document).ready(function() {
	if (jQuery.browser.msie) { 
		$('h2:first-child').css({'marginTop': 0});
	}
	
	/***************************************************************************
	 * Message Stream Animation
	 ***************************************************************************
	 * TODO: Unify start/stop mechanisms Ð event name spacing? Unbinding?
	 ***************************************************************************
		 * DONE: Loop stream so messages don't just stop.
	 * DONE: Stop stream speeding up message display when it is stopped and started in quick succession
	 		 Basically stop there being two messages animating at one time.
	 * DONE: Messages are displayed at random rather then by date/time.
	 * DONE: Retrieve messages via AJAX as JSON/XML.
	 * DONE: Differentiate items in stream from different services (eg. Twitter and YouTube)
	 ***************************************************************************/
	 
	jQuery.log = function(message) {
		if(window.console) {
			console.debug(message);
		} else {
			//alert(message);
		}
	};
	
	(function($) { /* Create closure */
	$.fn.animateMsg = function(options) {
		/* Set default options */
		var defaults = {
			/* Element type */
			elementType: 'li',
			/* Animation type */
			animType: 'blind',
			/* Direction of animation */
			animDirection: 'vertical',
			/* Duration of animation */
			animSpeed: 'slow'
		}
		
		/* Allow default options to be extended */
		var settings = $.extend({}, defaults, options);
			
		return $(this).each(function() {
			/* Check element is what we're after */
			if ($(this).is(settings.elementType)) {
				/* Animate the element */
				$(this).toggle(settings.animType, {direction: settings.animDirection}, settings.animSpeed);
			} else {
				/* We're not working on the correct element, output an error */
				//$.log('Element isnt a ' + settings.elementType + ' item.');
			}					
		});
	}
	})(jQuery); /* End closure */
	
	(function($) { /* Create closure */
	$.fn.animateStream = function(options) {
		/* Set default options */
		var defaults = {
			/* Store original messsages object */
			objMsg: [],
			/* Temporary object for manipulating message stream */
			tmpObjMsg: [],
			/* Delay between messages showing */
			delay: 3000,
			/* Stop stream toggle */
			stop: 0,
			/* Animated toggle */
			running: 0,
			/* First play toggle */
			firstPlay: 0, 
			/* Development toggle */
			dev: 0
		}
		
		/* Allow default options to be extended */
		var settings = $.extend({}, defaults, options);
										
		/* Load a temporary object with messages */
		function reloadMsgObj() {
			//$.log('Reloading and randomising order of message array');
			/* Create a copy of the messages object */
			$.extend(settings.tmpObjMsg, settings.objMsg);
			/* Randomise order of messages */
			settings.tmpObjMsg.sort(function() { return 0.5 - Math.random() });
			//$.log('Reloading and randomising message array successful');
		}
									
		return $(this).each(function() {
			/* Store stream element */					
			var s = $(this);
			
			function animate() {
				/* Stream is playing and not currently animating */
				if (settings.stop == 0 && settings.running == 0) {						
					/* Check if the temporary message object has content */
					if (settings.tmpObjMsg.length > 0) {
						
						/* Store class name for message service */
						var msgClass;
						/* Check for type of service */
						switch (settings.tmpObjMsg[0].service) {
							case 'twitter':
								msgClass = 'twitter';
								break;
							case 'youtube':
								msgClass = 'youtube';
								break;
							default:
								break;
						}
						
						/* Store message text and activate links */
						var msgText = settings.tmpObjMsg[0].response
							.replace(/((https?:\/\/|www\.)([-\w\.]+)+(:\d+)?([-\w\/\_\.]*)?(\?\S+)?)+/,'<a href="$1">$1</a>')
							.replace(/(#yvisLove)/i,'');
							//.replace(/(Rawkes)+/i, '<span class="term">$1</span>');
						/* Create direct link to Tweet */
						var msgLink = 'http://twitter.com/' + settings.tmpObjMsg[0].username + '/statuses/' + settings.tmpObjMsg[0].external_id;
						/* Create html element for message and add service class */
						if (settings.tmpObjMsg[0].service_id == 1) {
							var msgLi = $('<li><span class="term">' + settings.tmpObjMsg[0].username + '</span> &ndash; ' + msgText + '</li>').addClass(msgClass);
						} else if (settings.tmpObjMsg[0].service_id == 2) {
							var msgLi = $('<li><span class="term">' + settings.tmpObjMsg[0].username + '</span> &ndash; ' + msgText + '&nbsp;<a href="' + msgLink + '">&laquo;</a></li>').addClass(msgClass);
						}
						/* Set mouse events for the message element */
						msgLi.mouseover(function() {
							/* Highlight message on mouse-over */
							$(this).css({backgroundColor: 'rgba(51,51,51,0.5)'});
							/* Set stream to stop playing */
							settings.stop = 1;
						}).mouseout(function() {
							/* Remove highlight */
							$(this).css({backgroundColor: ''});
							/* Set stream to start playing */
							settings.stop = 0;
							/* Wait 1/2 a second and animate the stream */
							var t = setTimeout(function() {
								animate();
							}, 500);
						});
						
						/* Animation is running */
						settings.running = 1;
						
						/* Hide message, insert it into the stream and animate it */
						msgLi.hide().prependTo(s).animateMsg().animate({opacity: 1}, settings.delay, function() {
							/* Remove first item from the stream object */
							settings.tmpObjMsg.splice(0,1);
							/* Animation is over */
							settings.running = 0;
							/* Check if stream is playing */
							if (!settings.stop) {
								/* Animate the stream */
								animate();
							}
						});
					/* Check if the main message object has content */
					} else if (settings.objMsg.length > 0) {
						//$.log('Temporary message object is empty');
						/* Reload the temporary message object with content if there are more than enough messages to fill the stream */
						if (settings.firstPlay != 0 && settings.objMsg.length > 15) {
							reloadMsgObj();
							/* Animate the stream */
							animate();
						} else if (settings.firstPlay == 0) {
							//$.log('Animating stream for first time');
							settings.firstPlay = 1;
							reloadMsgObj();
							/* Animate the stream */
							animate();						
						} else {
							//$.log('Not enough messages to fill the screen completely');
						}
					/* Main message object is empty. There must be no messages in the stream. */
					} else {
						//$.log('Main message object is empty');
					}
				/* Stream is currently animating */
				} else if (settings.running == 1) {
					//$.log('Animation is running so command has been ignored');
				/* Stream is stopped */
				} else {
					//$.log('Stream stopped');
				}
			}
			
			if (settings.dev) {
				var ctrlBoxHtml = $('<p id="controlBox">\n<span class="streamControl">Stop Stream</span>\n</p>');
				
				/* Hide start button */
				ctrlBoxHtml.find('#streamStart').hide();	
				
				ctrlBoxHtml
					.mouseover(function(){ $(this).css({paddingTop: '13px'}) })
					.mouseout(function(){ $(this).css({paddingTop: '10px'}) })
					.click(function() {
						if (settings.stop == 0) {
							settings.stop = 1;
							$(this).html('Start Stream').css({backgroundColor: '#2BA039'})
						} else if (settings.stop == 1) {
							if (!settings.running) {
								$('#streamStop').show();
								$(this).html('Stop Stream').css({backgroundColor: '#A00020'});
								settings.stop = 0;
								animate();
							}
						}					
					});						
				
				$(this).before(ctrlBoxHtml);
			}
			
			/* Kick start animation */
			animate();
		});
	}
	})(jQuery); /* End closure */
});