jQuery(document).ready( function() {
	// open eternal links in new window
  jQuery('.source a, .external').click( function(e) {
		e.preventDefault();
		e.stopPropagation();
		window.open(this.href, '_blank');
	});
  
  if (jQuery('#carousel').length > 0) {
    slideshow_init();
  }

});

/**
 * SLIDESHOW FUNCTIONALITY
 */
var slideWidth = 810;         // default, can be smaller if viewport < 1200px
var slidePointer = 0;         // currently focussed slide
var intSlides = 0;            // number of slides in show (updated in initialize)
var slideDirection = 1;	   		// 1 for right, -1 for left
var slideshowTimer;			      // timer
var slideshowRunning = false;	// is our slideshow running?
var slidingNow = false;       // are we sliding right now?
var slideshowPause = 15000;   // time to show each slide

// Our initialisation function
function slideshow_init( action, booOnHomepage ) {

	// how many slides have we got?
	intSlides = jQuery('#carousel li').length -1 ;

  // only run if > 1 item
  if (intSlides > 0) {
    slideshow_run()
  }
}

// run the homepage slideshow
function slideshow_run() {
	// set our timer to loop over this until told otherwise
	slideshowTimer = setTimeout( function() {
		slideshow_move();
		slideshow_run();
	}, slideshowPause );
}

// move the slideshow
function slideshow_move() {

	// we're moving
	slidingNow = true;

	// fadeOut the current slide
	jQuery('#carousel li:nth-child('+ slidePointer + ')').fadeOut();

	// update the pointer
	slidePointer = slidePointer + slideDirection;

	// check to see we haven't run off the end
	if (slidePointer > intSlides) slidePointer = 0;

	// fadeIn the new slide
	jQuery('#carousel li:nth-child('+ slidePointer + ')').fadeIn( function() {
		slidingNow = false;
	});

}

/*
<object width="810" height="60"><param name="movie" value="http://www.youtube.com/v/36Q9jhanJ7U?version=3&amp;hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/36Q9jhanJ7U?version=3&amp;hl=en_US" type="application/x-shockwave-flash" width="810" height="60" allowscriptaccess="always" allowfullscreen="true"></embed></object>
 */
