function twitter( obj ) {
	var output = [];
	for (var i=0; i < obj.length; i++) {
		twit = obj[i].text.replace( /#([a-zA-Z0-9]+)/, '<a href="http://twitter.com/search?q=%23$1" target="_blank">#$1</a>' ).replace( /@([a-zA-Z0-9]+)/, '<a href="http://twitter.com/$1" target="_blank">@$1</a>' );
		output.push( '<p>' + twit + ' <br/><span>' + obj[i].created_at + '</span></p>' );
	};
	$$( '#recent-tweets' ).invoke( "insert", { "bottom" : output.join("") } ).invoke( "addClassName", "loaded" );
}
document.observe('dom:loaded', function() {

	FancyZoomBox.directory = '/wp-content/themes/rentjuice/images/fancy-zoom'; // no need for trailing slash

	/*****************************************************************************
	Font replacements
	*****************************************************************************/
	Cufon.replace( $$('h1'), {
		fontFamily: 'VistaSlab',
		fontWeight: 900,
		textShadow: '#fff 1px 1px'
	});
	Cufon.replace( $$('#tab-nav a'), {
		fontFamily: 'VistaSlabAlt',
		fontWeight: 500,
		textShadow: '#fff 1px 1px',
		hover: {}
	});

	/*****************************************************************************
	Login overlay
	*****************************************************************************/
	var opts = {duration:0.2};
	$$('#log-in-button').invoke("observe","click",function(event){
		event.stop();
		$('session-forms').appear(opts);
		$('username').activate();
	});
	$$('#session-forms, #cancel-log-in').invoke("observe","click",function(event){
		if ( event.target.id == "session-forms" || event.target.hasClassName("cancel") ) {
			event.stop();
			$('password-reset-form').hide();
			$('session-forms').fade(opts);
		}
	});
	$$('#open-reminder, #cancel-reminder').invoke("observe","click",function(event){
		event.stop();
		if ( $('password-reset-form').visible() ) {
			$('password-reset-form').fade(opts);
			$('username').activate();
		} else {
			$('password-reset-form').appear(opts);
			$('username').activate();
		}
	});

	/*****************************************************************************
	Video player overlay and player itself
	*****************************************************************************/
	if ( window.location.pathname == "/" ) {
		var flashvars = {
			autostart: "true",
			bufferlength: "0",
			backcolor : "FFFFFF",
			frontcolor : "FFFFFF",
			lightcolor : "FFFFFF",
			screencolor : "FFFFFF",
			icons : "false",
			controlbar : "none"
		};
		var params = {
			allowfullscreen : "true",
			allowscriptaccess : "always",
			wmode : "opaque"
		};
		var attributes = {};
		if ( !Prototype.Browser.IE ) {
			new FancyZoom('player-launcher');
			flashvars.file = "http://static.rentjuice.com/media/intro-video.mp4";
			flashvars.file = "http://static.rentjuice.com.s3.amazonaws.com/media/demo-video-20100713.mp4";
			// swfobject.embedSWF("/wp-content/themes/rentjuice/images/player.swf", "player", "640", "360", "9.0.0","/wp-content/themes/rentjuice/images/expressInstall.swf", flashvars, params, attributes);
		} else {
			$('player-launcher').href = '/videos/intro-video/';
		}
	}

	$$('.video-player').each(function(player){
		var flashvars = {
			file: "http://static.rentjuice.com/media/" + player.id + ".mp4"
		};
		var params = {
			allowfullscreen : "true",
			allowscriptaccess : "always",
			wmode : "opaque"
		};
		var attributes = {};
		swfobject.embedSWF("/wp-content/themes/rentjuice/images/player.swf", player.id, "640", "360", "9.0.0","/wp-content/themes/rentjuice/images/expressInstall.swf", flashvars, params, attributes);
	});

	/*****************************************************************************
	Horizontal tabs
	*****************************************************************************/
	$$('.tabbed .tabs li').invoke("observe","click",function(event){
		event.stop();
		var duration = 0.5;
		var bodies = $$('.tabbed .tab-body');
		var visible = bodies.find(function(b){return b.visible()});
		var requested = $( this.id.replace("tab-","tab-body-") );
		if ( visible != requested ) {
			$( visible.id.replace("tab-body-","tab-") ).removeClassName("active");
			this.addClassName("active");
			visible.fade({
				duration:duration,
				afterFinish: function(){
					requested.appear({duration:duration});
				}
			});
		}
	});

	/*****************************************************************************
	Support link
	*****************************************************************************/
	$$('.page-item-322').invoke("observe","click",function(event){
		event.stop();
		Zenbox.render();
	});

	/*****************************************************************************
	Support link
	*****************************************************************************/
	$$('.notification').invoke("highlight").invoke("fade",{delay:5});

	/*****************************************************************************
	Request Demo Form Validation
	*****************************************************************************/
	if ( $('request-demo-form') ) {
		$('request-demo-form').observe("submit",function(event){
			var fields = $$('#form-first-name, #form-agency').findAll(function(field){
				return ( field.value == '' || field.value == null );
			});
			if( fields.size() > 0 ) {
				event.stop();
				alert("Oops, you are missing some required values in the form. Please complete the whole form to continue.");
				fields.first().activate();
			}
		})
	}

	/*****************************************************************************
	Testimonial videos
	*****************************************************************************/
	$$( '.video-thumbnail' ).each(function(video){
		new FancyZoom(video);
	});
	
});
