// TWITTER SETTINGS
var twitteruser = 'SminCM';

// Start functioning when DOM is ready

$( function()

{

	// Set the BBC Newsticker
	$.ajax({
		url: '../deelnemers.ajax.html',
		success: function(d,t,x)
		{
			$('#news').empty().html(d);
			$().newsTicker({
				newsList: '#news',
				startDelay: 10,
				tickerRate: 40,
				loopDelay: 800
			});
		}
	});
	// Link between small and big speakers

	$('.speaker, .extra.dagvoorzitter, .extra.deejay').click( function() {

		var rel = $(this).attr( 'rel' );

		

		$('.popup_spreker:visible').hide();

		$('.popup_spreker[rel="'+rel+'"]').fadeIn( 'fast' );

	});

	

	// Close on crossclick

	$('.popup_spreker > .close > a').click( function() {

		$(this).parent().parent().fadeOut( 'fast' );

	});
	
	
	// Link 'programma' anchors with popups on the index
	$('.programma tbody tr .item a').click( function()
	{
		// Get persons Name
		var personName = $(this).text();
		
		// Split person's name
		var personName = personName.split( ' ' );
		
		// Get the person's last name
		var lastName = personName[ (personName.length-1) ].toLowerCase();
		
		// Goto the index with the correct name
		window.location = 'index.html#'+lastName;
		
		return false;
	});
	
	// Get the window location's hash (index.html)
	var hash = window.location.toString().split('#')[1];
	
	// Open a possible existing popup (index.html)
	$('.popup_spreker[rel="'+hash+'"]').show();
	
	// Load latest tweet
	$.getJSON('http://api.twitter.com/1/statuses/user_timeline/'+twitteruser+'.json?callback=?&count=1', function(obj)
	{
		// Get text and generate url
		var tweet = obj[0].text.replace( /(http:\/\/\S+)/, '<a href="$1" target="_blank">$1</a>' );
		
		// Update tweet
		$('.block_content_twitter p').html(tweet);
	});

});


// Define include function
var include = function( path, id )
{
	// Set original path
	var origPath = path;
	
	// IE6 fix
	if ( /MSIE 6/.test(navigator.userAgent) )
		//path = 'http://demo.7u.nl/whatsnext01/'+path;
		path = 'http://www.whatsnext03.nl/'+path;
	
	//$.get(path, false, function(r) { $('#'+id).empty().html(r); });
	$.get(path, false, function(r) {
		r = $(r).hide();
		
		$('#'+id)
			.empty()
			.html(r)
			.find('a')
			.fadeIn('normal');
	
		setTimeout( 'include(\''+origPath+'\', \''+id+'\')', 5000 );
	});
};

