
	/* Modified by Alex Spooner, 2008-08-20 */

  // ajaxLoad 2.0
	function ajaxLoad(func,method,url,vars)
  {
    try
    {
      xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
      new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e)
    {
      alert("Your browser doesn't support ajax. Use newer FireFox or IE!");
    }
    xmlhttp.onreadystatechange = function ajaxTrigger()
    {
      if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
      {
        eval(func)(xmlhttp.responseText);
      }
    }
    if (vars.length>0)
    {
      vars = vars + '&ajaxtimestamp=' + new Date();
    }
    else
    {
      vars = 'ajaxtimestamp=' + new Date();
    }
    if (method == "GET")
    {
      xmlhttp.open("GET", encodeURI(url + '?' + vars), true);
      xmlhttp.send(null);
    }
    if (method == "POST")
    {
      xmlhttp.open("POST", encodeURI(url), true);
			xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');      
      xmlhttp.send(encodeURI(vars));
    }
  }

	// fadeIO 1.0.1
	function fadeIO(type,id,opc,func,attr1,attr2)
	{
		div = document.getElementById(id);
		if (type=='out' && opc>0)
		{
		  div.style.opacity = opc * .01;
		  div.style.filter = 'alpha(opacity=' + opc + ')';
			opc = opc - 10;
			setTimeout( function() { fadeIO(type,id,opc,func,attr1,attr2) }, 10);
		}
		else if (type=='out')
		{
			eval(func)(attr1,attr2);
			setTimeout( function() { fadeIO('in',id,opc) }, 10);
		}
		else if (type=='in' && opc<100)
		{
		  div.style.opacity = opc * .01;
		  div.style.filter = 'alpha(opacity=' + opc + ')';
			opc = opc + 10;
			setTimeout( function() { fadeIO(type,id,opc) }, 10);
		}
		else if (type=='in')
		{
		  div.style.opacity = 1;
		  div.style.filter = 'alpha(opacity=100)';
		}
	}

	// loadStage 3.0
	function loadStage(id,loaded)
	{
		if (!loaded)
		{
			fadeIO('out','ajax_content',100,'loadStage',id,true);
		}
		else
		{
			str = new String(document.location);
			if (!id)
			{
				arr = str.split('#');
				if (arr[1]>'') id = arr[1];
				else id = '';
			}
			if (str.search('/tags/')!=-1) typ = 'tag';
			else typ = 'cat';
			ajaxLoad('showStage','GET','/projects.php','id='+id+'&type='+typ);
			document.body.style.cursor = 'progress';
			document.getElementById('stage').innerHTML = "<div id=\"ajax_content\">&nbsp;</div>";
			document.getElementById('content').className = "loading";
		}
	}

	// showStage 3.0
	function showStage(res,loaded)
	{
		//alert(res);
		if (!loaded)
		{
			fadeIO('out','ajax_content',100,'showStage',res,true);
		}
		else
		{
			if (res)
			{
				document.getElementById('content').className = "";
				document.getElementById('stage').innerHTML = res;
				//document.getElementById('category').value = document.getElementById('filter_title').innerHTML;
			}
			else
			{
				alert('Internal Error!');
			}
			document.body.style.cursor = 'default';
		}
	}
	
	function currentFilter(str,typ)
	{
		if (typ)
		{
			if (typ=='tag') document.getElementById('tagview').innerHTML = '[Viewing: '+str+']';
			else document.getElementById('category').value = str;
		}
		else document.getElementById('category').value = str;
	}
	