$(document).ready(function(){

//Rotate "Thank You" Pics
var pagePic = Math.ceil(Math.random() * 12);
$("#thankyou_pic")[0].className = "pic" + pagePic; 


//Donation Button
$("#donate-now a").click(
function ()
{
   window.open(this.href, 'popup', 'menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,width=500,height=500');
   return false;
});

var IEVer = $.browser.version;

//Dropdown Menus
$('#navigation li.active').mouseover(function() {
	$('#navigation li').each(function() {
		if(this.className == 'over') {
			this.className = 'up';
		}
	});
});

if (!($.browser.msie && IEVer == "6.0")) {
$('#navigation li.up').hover(
	
	function() {
		var subNav = this.getElementsByTagName('ul');
		
				$('#navigation li').each(function() {	
				if(this.className != 'active') {
					this.className = "up";
				} 
			});
		
		if(this.className != 'active' && subNav.length != 0) {
			var leftDist = this.firstChild.offsetWidth;
			this.getElementsByTagName('ul')[0].style.left = leftDist + 12 + "px";		
			this.className = "over";
			}
	},
	function() {
		if(this.className != 'active')
		{
		    
		}
	});
}
	

if (!($.browser.msie && IEVer == "6.0")) {	
$('#navigation li.up2').hover(	
	function() {
		var subNav = this.getElementsByTagName('ul');
		
		$('#navigation li.over ul li').each(function() {	
			this.className = "up2";
		});

		if(this.className != 'active' && subNav.length != 0) {
			var leftDist = this.firstChild.offsetWidth;
			this.getElementsByTagName('ul')[0].style.left = leftDist + 12 + "px";		
			this.className = "over";
			}
	},
	function() {
		if(this.className != 'active')
		{
			
		}
	});	
}


$('#navigation').hover(

function () {

},
	
	function() {


   
	if (!($.browser.msie && IEVer == "6.0")) {
                $('#navigation li').each(function() {
                
                
		    if(this.className == 'over') {
			this.className = 'up';
		    }
	        });
        }

});

// Hide FAQ Elements from FAQ Template
$("#navigation li ul li").each(
function ()
{
var faq = this.getElementsByTagName("a")[0];
var faqurl = this.getElementsByTagName("a")[0].href;     
faqurl = faqurl.substring(faqurl.lastIndexOf("/") + 1);
if(faqurl == "faq.aspx")
{
this.getElementsByTagName("ul")[0].style.display = "none";
}
});


// START TOOLTIP IMAGE SCRIPT
var tipimages=new Array();
function preloadimages(){
for (i=0;i<preloadimages.arguments.length;i++){
tipimages[i]=new Image();
tipimages[i].src=preloadimages.arguments[i];
}
}

var loadImages = "";

$('a.tooltip').each(function () {
	loadImages = loadImages + "'" + this + "',";	
});
loadImages = loadImages.substring(0, (loadImages.length - 1));

preloadimages(loadImages);



$('a.tooltip').click(function () {
	return false;
});

    var offSetTip = (window.innerWidth - 920)/2;
    if(offSetTip < 0) { offSetTip = 0 }



$('a.tooltip').hover(function (e) {
    // customize border
var IEVer = $.browser.version;
	if (!($.browser.msie && IEVer == "6.0")) {
        offSetTip = e.pageX - 1200/2;
         if(offSetTip < 0) { offSetTip = 0 }
}
    var borderColor = "#976135";
    var borderSize = "3px";
	var cursorX = e.pageX - offSetTip + 30;
	var cursorY = e.pageY - 80;
	this.innerHTML = this.innerHTML + "<img src='" + this + "' style='border:" + borderSize + " solid " + borderColor + " ; position:absolute; top:" +  cursorY + "px; left:" + cursorX + "px; display: none;' />";
	var tipImg = this.firstChild.nextSibling;
	$('a.tooltip img').fadeIn('fast');
	
},
function() {
	
        var linkText = this.innerHTML.substr(0,this.innerHTML.indexOf('<'));
	this.style.position = "static";
        this.innerHTML = linkText;
});


$('a.tooltip').mousemove(function(e2){
		var tipImgs = $(this).children();
                tipImgs.each(
                function()
                {
                  if(this.src != "")
                  {
                     tipImg = this;
                  }
                });
                
                cursorX = e2.pageX - offSetTip + 30;
		cursorY = e2.pageY - 80;
		tipImg.style.left = cursorX + "px";
		tipImg.style.top = cursorY + "px";
	});
// END TOOLTIP IMAGE SCRIPT
	

// ADD EXTRA COLUMN TO BOARD MEMBER LISTING WITHOUT COMPROMISING SEMANTIC VALUE OF MARKUP AND RETAINING EASE OF UPDATE
$("#staff-listing ul").each(
function()
{
  if(this.getElementsByTagName("li").length > 14)
  {
      var members = this.getElementsByTagName("li");
      var columnHeight = Math.ceil(members.length/2);
      var columnTwo = new Array();
      for(i=columnHeight;i<members.length;i++)
      {
        columnTwo.push("<li>" + members[i].innerHTML + "</li>");
        $(members[i]).empty();
      }
      $(this).after("<ul class='columnTwo'></ul>");
      for(i=0;i<columnTwo.length;i++)
      {
        $(".columnTwo")[0].innerHTML = $(".columnTwo")[0].innerHTML + columnTwo[i];
      }
      $(".columnTwo").after("<div style='clear: both'></div>");
      this.style.width = 175 + "px";
      this.style.paddingRight = 15 + "px";
      this.style.cssFloat = "left";
      this.style.styleFloat = "left";
      $(".columnTwo")[0].style.width = 175 + "px";
      $(".columnTwo")[0].style.paddingRight = 15 + "px";
      $(".columnTwo")[0].style.cssFloat = "left";
      $(".columnTwo")[0].style.styleFloat = "left";
  }
  var liNodes = this.getElementsByTagName("li");
  for(i=0;i<liNodes.length;i++)
  {
      if(liNodes[i].innerHTML == "")
      {
         liNodes[i].style.display = "none";
      }
  }
});



	
});
