
$(document).ready(function() {
	
// --------- PORTFOLIO
	// border color animation on portfolio thumbnails
	// project info slide up/down
	$('.slider li').hover(
      function () {
        $(this).children('a').css({borderColor: '#Bfbfbf'}).animate({borderColor: '#4a5666'}, 500);
        $(this).find('.description').slideDown(250, 'easeInExpo');
      }, 
      function () {
        $(this).children('a').animate({borderColor: '#Bfbfbf'}, 700);
        $(this).find('.description').slideUp(500, 'easeOutQuad');
      }
    );
	
	// ADD PORTFOLIO NAV TO PAGE
	// Got to prioritize esthetic over accessibility unfortunatly...
	// so following line now implemented via CSS to prevent "content flash"
	// $('.portfolio .slider').css("overflow-x", "hidden");
	// hide the portfolio descriptions
	$('.slider .description').hide();
	// disable access to individual portfolio page (only there for search results)
//
//	$('.portfolio a.img_link').click(function() {
//		window.open($(this).parent().find('.visit a').attr('href'));
//		return false;
//	});
//
	// get total portfolio items
	var items = $('.slider').find('li').length;
	// get # of pages
	var total_pages = Math.ceil(items/3);
	// create pagination + local nav
	var nav = '<div id="topicPath">Home / Projects / Current</div><ul id="pagination" display="width: ' + (19*total_pages) + 'px;">';
	for (var page = 0; page < total_pages; page++) {
		nav += '<li><a href="#page_0' + page + '">' + page + '</a></li>';
	}
/*	nav += '</ul><ul id="local_nav"><li class="prev"><a href="#">previous</a></li><li class="next"><a href="#">next</a></li></ul>';
*/
	$('.slider').after(nav);
/*
	// PORTFOLIO NAV FUNCTIONALITY - PAGINATION
	$('#pagination li:first a').addClass('selected');
	$('#pagination li a').click(function() {
		$('#pagination li a').removeClass('selected');
		$(this).addClass('selected');
		// get the portfolio item # to sroll to from end of pagination href*3
		var scroll_to = ($(this).attr('href')).slice(-1)*3;
		$('.slider').scrollTo('li:eq(' + scroll_to + ')', 1000, {axis:'x', easing:'easeInOutQuint'});
		// set prev/next to .off at end of pagination
		if (scroll_to == 0) { // if 1st page
			$('#local_nav .prev').addClass('off');
		} else {
			$('#local_nav .prev').removeClass('off');
		}
		// alert(scroll_to + ' and ' + items);
		if (items-scroll_to < 4) { // if 3 or less item left it's last page
			$('#local_nav .next').addClass('off');
		} else {
			$('#local_nav .next').removeClass('off');
		}
	});

	// PORTFOLIO NAV FUNCTIONALITY - PREV/NEXT
	// default state of prev is "off"
	$('#local_nav .prev').addClass('off');
	// PREV
	$('#local_nav .prev').click(function() {
		$('.slider').scrollTo('-=828', 1000, {axis:'x', easing:'easeInOutQuint'});
		// remove current .selected and add to next one if there's one
		if($('#pagination li a.selected').parent().prev().length) {
			$('#pagination li a.selected')
			.removeClass('selected')
			.parent().prev().children().addClass('selected');
		}
		// if there's no more pagination after the .selected page, can't click on next...
		if (!$('#pagination li a.selected').parent().prev().length) {
			$(this).addClass('off');
		}
		// just in case, we .next active
		$('#local_nav .next').removeClass('off');
	});
	
	// NEXT
	$('#local_nav .next').click(function() {
		$('.slider').scrollTo('+=828', 1000, {axis:'x', easing:'easeInOutQuint'});
		// remove current .selected and add to next one if there's one
		if($('#pagination li a.selected').parent().next().length) {
			$('#pagination li a.selected')
			.removeClass('selected')
			.parent().next().children().addClass('selected');
		}
		// if there's no more pagination after the .selected page, can't click on next...
		if (!$('#pagination li a.selected').parent().next().length) {
			$(this).addClass('off');
		}
		// just in case, we make .prev active
		$('#local_nav .prev').removeClass('off');
	});
*/
// --------- INFORMATION
	$('.information dt').addClass('closed');

	$('.information dt.closed a').hover(
		function () {
			if ($(this).parent().hasClass('closed')) {
				if ($(this).is(':animated')) {
					$(this).stop().animate({color: '#4a5666'}, 1);
				} else {
					$(this).css({color: '#Bfbfbf'}).animate({color: '#4a5666'}, 1);
				}
			}
		},
		function () {
			if ($(this).parent().hasClass('closed')) {
				if ($(this).is(':animated')) {
					$(this).stop().animate({color: '#Bfbfbf'}, 800);
				} else {
					$(this).css({color: '#4a5666'}).animate({color: '#Bfbfbf'}, 800);
				}
			}
		}
	);

	$('.information dt').click(function() {
		var answer = $(this).next();
		if (answer.is(':hidden')) {
			if ($('.information dd').is(':visible')) {
				// if an answer's already shown, slide it up
				$('.information dd:visible').slideUp(80, function() { answer.slideDown(350, 'easeInOutSine'); });
				$('.information dt').addClass('closed').removeClass('open');
				$(this).removeClass('closed').addClass('open');
			} else {
				answer.slideDown(350, 'easeInOutSine');
				$(this).removeClass('closed').addClass('open');
			}
		}
		// make sure the previously selected goes back to grey
		$('.information dt.closed a').css('color', '#Bfbfbf');
		return false;
	});

// sub

	$('.sub a').hover(
      function () {
        $(this).children('img').css({borderColor: '#Bfbfbf'}).animate({borderColor: '#4a5666'}, 500);
      }, 
      function () {
        $(this).children('img').animate({borderColor: '#Bfbfbf'}, 700);
      }
    );

});


