var slide_show_speed = 1500;
var slide_duration = 6000;
var slide_interval;
var slide_timeout;

$(document).ready(function() {
													 
	/* slideshow */
	var paused = '<div class="paused">Paused</div>';
	var url = '<a href="#" class="border_img"></a>';
	
	var $first = $('#slideshow .slides li:first');
	var $first_text = $('#slideshow .texts li:first');
	$first.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, slide_show_speed);
	$first_text.addClass('active');
	$("#slideshow").append(paused);
	$("#slideshow").append(url);
	
	url = $first_text.find("a").attr("href");
	$("#slideshow .border_img").attr("href", url);
});

$(window).load(function() {
	slide_interval = setInterval( "slideSwitch()", slide_duration );
	
	$("#slideshow").hover(function() {
			clearInterval(slide_interval);
			clearTimeout(slide_timeout);
			$("#slideshow .paused").fadeIn();
		},
		function() {
			$("#slideshow .paused").fadeOut();
			slide_interval = setInterval( "slideSwitch()", slide_duration );
			slide_timeout = setTimeout( "slideSwitch()", slide_show_speed );
		});
});

function slideSwitch() {
	var $active = $('#slideshow .slides .active');
	var $active_text = $('#slideshow .texts .active');
	
	var $not_active = $('#slideshow .slides li').not(".active");
	$not_active.css({opacity: 0.0});

	// if ( $active.length == 0 ) $active = $('#slideshow img:last');

	// use this to pull the images in the order they appear in the markup
	var $next =  $active.next().length ? $active.next() : $('#slideshow .slides li:first');
	var $next_text =  $active_text.next().length ? $active_text.next() : $('#slideshow .texts li:first');

	$active.addClass('last-active');
	
	var url = $next_text.find("a").attr("href");
		
	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, slide_show_speed, function() {
			$active.css({opacity: 0.0});
		});
	$next_text.addClass('active');
	
	$("#slideshow .border_img").attr("href", url);
	
	$active.removeClass('active last-active');
	$active_text.removeClass('active');
};

// Google Analytics
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-18565021-1']);
_gaq.push(['_trackPageview']);

(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
	
