var allAnchorTags = document.getElementsByTagName("a");

var web_visible = true;
var mobile_visible = true;
var graphic_design_visible = true;
var flash_visible = true;
var processing_visible = true;
var motion_visible = true;
var photography_visible = true;
var drawings_visible = true;

var onX = 12;
var offX = -24;

var onOpacity = 1;
var offOpacity = .4;

var time = 30;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

function animateSwitch(target_state, target_class, count)
{
	var newX;
	var newOpacity;
	
	if(target_state == "off")
	{
		newX = onX - ((onX - offX) / time * count) +'px 4px';
		newOpacity = onOpacity - ((onOpacity - offOpacity) / time * count);
	}
	else if(target_state == "on")
	{
		newX = offX + ((onX - offX) / time * count) +'px 4px';
		newOpacity = offOpacity + ((onOpacity - offOpacity) / time * count);
	}
	
	var target_filter_toggle = document.getElementById('filter_toggle_'+target_class);
	var target_filter = document.getElementById('filter_'+target_class);
	
	target_filter_toggle.style.backgroundPosition = newX;
	target_filter.style.opacity = newOpacity;
	
	if(count < time)
	{
		count++;
		setTimeout(function(){animateSwitch(target_state, target_class, count)}, 1);
	}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

function toggle_category(target_class)
{
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	if (target_class == "web")
	{
		if (web_visible == true)
		{	
			web_visible = false;
			animateSwitch('off', target_class, 1);
													
			for (i = 0; i < allAnchorTags.length; i++)
			{
				if (allAnchorTags[i].className == target_class) { allAnchorTags[i].style.display = 'none'; }
			}
		}
		else if (web_visible == false)
		{	
			web_visible = true;
			animateSwitch('on', target_class, 1);
			
			for (i = 0; i < allAnchorTags.length; i++)
			{
				if (allAnchorTags[i].className == target_class) { allAnchorTags[i].style.display = 'block'; }
			}
		}
	}
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	else if (target_class == "mobile")
	{
		if (mobile_visible == true)
		{	
			mobile_visible = false;
			animateSwitch('off', target_class, 1);
													
			for (i = 0; i < allAnchorTags.length; i++)
			{
				if (allAnchorTags[i].className == target_class) { allAnchorTags[i].style.display = 'none'; }
			}
		}
		else if (mobile_visible == false)
		{	
			mobile_visible = true;
			animateSwitch('on', target_class, 1);
			
			for (i = 0; i < allAnchorTags.length; i++)
			{
				if (allAnchorTags[i].className == target_class) { allAnchorTags[i].style.display = 'block'; }
			}
		}
	}
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	else if (target_class == "graphic_design")
	{
		if (graphic_design_visible == true)
		{	
			graphic_design_visible = false;
			animateSwitch('off', target_class, 1);
													
			for (i = 0; i < allAnchorTags.length; i++)
			{
				if (allAnchorTags[i].className == target_class) { allAnchorTags[i].style.display = 'none'; }
			}
		}
		else if (graphic_design_visible == false)
		{	
			graphic_design_visible = true;
			animateSwitch('on', target_class, 1);
			
			for (i = 0; i < allAnchorTags.length; i++)
			{
				if (allAnchorTags[i].className == target_class) { allAnchorTags[i].style.display = 'block'; }
			}
		}
	}
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	else if (target_class == "flash")
	{
		if (flash_visible == true)
		{	
			flash_visible = false;
			animateSwitch('off', target_class, 1);
													
			for (i = 0; i < allAnchorTags.length; i++)
			{
				if (allAnchorTags[i].className == target_class) { allAnchorTags[i].style.display = 'none'; }
			}
		}
		else if (flash_visible == false)
		{	
			flash_visible = true;
			animateSwitch('on', target_class, 1);
			
			for (i = 0; i < allAnchorTags.length; i++)
			{
				if (allAnchorTags[i].className == target_class) { allAnchorTags[i].style.display = 'block'; }
			}
		}
	}
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	else if (target_class == "processing")
	{
		if (processing_visible == true)
		{	
			processing_visible = false;
			animateSwitch('off', target_class, 1);
													
			for (i = 0; i < allAnchorTags.length; i++)
			{
				if (allAnchorTags[i].className == target_class) { allAnchorTags[i].style.display = 'none'; }
			}
		}
		else if (processing_visible == false)
		{	
			processing_visible = true;
			animateSwitch('on', target_class, 1);
			
			for (i = 0; i < allAnchorTags.length; i++)
			{
				if (allAnchorTags[i].className == target_class) { allAnchorTags[i].style.display = 'block'; }
			}
		}
	}
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	else if (target_class == "motion")
	{
		if (motion_visible == true)
		{	
			motion_visible = false;
			animateSwitch('off', target_class, 1);
													
			for (i = 0; i < allAnchorTags.length; i++)
			{
				if (allAnchorTags[i].className == target_class) { allAnchorTags[i].style.display = 'none'; }
			}
		}
		else if (motion_visible == false)
		{	
			motion_visible = true;
			animateSwitch('on', target_class, 1);
			
			for (i = 0; i < allAnchorTags.length; i++)
			{
				if (allAnchorTags[i].className == target_class) { allAnchorTags[i].style.display = 'block'; }
			}
		}
	}
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	else if (target_class == "photography")
	{
		if (photography_visible == true)
		{	
			photography_visible = false;
			animateSwitch('off', target_class, 1);
													
			for (i = 0; i < allAnchorTags.length; i++)
			{
				if (allAnchorTags[i].className == target_class) { allAnchorTags[i].style.display = 'none'; }
			}
		}
		else if (photography_visible == false)
		{	
			photography_visible = true;
			animateSwitch('on', target_class, 1);
			
			for (i = 0; i < allAnchorTags.length; i++)
			{
				if (allAnchorTags[i].className == target_class) { allAnchorTags[i].style.display = 'block'; }
			}
		}
	}
	
	/////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	else if (target_class == "drawings")
	{
		if (drawings_visible == true)
		{	
			drawings_visible = false;
			animateSwitch('off', target_class, 1);
													
			for (i = 0; i < allAnchorTags.length; i++)
			{
				if (allAnchorTags[i].className == target_class) { allAnchorTags[i].style.display = 'none'; }
			}
		}
		else if (drawings_visible == false)
		{	
			drawings_visible = true;
			animateSwitch('on', target_class, 1);
			
			for (i = 0; i < allAnchorTags.length; i++)
			{
				if (allAnchorTags[i].className == target_class) { allAnchorTags[i].style.display = 'block'; }
			}
		}
	}
}
