// JavaScript Document

$(document).ready(function() {
$(".navigation li:first").addClass('active');
$(".navigation li").click(function(){
	//Set Variables
	var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
	var $visibleItem = $('div.showarea:visible');
	
	if ($(this).is(".active")) {  //If the list item is active/selected, then...
		return false; // Don't click through - Prevents repetitive animations on active/selected list-item
	} else { //If not active then...
		//Animate the Description
		$visibleItem.hide();
		$(imgTitle).fadeIn(500);
	}
	//Show active list-item
	$(".navigation li").removeClass('active'); //Remove class of 'active' on all list-items
	$(this).addClass('active');  //Add class of 'active' on the selected list
	return false; 

}) .hover(function(){ //Hover effects on list-item 
	$(this).addClass('hover'); //Add class "hover" on hover 
	}, function() {
	$(this).removeClass('hover'); //Remove class "hover" on hover out
});

$('.bottomNav a, .showarea img').click( function (ev) {
    //prevent browser jumping to top
    ev.preventDefault();
	
	//remove active class from leftnav
	$('.navigation li').removeClass('active')
	
    //get current  item
    var $visibleItem = $('div.showarea:visible');
	var $activeItem = $('.navigation li.active');
    //get total item count
    var total =  $('div.showarea').length;

    //get index of current visible item
    var index = $visibleItem.prevAll().length;
	
    //if we click next increment current index, else decrease index
    if ($(this).attr('href') === '#close'){
		window.close();
		return false;
	} else if ($(this).attr('href') === '#previous'){
		index--;
	} else {
		index++;
	}

    //if we are now past the beginning or end show the last or first item
    if (index === -1){
       index = total-1;
    }
    if (index === total){
       index = 0
    }

    //hide current show item
    $visibleItem.hide();
	var current = index +1;
	$('.rightCol .count').html(current+' of '+ total);
    //fade in the relevant item
    $('div.showarea:eq(' + index + ')').fadeIn(500);
	$('.navigation li:eq(' + index + ')').addClass('active');

});
var tmpTotal =  $('div.showarea').length;
$('.rightCol .count').html(1+' of '+ tmpTotal);			   
});

