jQuery.fn.extend({
	textNodes: function() {
		return jQuery(
			jQuery.map( this, function(n){
				return jQuery.grep(n.childNodes, function(n) {
					return n.nodeType == 3;
				});
			})
		);
	}
});

Cufon.replace('#address .org');
Cufon.replace('#address .street-address');
Cufon.replace('#address .extended-address');
Cufon.replace('#address .locality');
Cufon.replace('#address .region');
Cufon.replace('#address .postal-code');
Cufon.replace('#address .tel');
Cufon.replace('#address .email');
Cufon.replace("h2");


$(document).ready(function() {
	
	/*$('a[data-img]').each(function(){
		if($(this).attr('data-has-thumb') != 'yes') {
			$(this).attr('data-has-thumb', 'yes');
			var href = $(this).attr('data-img');
			$(this).attr('data-img', '/tools/thumb.php?src='+href);
		}
	});*/

	$('a[data-img]').live("click",function(e){
		e.preventDefault();
		
		$(this).colorbox({
			rel:"group1",
			open: true,
			transition: 'elastic',
			href: function() { return $(this).attr('data-img'); },
			opacity: 0,
			photo: true
		});
	});
	
	
	$($("#latest-tweet").textNodes()).wrap("<span></span>");
	Cufon.replace("#latest-tweet span",{separate:'words'});
	Cufon.replace("#latest-tweet a",{hover: true, separate:'characters'});

	$('.tweets').delay(0).queue(function() {
		$(this).masonry({ 
			singleMode: true,
			resizeable: true,
			itemSelector: '.tweet',
			saveOptions: false
		},function(){
			$("html").removeClass("no-js").addClass("has-js");
		});
	});

	
	$('#wall').infinitescroll({
		navSelector		: ".more",
		nextSelector	: ".more .previous",
		itemSelector	: ".tweets",
		donetext		: 'No more pages to load.',
		debug			: false,
		loadingImg		: "/assets/images/loading.gif",
		loadingText		: "",
		errorCallback: function() { 
				$('#infscr-loading').hide();   
			}
		},function( newElements ) { 
			$('.tweets').masonry({ 
				singleMode: true,
				resizeable: true,
				itemSelector: '.tweet',
				saveOptions: false
			},function(){
				Cufon.refresh();

				/*$('a[data-img]').each(function(){
					if($(this).attr('data-has-thumb') != 'yes') {
						$(this).attr('data-has-thumb', 'yes');
						var href = $(this).attr('data-img');
						$(this).attr('data-img', '/tools/thumb.php?src='+href);
					}
				});*/
			});
			
	});
});
