$(document).ready(function(){	
	$('.container').each(function(e){
		if(e == 0){
			$(this).addClass('current');
		}
		 $(this).attr('id', 'handle' + e);
	})
	
	$('.tabs li').each(function(e){
		if(e == 0){
			$(this).addClass('current'); //adds class current to 1st li
		}
		$(this).wrapInner('<a class="title"></a>'); //wraps list items in anchor tag			
		$(this).append('<a><img /></a>'); //creates img tag		
		$(this).children('a').attr('href', '#handle' + e);//adds href to the anchors	
		y = $('#handle' + e + ' img').attr('src'); //grabs src from large pix
		$(this).find('img').attr('src', y); //appends src to small pix
		t = $(this).children('a').text(); 
		$('#handle' + e).append('<h2>' + t + '</h2>'); //adds h2 and text to big images	
		
	})
	
	$('.tabs li a').click(function(){
		c = $(this).attr('href'); 		
		if($(c).hasClass('current')){
			return false;
		}else{
			showImage($(c), 20);
			$('.tabs li').removeClass('current');
			$(this).parent().addClass('current');
			return false;
		}			
	})
	
	runRotateImages();
	
	$("#image-rotator").hover(
		function(){					
			clearTimeout(xx);
		}, 
		function(){					
			runRotateImages();
		}
	)
	  
	
	
})

function showImage(img, duration){		 

	$('.container').removeClass('current').css({
			"opacity" : 0.0, 
			"zIndex" : 2
			});
	img.animate({opacity:1.0}, duration, function(){		
		$(this).addClass('current').css({zIndex:1});
	});	 
	
}
function rotateImages(){
	
	var curPhoto = $("div.current");
	var nxtPhoto = curPhoto.next();		
	var curTab = $(".tabs li.current");
	var nxtTab = curTab.next();				
	
	if (nxtPhoto.length == 0) {
		nxtPhoto = $('#image-rotator div:first');	
		nxtTab = $('.tabs li:first-child');			
	}					
	 
	curTab.removeClass('current');
	nxtTab.addClass('current');
	showImage(nxtPhoto, 300);

}
function runRotateImages(){

	xx = setInterval("rotateImages()", 4000);
	
}