$(document).ready(function() {
	$(".xxxx div").last().addClass("column-4");
	
	if ($('#gallery-playback').length > 0) {
		
		if ($('#gallery-playback').children().length == 0) {
			$firstItem = $('.galleryThumb:first a').attr('href');
			//$('.galleryThumb:first a').append('<span class="active"></span>');
			$('#gallery-playback').load($firstItem+' .imageHolder', function() {
				$('#imageAndDescription').append('<p class="pagination"></p>');
				$imageCount = $('.galleryThumb').length;
				$('.pagination').html('1<span>/'+$imageCount+'</span>');
				$currentImage = 1;
				
				
				$('ul.linear li.next a').live('click',function(e) {
					e.preventDefault();
					if ($currentImage < $imageCount) {
						$currentImage++;
					} else {
						$currentImage = 1;
					}
					$loadURL = $('.galleryThumb:nth-child('+($currentImage)+') a').attr('href');
					$('.galleryThumb a span').remove();
					$('.galleryThumb:nth-child('+($currentImage)+') a').append('<span class="active"></span>');
					$('#imageAndDescription').fadeOut();
					$('#gallery-playback').load($loadURL+' .imageHolder', function() {
						$('#imageAndDescription').append('<p class="pagination"></p>');
						$('.pagination').html($currentImage+'<span>/'+$imageCount+'</span>');
						$('#imageAndDescription').hide().fadeIn();
					});
				});
				$('ul.linear li.previous a').live('click',function(e) {
					e.preventDefault();
					if ($currentImage > 1) {
						$currentImage--;
					} else {
						$currentImage = $imageCount;
					}
					$loadURL = $('.galleryThumb:nth-child('+($currentImage)+') a').attr('href');
					$('.galleryThumb a span').remove();
					$('.galleryThumb:nth-child('+($currentImage)+') a').append('<span class="active"></span>');
					$('#imageAndDescription').fadeOut();
					$('#gallery-playback').load($loadURL+' .imageHolder', function() {
						$('#imageAndDescription').append('<p class="pagination"></p>');
						$('.pagination').html($currentImage+'<span>/'+$imageCount+'</span>');
						$('#imageAndDescription').hide().fadeIn();
					});
				});
				
			});
		}
		$('.galleryThumb a').append('<span></span>');
		$('.galleryThumb a').hover(function() {
			$(this).find('span').addClass('active');
		}, function() {
			$(this).find('span').removeClass('active');
		});
		$('.galleryThumb a').click(function(e) {
			//$('.galleryThumb a span').remove();
			//$(this).append('<span class="active"></span>');
			$currentImage = $(this).parent().index()+1;
			e.preventDefault();
			$('#imageAndDescription').fadeOut();
			$('#gallery-playback').load($(this).attr('href')+' .imageHolder', function() {
				$('#imageAndDescription').append('<p class="pagination"></p>');
				$('.pagination').html($currentImage+'<span>/'+$imageCount+'</span>');
				$('#imageAndDescription').hide().fadeIn();
			});
		});
	}
	$('.hero-panel:not(:first)').hide();
	$('.hero-panel-nav li:first').addClass('active');
	$('.hero-panel-nav a').click(function(e) {
		e.preventDefault();
		$thisLink = $(this).attr('href');
		$thisLinkArray = $thisLink.split('#');
		$('.hero-panel').hide();
		$('.hero-panel-nav li').removeClass('active');
		$(this).parent().addClass('active');
		$('#'+$thisLinkArray[1]).fadeIn();
		$('#hero-dots').attr('class',$thisLinkArray[1]);
	});
	$('.hero-panel-nav').after('<div id="hero-dots">&nbsp;</div>');
	
	if ($('.decades').length > 0) {
	    $(".decades").zAccordion({
	        //slideWidth: 500,
	        tabWidth: 80,
	        auto: false,
	        width: 700,
	        height: 335,
	        speed: 500,
	        slideClass: "decade",
	        slideOpenClass: "open",
	        slideClosedClass: "closed",
	        slidePreviousClass: "previous",
	        click: function(){            
	            var openedSlide = $('.decades .open').find('.wrapper');
	            var previousSlide = $('.decades .previous').find('.wrapper');
	            
	            $(openedSlide).find('.years').hide();
	            $(openedSlide).animate({
	                width: 530
	            }, 500);
	            $(previousSlide).find('.years').hide();
	            $(previousSlide).animate({
	                width: 70
	            }, 500);
	        },
	        open: function(){
	            $('.decades .open').find('.years').fadeIn(300);
	            setTimeout(function(){
	                $('.year-wrapper').jScrollPane();
	            }, 0);
	        },
	        close: function(){
	            
	        }
	    });
	    $('.decades').find('.open .wrapper').width(530);
	}
	
});

