$(document).ready(function() {		

	liftoffTime = new Date(2010,9,1);	
	liftoffTime.setHours(23);
    $("#countdown").countdown({until: liftoffTime, layout: '<li class="days">{dn}</li> <li class="hours">{hnn}</li> <li class="minutes">{mnn}</li> <li class="seconds">{snn}</li>'});
    	
	//Speed of the slideshow
	var speed = 11000;
	
	//You have to specify width and height in #slider CSS properties
	//After that, the following script will set the width and height accordingly
	$('#mask-gallery, #gallery li').width($('#slider').width());	
	$('#gallery').width($('#slider').width() * $('#gallery li').length);
	$('#mask-gallery, #gallery li, #mask-excerpt, #excerpt li').height($('#slider').height());
	
	//Assign a timer, so it will run periodically
	var run = setInterval('newsscoller(0)', speed);	
	
	$('#gallery li:first, #excerpt li:first').addClass('selected');
	
    $('.txtDesc').hide();
    $('#d_2010').show();
    
    $(function() {
	    $(".displayBox").jCarouselLite({
	        btnNext: ".fwdbutton",
	        btnPrev: ".backbutton",
	        visible: 1,
		    afterEnd: function(a) {
			    $('.txtDesc').hide();
			    $('#'+a[0].firstChild.className).fadeIn();			
//			        console.log(a);
		    }
	    });
	    
		$('#newsitems').innerfade({
			speed: 'slow',
			timeout: 6200,
			type: 'sequence',
			containerheight: '115px'
		});
			
		$('#photoslider').jScrollPane({dragMinHeight:25, dragMaxHeight:25});


	});
	
    $('#attone').click(function () { 
      $('#page1').hide();
      $('#nextbutton2008').hide();      
      $('#newrecord').hide();   
      $('#page2').fadeIn();      
      $('#nextbutton2008-2').fadeIn();      
    });
    
    
    $('#atttwo').click(function () { 
      $('#page2').hide();
      $('#nextbutton2008-2').hide();      
      $('#page1').fadeIn();      
      $('#nextbutton2008').fadeIn();
      $('#newrecord').fadeIn();         
    });
    
    
    $('#attthree').click(function () { 
      $('#page2').hide();
      $('#nextbutton2008-2').hide();      
      $('#page3').fadeIn();      
      $('#nextbutton2008-3').fadeIn();      
    });
    

    $('#attfour').click(function () { 
      $('#page3').hide();
      $('#nextbutton2008-3').hide();      
      $('#page2').fadeIn();      
      $('#nextbutton2008-2').fadeIn();      
    });


    $('#attfive').click(function () { 
      $('#page3').hide();
      $('#nextbutton2008-3').hide();      
      $('#page4').fadeIn();      
      $('#nextbutton2008-4').fadeIn();    
    });
    

    $('#attsix').click(function () { 
      $('#page4').hide();
      $('#nextbutton2008-4').hide();      
      $('#newrecord').hide();      
      $('#page3').fadeIn();      
      $('#nextbutton2008-3').fadeIn();     
    });

});

function newsscoller(prev) {

	//Get the current selected item (with selected class), if none was found, get the first item
	var current_image = $('#gallery li.selected').length ? $('#gallery li.selected') : $('#gallery li:first');
	var current_excerpt = $('#excerpt li.selected').length ? $('#excerpt li.selected') : $('#excerpt li:first');

	//if prev is set to 1 (previous item)
	if (prev) {
		
		//Get previous sibling
		var next_image = (current_image.prev().length) ? current_image.prev() : $('#gallery li:last');
		var next_excerpt = (current_excerpt.prev().length) ? current_excerpt.prev() : $('#excerpt li:last');
	
	//if prev is set to 0 (next item)
	} else {
		
		//Get next sibling
		var next_image = (current_image.next().length) ? current_image.next() : $('#gallery li:first');
		var next_excerpt = (current_excerpt.next().length) ? current_excerpt.next() : $('#excerpt li:first');
	}

	//clear the selected class
	$('#excerpt li, #gallery li').removeClass('selected');
	
	//reassign the selected class to current items
	next_image.addClass('selected');
	next_excerpt.addClass('selected');

	//Scroll the items
	$('#mask-gallery').scrollTo(next_image, 800);		
	$('#mask-excerpt').scrollTo(next_excerpt, 800);					
	
}

