// JavaScript Document
var ss = {

	init: function() {
		
		if (!document.getElementById || !document.getElementsByTagName) { return; }	
		this.util.configEvents();
		
		this.changeButton();
			
		this.catinfo = document.getElementById('catinfo'); 
		this.maincontent = document.getElementById('maincontent');
		this.category = this.maincontent.getElementsByTagName('a');
		if (this.catinfo) {
			this.util.addEvent(this.maincontent, 'click', this.showInfo, false);	
		}

	},
	
	changeButton : function() {
		
		ss.currentPage = document.getElementsByTagName('body')[0]; 
		ss.currentPage = ss.currentPage.className;
		ss.currentButton = document.getElementById(ss.currentPage);
		ss.currentButton.firstChild.className = 'current';
		
	},
	
	showInfo : function(evt) {
		
	var theLink = ss.util.findTarget(evt, 'a', this);

		if (!theLink) { return; }
		for (var i=0, links=ss.category.length; i<links; i++) {
			var oldCategory = ss.category[i].rel;
			var oldSelected = document.getElementById(oldCategory);
			oldSelected.className = '';
		}
		var newCategory = theLink.rel;
		var newSelected = document.getElementById(newCategory);
		newSelected.className = 'show';
	},
	
	util : {

    configEvents : function() {
      if (document.addEventListener) {
        this.addEvent = function(el, type, func, capture) { el.addEventListener(type, func, capture); };
        this.stopBubble = function(evt) { evt.stopPropagation(); };
        this.stopDefault = function(evt) { evt.preventDefault(); };
        this.findTarget = function(evt, targetNode, container) {
         var currentNode = evt.target;
         while (currentNode && currentNode !== container) {
          if (currentNode.nodeName.toLowerCase() === targetNode) { return currentNode; break; }
          else { currentNode = currentNode.parentNode; }
         };
         return false;
        };
      }
      else if (document.attachEvent) {
       this.addEvent = function(el, type, func) { el["e" + type + func] = func; el[type + func] = function() { el["e" + type + func] (window.event); }; el.attachEvent("on" + type, el[type + func]); };
       this.stopBubble = function(evt) { evt.cancelBubble = true; };
       this.stopDefault = function(evt) { evt.returnValue = false; };
       this.findTarget = function(evt, targetNode, container) { var currentNode = evt.srcElement; 
        while (currentNode && currentNode !== container) {
         if (currentNode.nodeName.toLowerCase() === targetNode) { return currentNode; break; }
         else { currentNode = currentNode.parentNode; }
        };
        return false;
       };
      }
    }
  
  }

};

ss.init();

