
$(document).ready(function() {
	
	// Hide all the content panels and then show the first one
	$('.left-content').hide();
	$('#panel1').show();
	$('#services').children('li:first-child').children('a').addClass('current');
	
	// Show the panelbased on the index of the li that's been rolled over
	$('#services').children('li').hover(function(){
		if( $(this).children('a').attr('class') != 'current' ){										 
			$('#services').children('li').children('a').removeClass('current');
			$(this).children('a').addClass('current');
			var i = $(this).index() + 1;
			var panel = '#panel' + i;
			$('.left-content').fadeOut();
			$(panel).fadeIn();
		}
	}, function(){});
						   
	// Home page animation
	var rotation = function (){
	   	$("#img").rotate({
			duration:4000,
			angle:0, 
		  	animateTo:360, 
		  	callback: function () { 
				$('.animation').fadeOut(2000); 
				$('.logo').fadeOut(2000); 
				$.cookie('animation_played', 'yes');
			},
		  	easing: function (x,t,b,c,d){        // t: current time, b: begInnIng value, c: change In value, d: duration
				return c*(t/d)+b;
		  	}
	   });
	}
	if($.cookie('animation_played') == 'yes'){
		$('.animation').hide(); 
		$('.logo').hide();
	}else{
		rotation();
	}

});

function slideSwitch() {
	var $active = $('#slideshow img.active');

	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 img:first');

	// uncomment the 3 lines below to pull the images in random order
	
	// var $sibs  = $active.siblings();
	// var rndNum = Math.floor(Math.random() * $sibs.length );
	// var $next  = $( $sibs[ rndNum ] );


	$active.addClass('last-active');

	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() {
			$active.removeClass('active last-active');
		});
}
setInterval( "slideSwitch()", 4000 );

