// (c)2003-2008 activeweave, inc. - http://www.activeweave.com
// author: Jean Sini - mailto:jean@activeweave.com

var ActiveweaveLoader = window.ActiveweaveLoader || {};

ActiveweaveLoader.activeOption = null;

function swap(id, src)
  {
	$(id).src = src;
  }

ActiveweaveLoader.blurLinks = function()
  {
  // remove ugly focus rects on anchors and buttons
  var docLinks = document.getElementsByTagName("a");
	for(var i=0; i<docLinks.length; i++)
    {
		docLinks.item(i).setAttribute("onFocus", "this.blur();");
	  }
  docLinks = document.getElementsByTagName("button");
	for(var i=0; i<docLinks.length; i++)
    {
		docLinks.item(i).setAttribute("onFocus", "this.blur();");
    }
  // great, but it means we can't submit with the enter key - not worth it.
  /*
  docLinks = document.getElementsByTagName("input");
  for(var i=0; i<docLinks.length; i++)
    {
    if(docLinks.item(i).getAttribute("type")=="image")
      {
      docLinks.item(i).setAttribute("onFocus", "this.blur();");
      }
    }
  */
  }

ActiveweaveLoader.init = function()
  {
  ActiveweaveLoader.blurLinks();
  }

ActiveweaveLoader.setSearchOption = function (el)
  {
	var children = new Array();

	if($(el).className == "active")
    {
		if($(el).parentNode.parentNode.parentNode.className != "radio")
      {
			$(el).className = "inactive";
		  }
	  }
  else
    {
		$(el).className = "active";
		if($(el).parentNode.parentNode.parentNode.className == "radio")
      {
			if (!ActiveweaveLoader.activeOption)
        {
				var nel;

				children = getAllChildren($(el).parentNode.parentNode);
				for (var h = 0; nel = children[h]; h++)
					if (nel.className == "active")
						break;
				ActiveweaveLoader.activeOption = nel;
			  }
			if(ActiveweaveLoader.activeOption)
        {
				ActiveweaveLoader.activeOption.className = "inactive";
			  }
			ActiveweaveLoader.activeOption = el;
		  }
	  }
  }

ActiveweaveLoader.rules =
  {
	'#options a' : function(element)
    {
		element.onclick = function()
      {
			ActiveweaveLoader.setSearchOption(this);
		  }
	  }
  }

window.onload = ActiveweaveLoader.init;
Behaviour.start();
Behaviour.register(ActiveweaveLoader.rules);