jQuery(document).ready(function(){

	// mail rewrite (href)
	jQuery('a[href*="mailto:"]').each(function() {
		var mailto = jQuery(this).attr('href').split('[at]');
		jQuery(this).attr("href", mailto[0] + "@" + mailto[1]);
	});

	// mail rewrite (text node)
	jQuery('a:contains("[at]")').each(function() {
		var mailto = jQuery(this).text().split('[at]');
		jQuery(this).text(mailto[0] + "@" + mailto[1]);
	});

	jQuery(".answer").hide();
	jQuery(".question").bind('click', function() {
		jQuery(this).nextUntil(".question").toggle();
	});
	
	jQuery.ajax({ 
		// url: "http://192.168.1.8/ilse/AndroBlip.website-svn/AndroBlip.website/wp-content/themes/station-child/inc/blipfoto/BlipFoto.php",
		url: "http://androblip.huiges.nl/wp-content/themes/station-child/inc/blipfoto/BlipFoto.php",
		context: document.body,
		success: function(data) {
	    	jQuery("#header .headline").after(data);
	     }
	});
	
	if (jQuery(".blipfotoshowcase1").length > 0) {
		jQuery.ajax({ 
			// url: "http://192.168.1.8/ilse/AndroBlip.website-svn/AndroBlip.website/wp-content/themes/station-child/inc/blipfoto/BlipShowcase1.php",
			url: "http://androblip.huiges.nl/wp-content/themes/station-child/inc/blipfoto/BlipShowcase1.php",
			context: document.body,
			success: function(data) {
		    	jQuery(".blipfotoshowcase1").html(data);
		     }
		});
	}
	
	if (jQuery(".buzz").length > 0) {
	    // Declare variables to hold twitter API url and user name
	    var twitter_api_url = 'http://search.twitter.com/search.json';
	    var twitter_user    = 'AndroBlip';

	    // Enable caching
	    jQuery.ajaxSetup({ cache: true });

	    // Send JSON request
	    // The returned JSON object will have a property called "results" where we find
	    // a list of the tweets matching our request query
	    jQuery.getJSON(
	        twitter_api_url + '?callback=?&rpp=10&q=from:' + twitter_user,
	        function(data) {
				var html = '';
				var odd = true;
	            jQuery.each(data.results, function(i, tweet) {
	                // Uncomment line below to show tweet data in Fire Bug console
	                // Very helpful to find out what is available in the tweet objects
	                //console.log(tweet);

				

	                // Before we continue we check that we got data
	                if(tweet.text !== undefined) {
	                    // Calculate how many hours ago was the tweet posted
	                    var date_tweet = new Date(tweet.created_at);
	                    var date_now   = new Date();
	                    var date_diff  = date_now - date_tweet;
	                    var hours      = Math.round(date_diff/(1000*60*60));

	                    // Build the html string for the current tweet
	                    var tweet_html = '<div class="tweet' + (odd ? ' odd' : ' even') + '"><div class="tweet_text">';
	                    tweet_html    += tweet.text + '<\/div>';
	                    tweet_html    += '<div class="tweet_hours"><a href="http://www.twitter.com/' + twitter_user + '/status/' + tweet.id + '">' + hours;
	                    tweet_html    += ' hours ago<\/a><\/div></div>';

	                    // Append html string to tweet_container div
						html += tweet_html;
						if (odd == true) {
							odd = false;
						} else {
							odd = true;
						}
	                }
	            });
            
				jQuery('.buzz .copy .entry').prepend(html);
	        }
	    );
	}	
});
