/* Sniffs */

var isIE = (document.getElementById && document.all)?true:false;
var isNS4 = (document.layers)?true:false;
var isNS6 = (document.getElementById && !document.all)?true:false;

/* Toolbox */

function myGetElementById (id)
{
    if ( isIE )
    {
	var str = "document.all('" + id + "')";
	var o = eval(str);
	return o;
    }

    return document.getElementById(id);
}

function myGetElementsByClass(searchClass,node,tag) {
  var classElements = new Array();
  if (node == null)
    node = document;
  if (tag == null)
    tag = '*';
  var els = node.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
  for (i = 0, j = 0; i < elsLen; i++) {
    if (pattern.test(els[i].className) ) {
      classElements[j] = els[i];
      j++;
    }
  }
  return classElements;
}

function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function initHelpIcons() {
	var loginHelp = myGetElementById('login-help');
	var loginCallout = myGetElementById('login-help-callout');
	if ( loginHelp ) {
		loginHelp.onmouseover = function() {
			loginCallout.style.left = findPos(this)[0] - 250 + "px";
			loginCallout.style.top =  findPos(this)[1] + 27 + "px";
			loginCallout.style.display = "block";
		}
		loginHelp.onmouseout = function() {
			loginCallout.style.display = "none";
		}
	}
	var toolsHelp = myGetElementById('tools-help');
	var toolsCallout = myGetElementById('tools-help-callout');
	if ( toolsHelp ) {
		toolsHelp.onmouseover = function() {
			toolsCallout.style.left = findPos(this)[0]- 250 + "px";
			toolsCallout.style.top =  findPos(this)[1] + 27 + "px";
			toolsCallout.style.display = "block";
		}
		toolsHelp.onmouseout = function() {
			toolsCallout.style.display = "none";
		}
	}
}

function searchInput(text,input) {  
	
  if (!myGetElementById(input)) return false;
    myGetElementById(input).onfocus = function() {
      if (this.value == text) {
        this.value = "";
      }
    }
    myGetElementById(input).onblur = function() {
      if (this.value == "") {
        this.value = text;
      }
    }
}

function initExpandables() {
	var expandables = myGetElementsByClass('expandable',null,'ul');
	for ( var a=0; a<expandables.length; a++ ) {
		var togglers = myGetElementsByClass('toggler',expandables[a],'a');
		for ( var b=0; b<togglers.length; b++ ) {
			togglers[b].onclick = function() {
				var mom = this.parentNode;
				if ( mom.className == "open" ) {
					mom.className = "closed";
				} else { 
					mom.className = "open";
				}
				return false;
			}
		}
	}
}

function initEventsTabs() {
	if (!myGetElementById('events-wrap')) return false;
	var eWrap = myGetElementById('events-wrap');
	var clubT = myGetElementById('go-club-events');
	var centT = myGetElementById('go-cent-events');
	var clubE = myGetElementById('club-events');
	var centE = myGetElementById('cent-events');
	clubT.onclick = function() {
		if ( eWrap.className == "cent" ) {
			eWrap.className = "club";
		} else {
			return false;
		}
		return false;
	}
	centT.onclick = function() {
		if ( eWrap.className == "club" ) {
			eWrap.className = "cent";
		} else {
			return false;
		}
		return false;
	} 
}

function initHomeTabs() {
	if (!myGetElementById('col2')) return false;
	var cWrap = myGetElementById('col2');
	var newT = myGetElementById('home-whatsnew-tab');
	var calT = myGetElementById('home-events-tab');
	var whatsNew = myGetElementById('home-whatsnew');
	var homeEvents = myGetElementById('home-events');
	newT.onclick = function() {
		if ( cWrap.className == "events" ) {
			cWrap.className = "whatsnew";
		} else {
			return false;
		}
		return false;
	}
	calT.onclick = function() {
		if ( cWrap.className == "whatsnew" ) {
			cWrap.className = "events";
		} else {
			return false;
		}
		return false;
	}
	
	/*
	var oRes = myGetElementById('home-resources');
	var resT = myGetElementById('home-resources-tab');
	resT.onmouseover = function() {
		oRes.style.left = findPos(this)[0] - 15 + "px";
		oRes.style.top =  findPos(this)[1] - 11 + "px";
		oRes.style.display = "block";
	}
	oRes.onmouseout = function() {
		oRes.style.display = "none";
	} 
	
	*/
	
}

	function openSection() {
		$(this).parent('li').removeClass('open');
		$(this).parent('li').removeClass('closed');
		$(this).parent('li').siblings().removeClass('open').addClass('closed');
		$(this).parent('li').removeClass('closed').addClass('open');
		return false;
	}
	

 $(document).ready(function(){
 
 	$("#home-resources-tab").hover(
      function () {
        $("#home-resources").show();
      }, 
      function () {
      }
    );
    
   	$("#home-resources").hover(
      function () {
      }, 
      function () {
        $(this).hide();
      }
    );
    $('ul.expandable li a.fancypants').click(openSection);
 });
