//function for swapping thumbnail images
function changeThumb(thumbsrc){
	$("#largeThumb").attr("src",thumbsrc);
	//need to update the links on the arrows
	updateArrows();
}


//function for updating the arrow navigation
function updateArrows(){
	//step 1. get the current source for the large image
	var largeThumb = $("#largeThumb").attr("src");
	
	//step 2. traverse the array to find which node this is
	for(i=0;i<thumbnails.length;i++){
		if(thumbnails[i] == largeThumb){ var currentNode = i;}
	}
	
	//step 3. determine the previous and next nodes
	if(currentNode == 0){
		var prevNode = thumbnails.length -1;
		if(thumbnails.length > 1){
			var nextNode = 1;
		}else{
			var nextNode = 0;
		}
	}else if(currentNode == thumbnails.length -1){
		var nextNode = 0;
		var prevNode = currentNode -1;
	}else{
		var nextNode = currentNode +1;
		var prevNode = currentNode -1;
	}
	
	//step 4. update the arrow links
	$("#prevWork").attr("href",'javascript:changeThumb("'+thumbnails[prevNode]+'");');
	$("#nextWork").attr("href",'javascript:changeThumb("'+thumbnails[nextNode]+'");');
}


function moveThumb(dir,limit){
	
	if(dir == 'prev'){
		if(sansPX($('#largeThumbInner').css('left')) < 0){
			$('#largeThumbInner').animate({left: '+=600px'},800);
		}else{
			$('#largeThumbInner').animate({left: ((limit -1) * -600)+'px'},800);
		}
	}else{
		if(sansPX($('#largeThumbInner').css('left')) > ((limit -1) * -600)){
			$('#largeThumbInner').animate({left: '-=600px'},800);
		}else{
			$('#largeThumbInner').animate({left: '0'},800);
		}
	}
}

function setAmount(){
	var nm = $("#nam").val();
	var co = $("#com").val();
	var pr = $("#pro").val();
	var cl = nm+' - '+co+' - '+pr;
	
	$("#os0").val(cl);
}

//function to swap the B&W image for a color version
function swapBWimages(){
	$(".project_thumb").hover(
		function () {
		var imgid = $(this).attr('id');
		$("#"+imgid).fadeTo('fast',0.01);
		},
		function () {
		var imgid = $(this).attr('id');
		$("#"+imgid).fadeTo('fast',1.00);
		}
	);
}

//function to filter the work thumbnails
function filterCats(catname){
	$.ajax({
	   type: "POST",
	   url: "ajax.work-filter.php",
	   data: "category="+catname,
	   success: function(msg){
	   	//fade out current group of thumbnails	
	   	$("#work_thumbnails .work_thumbnail").each(function(){ $(this).fadeOut(); });
	   	   	
	   	$("#work_thumbnails").html(msg);
	   	swapBWimages();
	   	//$("#work_thumbnails .work_thumbnail").each(function(){ $(this).hide(); });
			$("#work_thumbnails .work_thumbnail").each(function(){ $(this).hide().fadeIn(); });
	   	$("#work_nav a").each(function(){ $(this).removeClass('active'); });
	   	$("#work_nav_"+catname).addClass('active');
	}
	 });
}

/****GET THE MEASURE SANS PX*******************************************/
		
		function sansPX(str){
			var tempMeasure = str;
			if(tempMeasure == ''){return 0;}
			else {
				if(tempMeasure.substring(tempMeasure.length-2, tempMeasure.length) == 'px'){
					var asInt = tempMeasure.substring(0, tempMeasure.length-2);
					return asInt;
				}else{
					return tempMeasure;
				}
			}
			
		}

//function for jump menus
function jumpMenu(url){
	if(url != ''){window.location = url;}
}

