$(document).ready(function(){
	$("#subNav").draggable({containment:'#header'});
	
	$(".fancy").fancybox({
				'zoomSpeedIn':	0, 
				'zoomSpeedOut':	0, 
				'overlayShow':	true
			});
	
	$("#embed-expo-folder").each(function(){
		listCount = $("#embed-expo-folder ul li").length;
		newWidth = (itemwidth*listCount) + (marginwidth*listCount);
		$("#embed-expo-folder ul").css("width",newWidth+"px");
		
		$("#embed-expo-folder .prev").css("display","none");
		$("#embed-expo-folder .next").css("display","none");
		
		
		$(this).find(".image_holder img").each(function(){
			var w = $(this).width();
			var h = $(this).height();
			var res = false;
			if(h < itemheight){
				w = Math.round((w/h)*itemheight)
				h = itemheight;
				res = true;
			}
			if(w < (itemwidth-6)){
				h = Math.floor((h/w)*itemwidth);
				w = itemwidth;
				res = true;
			}
			if(res == false){
				if(((h-itemheight) > (w-itemwidth)) && (w-itemwidth)> 0){
					h = Math.floor((h/w)*itemwidth);
					w = itemwidth;
				}
				if(((h-itemheight) < (w-itemwidth)) && (h-itemheight)> 0){
					w = Math.round((w/h)*itemheight)
					h = itemheight;
					
				}
			}
			$(this).attr("width",w);
			$(this).attr("height",h);
			
		});
		$("#embed-expo-folder li").hover(function(){
				
				$(this).find("img").each(function(){
					$(this).animate({'opacity' : 0.4}, 400);
				});
				$(this).find(".expo-title").each(function(){
					$(this).animate({'opacity' : 0.7}, 400);
				});
			
			},
			function(){
				$(this).find("img").each(function(){
					$(this).animate({'opacity' : 1}, 400);
				});
				$(this).find(".expo-title").each(function(){
					$(this).animate({'opacity' : 0}, 400);
				});
			}
		);
		$("#embed-expo-folder").hover(function(){
			if(slideCounter < listCount-3){
				$("#embed-expo-folder .next").css("display","block");
			}
			if(slideCounter > 0){
				$("#embed-expo-folder .prev").css("display","block");
			}
			
		},
		function(){
			$("#embed-expo-folder .prev").css("display","none");
			$("#embed-expo-folder .next").css("display","none");
		});
		
		$("#embed-expo-folder .next").click(function(){
			if(slideCounter < listCount-1){
				sliderUp();
			}
			if(slideCounter < listCount-3){
				$("#embed-expo-folder .next").css("display","block");
			}
			if(slideCounter > 0){
				$("#embed-expo-folder .prev").css("display","block");
			}
		});
		$("#embed-expo-folder .prev").click(function(){
			if(slideCounter > 0){
				sliderDown();
			}
			if(slideCounter < listCount-3){
				$("#embed-expo-folder .next").css("display","block");
			}
			if(slideCounter > 0){
				$("#embed-expo-folder .prev").css("display","block");
			}
		});
	});		
});

var slideCounter = 0;
var listCount = 0;
var width = 269;
var itemwidth = 225;
var itemheight = 220;
var marginwidth = 44;
function sliderUp(){
	slideCounter++;
	var newMargin = width * slideCounter;
	$("#embed-expo-folder ul").animate({marginLeft:"-"+newMargin+"px"},500);
}
function sliderDown(){
	slideCounter--;
	var newMargin = width * slideCounter;
	$("#embed-expo-folder ul").animate({marginLeft:"-"+newMargin+"px"},500);
}