// JavaScript Document

$(document).ready(function(){
$("#ko-gallery-inner img").hide();
$("#ko-gallery-inner img:first-child").show();


imgCount = $("#ko-gallery-inner img").size();

//if (imgCount < 2) {
//	$("#count").hide();
//}

$("#ko-gallery-inner img").each(function (i) {
    i = i+1;
    $(this).addClass("item" + i);
	
	
	if (imgCount > 1) {
		$("#count").append("<li class='item" + i +"'><a>" + i + "</a></li>");
	}
	
	
});

$("#ko-gallery ul#count li:first-child a").addClass("current-image");

var initialCaption = $("#ko-gallery-inner img:first-child").attr("alt");
var initialSubcaption = $("#ko-gallery-inner img:first-child").attr("title");

$("#ko-gallery .caption").html(initialCaption);
$("#ko-gallery .subcaption").html(initialSubcaption);

$("#ko-gallery #count li a").click(function(){

	var clicked = $(this).parent("li").attr("class");
	var clickedFull = "#ko-gallery-inner img." + clicked;
	var clickedCaption = $(clickedFull).attr("alt");
	var clickedSubcaption = $(clickedFull).attr("title");
	
	$("#ko-gallery-inner img").fadeOut();
	$(clickedFull).fadeIn();
	$("#ko-gallery ul#count li a").removeClass("current-image");
	$(this).addClass("current-image");
	$("#ko-gallery .caption").html(clickedCaption);
	$("#ko-gallery .subcaption").html(clickedSubcaption);
 
});

var glanceHeight = $("#ko-gallery .project-glance").height();

$("#ko-gallery .project-glance").css("height","0");

$("#ko-gallery .glance-button a").toggle(
      function () {
       $("#ko-gallery .project-glance").animate({ 
			height: glanceHeight + "px"
		}, 250 );
		$(this).addClass("open");
      },
      function () {
        $("#ko-gallery .project-glance").animate({ 
			height: 0
		}, 250 );
		$("#ko-gallery .glance-button a").removeClass("open");
      }
    );




});

