$(function(){
	
	var imCount = 0;
	var curMax = 4;
	$(".cottageGallery .nyroModal").each(function(){
		$("body").append("<img src='"+$(this).attr("href")+"' alt='hmmmmmm loverly hover function ness' class='hoverImage' style='position:absolute; display:none; border:10px solid #4F4C26;' id='hi"+imCount+"' />");
		$(this).attr("jrel","hi"+imCount);
	imCount++;	
	});
	//alert(imCount);
	
	
	if(imCount>4){
		$(".cottageGallExtraNav").append("<p id='navLeft' title='Click here to scroll left'>&laquo;&laquo;</p><p id='navNo'> 1 - 4 of "+imCount+"</p><p id='navRight' title='click her to scroll right'>&raquo;&raquo;</p>");
		var nw = imCount*165;
		$("#gallInner").css("width",nw);
		activateNav();
	}
	
	
	
	function activateNav(){
		$("#navLeft").css({"height":1,"overflow":"hidden"});
		$("#navLeft").click(function(){
		//	alert(curMax+" "+imCount);
			var myID = "navLeft";
			if(curMax>4){
				$(this).css({"height":1,"overflow":"hidden"});
				//disableNav();
				var newWidth = parseInt($("#gallInner").css("marginLeft"))+165;
				$("#gallInner").animate({"marginLeft":newWidth},1200,"linear",function(){ if((curMax)!=4){showNav(myID);}});
				//activateNav()
				curMax--;
				var stI = curMax-3;
				var eI = curMax;
				
				$("#navNo").html(stI+" - "+eI+" of "+imCount);
				if(curMax<imCount){
					showNav("navRight");
				}
			}
			
			
			
		});
		
		$("#navRight").click(function(){
		//	alert($("#gallInner").css("marginLeft"));
	
		var myID = "navRight";
		var newWidth = parseInt($("#gallInner").css("marginLeft"))-165;
		
		
	//	alert(newWidth);
			//alert(curMax+" "+imCount);
			if(curMax<imCount){
				$(this).css({"height":1,"overflow":"hidden"});
				//disableNav();
				$("#gallInner").animate({"marginLeft":newWidth},1200,"linear",function(){ if((curMax)!=imCount){showNav(myID);}});
			//activateNav()
			curMax++;
				var stI = curMax-3;
				var eI = curMax;
				
				$("#navNo").html(stI+" - "+eI+" of "+imCount);
				if(curMax>4){
					showNav("navLeft");
				}
				}
				
		});
	}
	
	
	function showNav(navID){
$("#"+navID).css("height",20);
	}
	
	$(".nyroModal").mousemove(function(e){
		var ImN = "#"+$(this).attr("jrel");
		//alert(ImN);
		//var thisIm = $(".hoverImage")
		//$(this).attr("href","javascript:void;");
		
	$(ImN).css({top: (e.pageY - 200) + "px",left: (e.pageX + 15) + "px"}); 
 $(ImN).show();
		
	});
	$(".nyroModal").mouseout(function(){

		$(".hoverImage").hide();
	
	});
	
})
