var currentItem = 1;
var totalItems = 5;
$(document).ready(function(){
	$("#homeSlideshow li").css({"position":"absolute"}).hide();
	$("#homeSlideshow li:first").show();
	setImageSizes();
	$(window).resize(function(){
		setImageSizes();
	})
	
	$(".colorbox").colorbox({ height:"95%",rel:"gallery-group"});
	
	$(".image-caption-icon").hover(function(){
		$(this).parent().find(".image-caption").fadeIn(300);
	},function(){
		$(this).parent().find(".image-caption").fadeOut(300);
	})
	
	totalItems = $("#homeSlideshow li").size();
	$(".navArrow").click(function(){
		setImageSizes();
		if($(this).hasClass("arrLeft")){
			if(currentItem == 1){
				//currentItem = totalItems;
				if(currentPageNum == 1){
					if(currentGallery == "selects"){
						window.location = baseURL + "load/selects/"+totalPageCount;
					} else {
						window.location = baseURL +currentGallery+"/"+(totalPageCount-1)+"/";
					}
				} else {
					if(currentGallery == "selects"){
						window.location = baseURL + "load/selects/"+(currentPageNum-1);
					} else {
						window.location = baseURL + currentGallery+"/"+(currentPageNum-1)+"/";
					}
				}
				
			} else {
				currentItem = currentItem - 1;
			}
		} else {
			if(currentItem == totalItems){
				//currentItem = 1;
				if(currentPageNum == totalPageCount){
					if(currentGallery == "selects"){
						window.location = baseURL;
					} else {
						window.location = baseURL + currentGallery+"/1/";
					}
				} else {
					if(currentGallery == "selects"){
						window.location = baseURL + "load/selects/"+(currentPageNum+1);
					} else {
						window.location = baseURL + currentGallery+"/"+(currentPageNum+1)+"/";
					}
				}
				
			} else {
				currentItem = currentItem + 1;
			}
		}
		$("#homeSlideshow li").fadeOut(600);
		$("#homeSlideshow li:eq("+(currentItem-1)+")").fadeIn(600);
	})
	
	$("#Galleries li.sortable").hover(function(){
		$(this).find(".image-holder").fadeTo("100",.8);
	},function(){
		$(this).find(".image-holder").fadeTo("100",1);
	})

	$(document).keydown(function(event) {
		switch (event.keyCode) {
			case 37: 
				$(".arrLeft").trigger("click");
				break;
			case 39: 
				$(".arrRight").trigger("click");
				break;
		}
	});

	var theTimer = setInterval("setImageSizes();",500);
	
})

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

