// JavaScript Document

d=document;

function killAnnounce(){
  d.getElementById('fullscreen').style.display='none';
  d.getElementById('screen').style.display='none';
}


function showHide(elementid){ 
  if (d.getElementById(elementid).style.display == 'none'){ 
    d.getElementById(elementid).style.display = '';
  } else { 
    d.getElementById(elementid).style.display = 'none'; 
  } 
}


//getElementsByClassName() Written by Jonathan Snook, http://www.snook.ca/jonathan; Add-ons by Robert Nyman, http://www.robertnyman.com
function getElementsByClassName(oElm, strTagName, strClassName){
  var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
  var arrReturnElements = new Array();
  strClassName = strClassName.replace(/\-/g, "\\-");
  var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
  var oElement;
  for(var i=0; i<arrElements.length; i++){
    oElement = arrElements[i];      
    if(oRegExp.test(oElement.className)){
      arrReturnElements.push(oElement);
    }   
  }
  return (arrReturnElements)
}


function launchPlayer(messageID){
  if(playerWin){
	  playerWin.close();
  }
  var playerWin=window.open('/media_player.asp?messageID=' + messageID,playerWin,'width=550,height=450,toolbar=false,resizable=false,menubar=false,scrollbars=false,status=false');
}	

function launchPlayerLarge(messageID,winWidth,winHeight){
  if(playerWin){
	playerWin.close();
  }
  var playerWin=window.open('/media_player.asp?type=large&messageID=' + messageID,playerWin,'width=' + winWidth + ',height=' + winHeight + ',toolbar=false,resizable=false,menubar=false,scrollbars=false,status=false');
}	


function popNewWindow(eventID, type) {
	window.open('/event_detail.asp?id=' + eventID + '&type=' + type, '_blank', 'width=450, height=450, scrollbars=yes, menubar=no');
}


//sfHover couresty of http://www.htmldog.com (http://www.htmldog.com/articles/suckerfish/dropdowns/)
sfHover = function() {
	var sfEls = d.getElementById("nav").getElementsByTagName("li");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}


function navSlideUp() {
	
	if($('body').parent().hasClass('ie8')){
		$('#nav li a').addClass('parent-link').parent().addClass('parent');
	} else if($('body').parent().hasClass('ie7')){
		$('#nav li a').addClass('parent-link').parent().addClass('parent');
	} else {
		$('#nav li a').addClass('parent-link').parent().addClass('parent');
		$('#nav li a').addClass('parent-link').parent().addClass('parent').find('div').css({opacity:0.0});
	}
	$('#nav div li.parent').removeClass('parent');
	$('#nav div a.parent-link').removeClass('parent-link');
	
	$('#nav li.parent a.parent-link').mouseenter(function(){
		subnavHeight       = $(this).parent().find('div').height();
		mainnavHeight      = $(this).parent().height();
		subnavHeightMargin = 305 - parseInt(subnavHeight)-mainnavHeight-5;
		if($(this).parent().hasClass('shown')) {
			return false;
		} else {
			if($('body').parent().hasClass('ie8')){
				$(this).parent().find('div').css('top', subnavHeightMargin+'px');
				$(this).parent().addClass('shown').find('div');
			} else if($('body').parent().hasClass('ie7')){
				$(this).parent().find('div').css('top', subnavHeightMargin+'px');
				$(this).parent().addClass('shown').find('div');
			} else {
				$(this).parent().find('div').css('top', subnavHeightMargin+'px');
				$(this).parent().addClass('shown').find('div').animate({
					opacity: 1.0
				});   
			}
		}
	}).parent().mouseleave(function(){
		if($('body').parent().hasClass('ie8')){
			$('#nav li.parent.shown a.parent-link').parent().removeClass('shown');
		} else if($('body').parent().hasClass('ie7')){
			$('#nav li.parent.shown a.parent-link').parent().removeClass('shown');
		} else {
			$(this).parent().find('div').animate({
				opacity: 0.0
			});
			$('#nav li.parent.shown a.parent-link').parent().removeClass('shown');		
		}
	});
	
}


/* Javascript to determine browser and add as a class */
function defineBrowser(u){
	var ua = u.toLowerCase();
	is=function(t){return ua.indexOf(t)>-1;};
	g='gecko';
	w='webkit';
	s='safari';
	o='opera';
	h=document.getElementsByTagName('html')[0];
	b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):
		is('firefox/2')?g+' ff2':
		is('firefox/3.5')?g+' ff3 ff3_5':
		is('firefox/3')?g+' ff3':
		is('gecko/')?g:
		is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):
		is('konqueror')?'konqueror':
		is('chrome')?w+' chrome':
		is('iron')?w+' iron':
		is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):
		is('mozilla/')?g:'',
		is('j2me')?'mobile':
		is('iphone')?'iphone':
		is('ipod')?'ipod':
		is('mac')?'mac':
		is('darwin')?'mac':
		is('webtv')?'webtv':
		is('win')?'win':
		is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; 
	c = b.join(' '); 
	h.className += ' '+c; return c;
}



window.onload=startUp;

function startUp(){
	cufonReplacement();
	defineBrowser(navigator.userAgent);
	
	if(d.getElementById("nav")){
		sfHover();
		navSlideUp();
	}

  if(window.attachEvent){
    ////replaceActiveX();
  }
  if(d.getElementById("standard_login")){
	  bodyOnLoad();
  }
  if(d.getElementById("volunteer")){
	  fnInitializeFormElements();
  }
  if(d.getElementById("archives")){
      hidePageName();
      podcastButton();
  }
  if(d.getElementById("features")){
		$('#features').features({
			name: 'features',
			autoplay: true,
			delay: 4000,
			fadeDelay: 750,
			showPanel: false,
			showControls: true,
			showPlayBack: false,
			thumbControl: false,
			addCount: true,
	        addCountOf: true 			// adds 1 of # count
		});
		$('#features.features ul li').css('display', 'block');
	}

}


function updateName(myName){
  if(myName){
    d.getElementById('staff_name').innerHTML=myName;
  }else{
	d.getElementById('staff_name').innerHTML="Click a photo below to view details";
  }
}


function showStaff(total, obj, source){  
  for(var i=1; i<=total; i++){
	  if(i==obj){
	    d.getElementById('staff' + obj).style.display='';
	    var image="<img src='" + source + "'>";
	    d.getElementById('staff_image' + obj).innerHTML=image;
	  }else{
	    d.getElementById('staff' + i).style.display='none';
	  }
  }
}


function URLencode(sStr) {
  return escape(sStr).replace(/\+/g, '%2C').replace(/\"/g,'%22').replace(/\'/g, '%27');
}

function fileDownload(filePath){
  filePath = URLencode(filePath);
  var fileDownloader=window.open('/file_download_launch.asp?filePath=' + filePath,'fileDialog','width=400,height=300,toolbar=false,resizable=false,menubar=false,scrollbars=false,status=false');
}

function hidePageName(){
    d.getElementById('pageName').style.display = 'none'; 
}

function podcastButton(){
    $("a.podcast").parent('li').addClass("podcastLi");
    
    $(".podcastLi").mouseover(function() {
      $("div.podcastList").removeClass("hidden ");
    }).mouseout(function(){
      $("div.podcastList").addClass("hidden");
    });
}

// CUFON FONT REPLACEMENT 
function cufonReplacement(){
	
	Cufon.replace('#pageName, #group_nav .name, #features h2, #nav li span',{
		hover: true,
		fontFamily: 'Garamond Premiere Pro'
	});
	Cufon.replace('#group_nav li a',{
		hover: true,
		fontFamily: 'Arial Narrow'
	});
	Cufon.replace('#quote p',{
		hover: true,
		fontFamily: 'Annie BTN'
	});
	Cufon.replace('#nav li a, #nav li li a, #features a.readMore',{
		hover: true,
		fontFamily: 'Univers'
	});	
	$('#pageName').css('display', 'block');
}


