
/*
-----------------   Fire Functions as soon as DOM is ready -----------------------------------*/	

	$(document).ready(function() {

		$("#thumbnails").scrollable({size: 1, clickable: false}).find("img").each(function(index) {
	
			// thumbnail images trigger overlay
			$(this).overlay({
				target: '#box',
				expose: {maskId: 'mask'},
				start: {top: 0},
				finish: {top: 0},
				onLoad: function() {
					images.seekTo(index, 0);
				},
				onBeforeClose: function() { 
					// When the close button is selected get the index of the existing overlay image via the images API, 
					// then reference the underlying image, and use the API call seek, to update the underlying images position
					var overlayIndex = images.getIndex();
					var underlyingImage = $("#thumbnails").scrollable();
					underlyingImage.seekTo(overlayIndex);
				} 		
			});
		});
		
		var images = $("#images").scrollable({size: 1, api:true});// scrollable inside the box. Its API is assigned to the "images" variable
		var api = $("#thumbnails").scrollable();// Set up api
		
		// Get the id of the thumbnail, and use this value within the API to seek the new image position
		$('#thumbs').click(function(e) {		
			var $target = $(e.target); 
			if($target.is('img') ) {
				var newImage = $target.attr('id');
				var amountToMove = parseInt(newImage)
					api.seekTo(amountToMove);
			}
			return false;
		})
		
	if ($('#contactform').length) {
			$("#contactform").RSV({
			//onCompleteHandler: myOnComplete,
			//errorFieldClass: "errorField",
			rules: [
			"required,name,Please enter your first name.",
			"required,email,Please enter your email address.",
			"valid_email,email,Please enter a valid email address.",
			"required,message,Please enter your first name."
			]
			});
	}
		
	});
	

	//function closeOverlayAction() {
		///alert('hi')
	//}

/*
	function moveThumbs() {

		var thumbSize = 96;	
		var carouselWindowWidth = $('#carousel').outerWidth();

		$('#nextbutton').click(function(e) {
			e.preventDefault();
			var thumbposition = $('#thumblist').position();
			var currentPos = thumbposition.left;
			var nextPos = parseInt(currentPos) - thumbSize;
			//console.log(currentPos+ ' ' +nextPos)
			var nextPos10 = nextPos// - 10;
			if (Math.abs(nextPos10) < (carouselWindowWidth + thumbSize)) {
				$('#thumblist').animate({left: nextPos10 + "px"})	
			}
		})

		$('#prevbutton').click(function(e) {
			e.preventDefault();
			var thumbposition = $('#thumblist').position();
			var currentPos = thumbposition.left;
			var nextPos = parseInt(currentPos) + thumbSize;
			//console.log(currentPos + ' ' + nextPos)
			var nextPos10 = nextPos// - 10;
			if (nextPos10 < thumbSize) {
				$('#thumblist').animate({left: nextPos10 + "px"})	
			}
		})
}

function showHide() {
			var mainImage = $('#mainimage');
			$('#thumbs li a, #thumblist li a').click(function(e) {
			e.preventDefault();
			$(mainImage).attr("src", this.href); 
			
			var blockName = $(this).prev("span").attr("class");
			$('.project-section').css({visibility:"hidden", position:"absolute", left:"-10000px", top:"-10000px"})	
			$('#' + blockName).css({visibility:"visible", position:"relative", left:"-0px", top:"-0px"})

		})

}*/





