switch (app)
{
	case 'hagenburg':
		var text = ( current_language == 'en' ) ? 'Latest images from Basecamp, Linz' : 'Latest images from Basecamp, Linz';            
		render_hagenburg(template_url, '/code/livebits/fh-guestbook', text);
		break;
	
	case 'wia-wia':
		var text = ( current_language == 'en' ) ? 'View the WIA<>WIA application' : 'Die WIA<>WIA Applikation Ansehen';
		render_wiawia(template_url, text);
		break;
		
	case 'taxilink':
		var text = ( current_language == 'en' ) ? 'View the Taxilink application' : 'Die Taxilink Applikation Ansehen';
		render_taxilink(template_url, '/code/livebits/taxilink', text);
		break;
		
	case 'gms':
		var image_dir = '/code/livebits/gms/';
		break;
		
	case 'microbloggingsuit':
		render_microbloggingsuit( template_url );
		break;
		
	case 'arrorro':
		var text = ( current_language == 'en' ) ? 'Latest videos' : 'Latest videos';            
		render_arrorro(template_url, text);
		break;
	
}

//--------------------------------------------------------

function render_gallery( template_dir, template_url, image_dir, text )
{
	$('.post-image').hide();

	$('.entry:first')
	    .prepend('<ul class="gallery"></ul>')
	    .prepend('<h2>' + text + '</h2>');

	$('.gallery').load( 
	    template_url + '/code/livebits/gallery/index.php', 
	    {
	        template_dir: template_dir,
	        template_url: template_url,
	        image_dir: image_dir
	    }, 
	    function() { $.superbox(); } 
	);
}

//--------------------------------------------------------

function render_hagenburg( template_url, file_path, text ) 
{
	$('.entry:first').append('<p class="view-app"><a href="' + template_url + file_path + '">' + text + ' &rarr;</a></p>');
}

function render_taxilink( template_url, file_path, text ) 
{
	$('.entry:first').append('<p class="view-app"><a rel="superbox[iframe]" href="' + template_url + file_path + '">' + text + ' &rarr;</a></p>');
}

//--------------------------------------------------------

function render_wiawia(template_url, text)
{
	$.get(template_url + '/code/livebits/wia-wia/wia-wia.py');
	// Check the canvas support
	var canvas_support = {
		canvas_compatible : false,
		check_canvas : function() {

			try {
				this.canvas_compatible = !!(document.createElement('canvas').getContext('2d')); // S60
			} catch(e) {
				this.canvas_compatible = !!(document.createElement('canvas').getContext); // IE
			} 

			return this.canvas_compatible;
		}
	}

	if (!canvas_support.check_canvas()){
    $('.entry:first').append('<a class="view-app" rel="superbox[iframe]" href="' + template_url + '/code/livebits/wia-wia/wia-wia-ie.html">' + wia_text + '</a>');
	} else {
    $('.entry:first').append('<a class="view-app" rel="superbox[iframe]" href="' + template_url + '/code/livebits/wia-wia/wia-wia.html">' + wia_text + '</a>');
	}
}

//--------------------------------------------------------

function render_microbloggingsuit( template_url )
{
		$('.post-image').hide();
		
		$('.entry:first').append('<div class="app"></div>');
		
		$('.app').load(
			template_url + '/code/livebits/microbloggingsuit/index.php', 
			{ template_url: template_url }, 
			function() { 	$('.tabbed').tabs(); twitter() }
		);
		
		function twitter()
		{
			$("#producer .twitter").tweet({
          username: "PRODUCER_MBS",
          avatar_size: 32,
					loading_text: "loading..."
      });

      $("#checkout .twitter").tweet({
          username: "CHECKOUT_MBS",
          avatar_size: 32,
					loading_text: "loading..."
      });

      $("#operator .twitter").tweet({
          username: "OPERATOR_MBS",
          avatar_size: 32,
					loading_text: "loading..."
      });
			
			$('.tabbed .twitter').each(function() {
					$(this).prepend('<h3>Latest Tweets</h3>');
			});

		}
}

//--------------------------------------------------------

function render_arrorro( template_url, text )
{
		
	$('.post-image').hide();

	$('.entry:first')
	    .append('<h2>' + text + '</h2>')
	    .append('<ul class="gallery video"></ul>');
			
	$.getJSON(template_url + '/code/livebits/arrorro/index.py',
			
			function(data) {
				$.each(data.videos, function(i,video) {
					$('.gallery').append('<li><a href="' + video.vidLink + '"><img src="' + video.imgSource +'"/></a></li>')
					if ( i == 5 ) return false;
				});
				
	});
	
}