// 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"), "");
		}
	}
}

window.onload=startUp;

function startUp(){

cufonReplacement();
  
  if(d.getElementById("mainNav")){
	//sfHover();
	openMenu();
  } 
  if(window.attachEvent){
    ////replaceActiveX();
  }
  if(d.getElementById("standard_login")){
	bodyOnLoad();
  }
  if(d.getElementById("volunteer")){
	fnInitializeFormElements();
  }
  if(d.getElementById("marquee")){
 	roundedCorners('#marquee .image');
  }
  if(d.getElementById("pageHeader")){
 	roundedCorners('#pageHeader');
  }
  if(d.getElementById("container")){
 	roundedCorners('.imageLeft');
  }
  if(d.getElementById("features")){
	  $('#features').features({
		  name: 'eaglebrook',
		  autoplay: true,
		  delay: 4000,
		  fadeDelay: 750,
		  showPanel: true,
		  showControls: true,
		  showPlayBack: false,
		  thumbControl: true,
		thumbLimit:   8			// limit thumbnails to this number
	});
	$('#features.features ul li').css('display', 'block');
	roundedCorners('#features li');
	}
	
	if(d.getElementById("archives")){
            hidePageName();
            podcastButton();
    }         
}

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 Replaced Items 
function cufonReplacement(){
	$('#mainNav li a').addClass('parent');
	$('#mainNav li li a').removeClass('parent');
	    
	Cufon.replace('#mainNav li a.parent, #pageName, #group_nav .name',{
		fontFamily: 'Arial',
		hover: true
	});  
	
	$('#mainNav li a.parent, #pageName, #group_nav .name').css('display', 'block');

}


function openMenu(){
    $('#mainNav li a.parent').click(function(){
            //$(this).siblings().slideToggle(450);
			$(this).siblings().slideDown(550);
    });
	$('#mainNav li a.parent').parent('li').mouseleave(function(){
			$('#mainNav li ul').slideUp(550);
	});

}


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 TAKES A PREDEFINED ELEMENT AND SETS THE BACKGROUND WHEN THERE IS A PARENT
function roundedCorner($element) {
	$($element).each(function() {
		imgUrl = $(this).find('img').attr('src');
		$(this).css('background-image', 'url('+imgUrl+')');
		$(this).find("img").css("opacity","0");
	});
}

// FUNCTION ADDS A NEW SPAN AROUND THE ELEMENT THEN SETS THE CSS PROPERTIES INLINE
function roundedCorners($element){
    $( $element + " img").wrap(function(){
      	return '<span style="background:url(' + $(this).attr('src') + ') no-repeat top left; width: ' + $(this).width() + 'px; height: ' + $(this).height() + 'px; display:block; visibility:visible;" />';
    });
    $( $element + " img").css("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 setFlashHeight(divid, h){
	document.getElementById(divid).style.height = h+"px";
}


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');
}	

