var currentSlide = 1;
var totalSlidesHome = 1;
var totalSlides = 1;
var checkActivity;
var currentPage 	= 0;
var itemsPerPage 	= 16;
$(document).ready(function(){
	$("#slideshow li:not(:first)").hide();
	$("#slideshow li").css({"position":"absolute"});
	totalSlides = $("#slideshow li").size();
	//setImageSizes();
	$(window).resize(function(){
	//	setImageSizes();
	})
	
	$("#slideshow li").append("&nbsp;").prepend("&nbsp;");

	var totalSlidesCk	= $("ul.thumbnail-list li").size();
	var totalPages		= (Math.ceil(totalSlidesCk/itemsPerPage))-1;
	
	$(".thumbnail-list").wrapInner("<div class=\"slideshow-hideable\" />");
	$(".slideshow-hideable").wrapInner("<div class=\"slideshow-inner\" />");
	$(".slideshow-inner").append("<div class=\"clear\"></div>");
	
	$("#slideshow .navArrow").click(function(){
		if($(this).hasClass("arrLeft")){
			currentSlide=currentSlide-1;
		} else {
			currentSlide=currentSlide+1;
		}
		if(currentSlide < 1){ currentSlide = totalSlides; }
		if(currentSlide > totalSlides){ currentSlide = 1; }
		showSlide(currentSlide);
		return false;
	})
	
	if(totalPages>0){
		$(".thumbnail-list").prepend("<div class=\"navArrow arrowLeft\"></div><div class=\"navArrow arrowRight\"></div>")
		$("#thumbnails .navArrow").click(function(){
			if($(this).hasClass("arrowLeft")){
				currentPage = currentPage-1;
				if(currentPage < 0){ currentPage = totalPages; }
			} else {
				currentPage = currentPage+1;
				if(currentPage > totalPages){ currentPage = 0; }
			}
			$(".slideshow-inner").animate({"margin-left":(currentPage*960)*-1 + "px"},300);
		})
	}


	$(".single-video img").click(function(){
		var vimeoID = $(this).attr("rel");
		//var finalVideo = "<iframe src=\"http://player.vimeo.com/video/"+vimeoID+"?byline=0&amp;portrait=0\" width=\"700\" height=\"430\" frameborder=\"0\" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>";
		var finalVideo = "<iframe src=\"http://player.vimeo.com/video/"+vimeoID+"?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=1\" width=\"700\" height=\"430\" frameborder=\"0\" webkitAllowFullScreen allowFullScreen></iframe>";
		$("#video-background").fadeIn(500,function(){
			$("#video-overlay .videoInner").html(finalVideo);
			$("#video-overlay").show();
		})
		return false;
	})
	$(".videoClose,#video-background").click(function(){
		$("#video-overlay .videoInner").html("");
		$("#video-overlay").hide();
		$("#video-background").fadeOut(400);
	})


	
	$(document).keydown(function(event) {
		switch (event.keyCode) {
			case 37: 
				$(".arrLeft").trigger("click");
				break;
			case 39: 
				$(".arrRight").trigger("click");
				break;
		}
	});
	
	$(".thumbnail-list li:not(:first)").fadeTo(50,.5);
	$("#thumb1").addClass("active");
	
	$("#subnav-fashion,#subnav-projects,#subnav-personal").show();
	$("#subnav-fashion,#subnav-projects,#subnav-personal").animate({"left":"0px","opacity":"0"},0);
	$("#nav-portfolio").hover(function(){
		$(this).addClass("hoveredSub");
		//$("#subnavigation").show();
		$("#subnav-fashion").animate({"left":"20px","opacity":"1"},500);
		$("#subnav-projects").animate({"left":"90px","opacity":"1"},500);
		$("#subnav-personal").animate({"left":"164px","opacity":"1"},500);
	}, function(){
		$(this).removeClass("hoveredSub");
		//$("#subnavigation").hide();
		$("#subnav-fashion,#subnav-projects,#subnav-personal").animate({"left":"0px","opacity":"0"},500);
	})
	
	$(".navArrow").hover(function(){
		$(this).addClass("hoveredArrow");
	},function(){
		$(this).removeClass("hoveredArrow");
	})
	
	$("#thumbnails li").hover(function(){
		if(!$(this).hasClass("active")){
			$(this).fadeTo(300,1);
		}
	},function(){
		if(!$(this).hasClass("active")){
			$(this).fadeTo(300,0.5);
		}
	})
	
	$("#thumbnails li").click(function(){
		showSlide($(this).attr("rel"));
	})
})

function showSlide(whatSlide){
	$("#slideshow li").fadeOut(500);
	$("#slide"+whatSlide).fadeIn(500);
	$(".thumbnail-list li:not('#thumb"+whatSlide+"')").fadeTo(300,.5);
	$("#thumbnails .active").removeClass("active");
	$("#thumb"+whatSlide).fadeTo(100,1).addClass("active");
	currentSlide = parseInt(whatSlide);

	var totalSlidesCk	= $("ul.thumbnail-list li").size();
	var totalPages		= (Math.ceil(totalSlidesCk/itemsPerPage))-1;
	currentPage 		= (Math.ceil(whatSlide/itemsPerPage))-1;
	$(".slideshow-inner").animate({"margin-left":(currentPage*960)*-1 + "px"},300);

}

function setImageSizes(){
	var windowWidth = $(window).width();
	var windowHeight = $(window).height();
	$("#slideshow").css({"height":windowHeight-235,"width":"auto"});
	$("#slideshow li img").each(function(){
		$(this).css({"height":windowHeight-245,"width":"auto"});
		if($(this).width() > (windowWidth-100)){
			$(this).css({"width":windowWidth-100,"height":"auto"});
		}
	})
	
	
	
	
}


function nextSlide(){
	currentSlide = currentSlide+1;
	if(currentSlide > totalSlides) { currentSlide = 1; }
	$("#slideshow li").fadeOut(500);
	$("#slide"+currentSlide).fadeIn(500);
	checkActivity = setTimeout("nextSlide();",4000);
}














/*
var currentSlide = 1;
var totalSlides = 1;
var checkActivity;

$(document).ready(function(){
	$("#slideshow li:not(:first)").hide();
	$("#navigation").prepend("<div id=\"navinner\"></div><div id=\"navshadow\"></div>");
	
	$(window).scroll(function(){
		var howScroll = $(window).scrollTop();
		if(howScroll > 20){
			$("#navshadow").fadeIn(100);
			$("#navigation .hasChildren ul").addClass("withBackground");
		} else {
			$("#navshadow").fadeOut(100,function(){
				$("#navigation .hasChildren ul").removeClass("withBackground");
			});
		}
	})
	
	$(".hasChildren").hover(function(){
		$(this).find("ul").fadeIn(100);
		$(this).find(".noClick").addClass("hovered");
	},function(){
		$(this).find("ul").fadeOut(100);
		$(this).find(".noClick").removeClass("hovered");
	})
	$("a.inactive, a.noClick").click(function(){ return false; })
	
	totalSlides = $("#slideshow li").size();
	checkActivity = setTimeout("nextSlide();",4000);
	
	$(".chips-credit").hover(function(){
		$(this).html("CHIPS");
	},function(){
		$(this).html("Credits");
	})
})

function nextSlide(){
	currentSlide = currentSlide+1;
	if(currentSlide > totalSlides) { currentSlide = 1; }
	$("#slideshow li").fadeOut(500);
	$("#slide"+currentSlide).fadeIn(500);
	checkActivity = setTimeout("nextSlide();",4000);
}

function setUpMap() {
	var info_window = new google.maps.InfoWindow({content: ''});
	var myLatlng = new google.maps.LatLng(40.687684,-73.989957);
	var myOptions = {
		zoom: 16,
		mapTypeControl: false,
		center: myLatlng,
		mapTypeId: google.maps.MapTypeId.TERRAIN
	}
	var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

	var marker = new google.maps.Marker({
	    position: myLatlng, 
	    map: map,
	    title:"Bien Cuit - The Smith Street Bakery"
	});
	marker.setIcon("/site/art/biencuit_marker.png");
	google.maps.event.addListener(marker, 'click', function() {
		//window.location = "http://maps.google.com/maps?q=120+Smith+Street+Brooklyn+NY+11211&hl=en&sll=40.761689,-73.920833&sspn=0.011669,0.015557&z=16";
		info_window.content = '<div class="map-popup">Directions to <a href="http://maps.google.com/maps?q=120+Smith+Street+Brooklyn+NY+11211&hl=en&sll=40.761689,-73.920833&sspn=0.011669,0.015557&z=16" target="_blank">Bien Cuit</a> </div>';
		info_window.open(map, marker);
	})
}


$(document).nap(
	function() { 
		clearTimeout(checkActivity);
	},
	function() { 
		nextSlide();
	}
);
*/

