function changeZIndex(){
	$('.left').css('z-index',3);
	$('.active2').css('z-index',2);
	$('.right').css('z-index',1)
	$('.left2').css('z-index',3);
	$('.active2').css('z-index',2);
	$('.right2').css('z-index',1)
};
function changeZIndex2()
{
	$('.left').css('z-index',2);
	$('.active2').css('z-index',2);
	$('.right').css('z-index',3)
	$('.left2').css('z-index',1);
	$('.right2').css('z-index',2)
};
function loadCarousel(){
	$('.carouselWrapper img').hide();
	var a=$('.active2');
	a.css({'left':'125px','width':'225px','z-index':3}).show();
	a.prev('img').css({'left':'60px','width':'175px','top':'90px','z-index':2}).addClass('left').show();
	a.prev('img').prev('img').css({'left':'20px','width':'125px','height':'125px','top':'115px','z-index':1}).addClass('left2').show();
	a.next('img').css({'left':'235px','width':'175px','top':'90px','z-index':2}).addClass('right').show();
	a.next('img').next('img').css({'left':'320px','width':'125px','height':'125px','top':'115px','z-index':1}).addClass('right2').show();
	$('.carouselWrapper img').not('.active2, .left, .right, .left2, .right2').addClass('inactive').css({'width':'0px','height':'0px','left':'130px','top':'100px'})
};
$(document).ready(function(){
	loadCarousel();
	$('#rightarrow').live('click',function(){
		$('.nodisplay').hide();
		setTimeout("changeZIndex()",200);
		$('.active2:not(:animated)').animate({'left':'235px','width':'175px','height':'175px','top':'90px','opacity':0.8},500,function(){
			$(this).removeClass('active2').addClass('right')
		});
		$('.left').animate({'left':'125px','width':'225px','height':'225px','top':'60px','opacity':1,'z-index':'4'},500,function(){
			var myClass = $('.left').attr("class");
			var myArray = myClass.split(' '); 
			$('#'+myArray[0]+'overlay').show();
			$(this).removeClass('left').addClass('active2');
			$('.carouselWrapper img:last').prependTo('.carouselWrapper')//;
		});
		$('.left2').prev('img').show().animate({'left':'20px','width':'125px','height':'125px','top':'115px','z-index':'1','opacity':0.8},500,function(){
			$(this).addClass('left2')
		});
		$('.left2:not(:animated)').animate({'left':'60px','width':'175px','height':'175px','top':'90px','z-index':'2'},500,function(){
			$(this).removeClass('left2').addClass('left')
		})
		$('.right:not(:animated)').animate({'left':'320px','width':'125px','height':'125px','top':'115px'},500,function(){
			$(this).removeClass('right').addClass('right2')
		})
		$('.right2:not(:animated)').animate({'left':'130px','width':'0px'},500,function(){
			$(this).removeClass('right2').hide()
		}); 
	});
	$('#leftarrow').live('click',function(){
		$('.nodisplay').hide();
		setTimeout("changeZIndex2()",300);
		$('.active2:not(:animated)').animate({'left':'60px','width':'175px','height':'175px','top':'90px','opacity':0.8},500,function(){
			$(this).removeClass('active2').addClass('left')
		});
		$('.right').animate({'left':'125px','width':'225px','height':'225px','top':'60px','opacity':1,'z-index':'4'},500,function(){
			var myClass = $('.right').attr("class");
			var myArray = myClass.split(' '); 
			$('#'+myArray[0]+'overlay').show();
			$(this).removeClass('right').addClass('active2');
			$('.carouselWrapper img:first').appendTo('.carouselWrapper')//;
		});
		$('.right2').next('img').show().animate({'left':'320px','width':'125px','height':'125px','top':'115px','z-index':'1','opacity':0.8},500,function(){
			$(this).addClass('right2')
		});
		$('.right2:not(:animated)').animate({'left':'235px','width':'175px','height':'175px', 'top':'90px','z-index':'2'},500,function(){
			$(this).removeClass('right2').addClass('right')
		});
		$('.left:not(:animated)').animate({'left':'20px','width':'125px','height':'125px', 'top':'115px'},500,function(){
			$(this).removeClass('left').addClass('left2')
		});
		$('.left2:not(:animated)').animate({'left':'130px','width':'0px'},500,function(){
			$(this).removeClass('left2').hide()
		});
	})
	
	function getFileName(path) {
		return path.match(/[-_\w]+[.][\w]+$/i)[0];
	}
	
	$('#marineoverlay').click(function() {
		$('.carouselWrapper img').each(function(index) {
			myHref = $(this).attr('src');
			myDesc = $(this).attr('alt');
			fileName = getFileName(myHref);
			$(this).wrap('<a title="'+myDesc+'" href="/sites/all/themes/pontoonworks/images/carousel/large/'+fileName+'" />');
		});
		
		$('.active2').parent('a').lightBox({fixedNavigation:true}).trigger('click');
		
		$('.carouselWrapper img').each(function(index) {
			$(this).unwrap();
		});
	});
	
	
	$('#commercialoverlay').click(function() {
		$('.carouselWrapper img').each(function(index) {
			myHref = $(this).attr('src');
			myDesc = $(this).attr('alt');
			fileName = getFileName(myHref);
			$(this).wrap('<a title="'+myDesc+'" href="/sites/all/themes/pontoonworks/images/carousel/large/'+fileName+'" />');
		});
		
		$('.active2').parent('a').lightBox({fixedNavigation:true}).trigger('click');
		
		$('.carouselWrapper img').each(function(index) {
			$(this).unwrap();
		});
	});
	$('#eventsoverlay').click(function() {
		$('.carouselWrapper img').each(function(index) {
			myHref = $(this).attr('src');
			myDesc = $(this).attr('alt');
			fileName = getFileName(myHref);
			$(this).wrap('<a title="'+myDesc+'" href="/sites/all/themes/pontoonworks/images/carousel/large/'+fileName+'" />');
		});
		
		$('.active2').parent('a').lightBox({fixedNavigation:true}).trigger('click');
		
		$('.carouselWrapper img').each(function(index) {
			$(this).unwrap();
		});
	});
});

/*

	$('#eventsoverlay').click(function() {
		myHref = $('.active2').attr('src');
		myDesc = $('.active2').attr('alt');
		fileName = getFileName(myHref);
		$('.active2').wrap('<a title="'+myDesc+'" href="/sites/all/themes/pontoonworks/images/carousel/large/'+fileName+'" />');
		$('.carouselWrapper a').lightBox({fixedNavigation:true}).trigger('click');
		$('.active2').unwrap();
	});
	
	*/
