	function stopStream() {
		$('#player_status').html('<div id="vic_load"></div> Stopped');
	}

	function resetStream() {
		$("#vic_radio_player").jPlayer( "clearMedia" );
		$('#vic_radio_player').jPlayer( "setMedia", { mp3: "http://www.live365.com/play/326059?sid=209.201.113.2-1304054501142&lid=&from=pls"});	
	}

	function canPlay() {
		$('#player_status').html('Stream Ready!');
	}

	function liveStream() {
		$('#player_status').html('Streaming...');
	}
	

	$('div#open> a').click(function () {
		$('div#splash').fadeOut('slow'); 
   		$('div.hidden').delay(500).fadeTo('slow',1);
	});
	
	$('#ribbon').click(function () {
   		$('#ribboninfo').fadeToggle('slow');
	});
	
$('#dashboard').click(function(){
	$.ajax({
  		type: 'GET',
 		url: 'index.php',
 		dataType: 'html',
  		
  		beforeSend:function(){
  			$('#main').slideUp('normal');
   			// this is where we append a loading image
			$('#container').append('<div id="load">LOADING...</div>');
			$('#load').fadeIn('normal');  		
		},
  		
  		success:function(data){
    		// successful request; do something with the data
      		$('#main').load('index.php #main');
  		},
  		
 		error:function(){
    		// failed request; give feedback to user
    		$('#main').html('<p class="error"><strong>Oops!</strong> Try that again in a few moments.</p>');
  		},
  		
  		complete:function(){
  			$('#load').delay(3000).fadeOut('normal');
    		$('#main').delay(3500).slideDown('slow');
    		$.getScript("js/dashboard.js");
 		}
  
	});	
});


$('#staff').click(function(){
	$.ajax({
  		type: 'GET',
 		url: 'staff.php',
 		dataType: 'html',
  		
  		beforeSend:function(){
  			$('#main').slideUp('normal');
   			// this is where we append a loading image
			$('#container').append('<div id="load">LOADING...</div>');
			$('#load').fadeIn('normal');  		
		},
  		
  		success:function(data){
    		// successful request; do something with the data
      		$('#main').load('staff.php #main');
  		},
  		
 		error:function(){
    		// failed request; give feedback to user
    		$('#main').html('<p class="error"><strong>Oops!</strong> Try that again in a few moments.</p>');
  		},
  		
  		complete:function(){
  			$('#load').delay(3000).fadeOut('normal');
    		$('#main').delay(3500).slideDown('slow');
 		}
  
	});	
});

$('#events').click(function(){
	$.ajax({
  		type: 'GET',
 		url: 'events.php',
 		dataType: 'html',
  		
  		beforeSend:function(){
  			$('#main').slideUp('normal');
   			// this is where we append a loading image
			$('#container').append('<div id="load">LOADING...</div>');
			$('#load').fadeIn('normal');  		
		},
  		
  		success:function(data){
    		// successful request; do something with the data
      		$('#main').load('events.php #main');
  		},
  		
 		error:function(){
    		// failed request; give feedback to user
    		$('#main').html('<p class="error"><strong>Oops!</strong> Try that again in a few moments.</p>');
  		},
  		
  		complete:function(){
  			$('#load').delay(3000).fadeOut('normal');
    		$('#main').delay(3500).slideDown('slow');
 		}
  
	});	
});

$('#marathon').click(function(){
	$.ajax({
  		type: 'GET',
 		url: 'marathon.php',
 		dataType: 'html',
  		
  		beforeSend:function(){
  			$('#main').slideUp('normal');
   			// this is where we append a loading image
			$('#container').append('<div id="load">LOADING...</div>');
			$('#load').fadeIn('normal');  		
		},
  		
  		success:function(data){
    		// successful request; do something with the data
      		$('#main').load('marathon.php #main');
  		},
  		
 		error:function(){
    		// failed request; give feedback to user
    		$('#main').html('<p class="error"><strong>Oops!</strong> Try that again in a few moments.</p>');
  		},
  		
  		complete:function(){
  			$('#load').delay(3000).fadeOut('normal');
    		$('#main').delay(3500).slideDown('slow');
 		}
  
	});	
});

$('#podcast').click(function(){
	$.ajax({
  		type: 'GET',
 		url: 'podcast.php',
 		dataType: 'html',
  		
  		beforeSend:function(){
  			$('#main').slideUp('normal');
   			// this is where we append a loading image
			$('#container').append('<div id="load">LOADING...</div>');
			$('#load').fadeIn('normal');  		
		},
  		
  		success:function(data){
    		// successful request; do something with the data
      		$('#main').load('podcast.php #main');
  		},
  		
 		error:function(){
    		// failed request; give feedback to user
    		$('#main').html('<p class="error"><strong>Oops!</strong> Try that again in a few moments.</p>');
  		},
  		
  		complete:function(){
  			$('#load').delay(3000).fadeOut('normal');
    		$('#main').delay(3500).slideDown('slow');
 		}
  
	});	
});


	
	//
// This is the code that initializes and runs the Twitter feed on the DASHBOARD
//	
var Queue = function (delay, callback) {
  var q = [], 
      timer = null, 
      processed = {}, 
      empty = null, 
      ignoreRT = twitterlib.filter.format('-"RT @"'); // if you want to reuse this queue, ditch this reference
  
  function process() {
    var item = null;
    if (q.length) {
      callback(q.shift());
    } else {
      this.stop(); // don't like this, should change to prototype eventually
      setTimeout(empty, 5000);
    }
    return this;
  }
  
  return {
    push: function (item) {
      var green = [], i;
      if (!(item instanceof Array)) {
        item = [item];
      }
      
      if (timer == null && q.length == 0) {
        this.start();
      }
      
      for (i = 0; i < item.length; i++) {
        if (!processed[item[i].id] && twitterlib.filter.match(item[i], ignoreRT)) {
          processed[item[i].id] = true;
          q.push(item[i]);
        }
      }
      
      // resort the q
      q = q.sort(function (a, b) {
        return a.id > b.id;
      });
      
      return this;
    },
    start: function () {
      if (timer == null) {
        timer = setInterval(process, delay);
      }
      return this;
    },
    stop: function () {
      clearInterval(timer);
      timer = null;
      return this;
    },
    empty: function (fn) {
      empty = fn;
      return this;
    },
    q: q,
    next: process
  };
}; //.start();
 
// twitter related processing
function renderTweet(data) {
  var html = '<li><div class="tweet">';
  html += '<div class="vcard"><a href="http://twitter.com/' + data.user.screen_name + '" class="url"><img style="height: 24px; width: 24px;" alt="' + data.user.name + '" class="photo fn" height="24" src="' + data.user.profile_image_url + '" width="24" /></a></div>';  
  html += '<div class="hentry"><strong><a href="http://twitter.com/';
  html += data.user.screen_name + '" ';
  html += 'title="' + data.user.name + '">' + data.user.screen_name + '</a></strong> ';
  html += '<span class="entry-content">';
  html += twitterlib.ify.clean(data.text);
  html += '</span> <span class="meta entry-meta"><a href="http://twitter.com/' + data.user.screen_name;
  html += '/status/' + data.id + '" class="entry-date" rel="bookmark"><span class="published" title="';
  html += data.created_at + '">' + twitterlib.time.datetime(data.created_at) + '</span></a> <span>from ';
  html += data.source;
  html += '</span></span></div></div></li>';
  
  // since_id is a global tracker to ensure we only hit Twitter for *new* tweets
  since_id = data.id;
  
  return html;
}
 
function passToQueue(data) {
  if (data.length) {
    twitterQueue.push(data.reverse());
  }
}
 
var since_id = 1;
var run = function () {
  twitterlib
    .timeline('vicradio', { limit: 15, since: since_id}, passToQueue)
    .search('@vicradio', { limit: 15, since: since_id }, passToQueue);
};
 
// start a new queue and on the callback, render the tweet and animate it down
var twitterQueue = new Queue(7500, function (item) {
  // 1. stuff a new p tag, and animate it up - to force content down (with text:visibility:hidden)
  // 2. drop effect from top of page
  // 3. once effect complete, remove animated el, and show text to fake effect  
  var tweet = $(renderTweet(item));
  var tweetClone = tweet.clone().hide().css({ visibility: 'hidden' }).prependTo('#tweets').slideDown(1000);
 
  tweet.css({ top: -200, position: 'absolute' }).prependTo('#tweets').animate({
    top: 0
  }, 1000, function () {
    tweetClone.css({ visibility: 'visible' });
    $(this).remove();
  });
  
  // remove elements that aren't visible
  $('#tweets p:below(' + window.innerHeight + ')').remove();
}).empty(run);
 
 
// kick off
run();


	

