// JavaScript Document

d=document;

function showHide(elementid){ 
  if (document.getElementById(elementid).style.display == 'none'){ 
    document.getElementById(elementid).style.display = '';
  } else { 
    document.getElementById(elementid).style.display = 'none'; 
  } 
}

function hideAnnouncement(){
	document.getElementById("announcement").style.display = 'none';
	document.getElementById("screen").style.display = 'none';
	document.getElementById("fullscreen").style.display = 'none';
}

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 popNewWindow(eventID, type) {
	window.open('/event_detail.asp?id=' + eventID + '&type=' + type, '_blank', 'width=450, height=450, scrollbars=yes, menubar=no');
}

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';
	}
  }
}

//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"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
*/

/*
if(window.attachEvent){
  window.attachEvent("onload", startUp);
}
*/

window.onload=startUp;

function startUp(){ 
  cufonReplace();
  defineBrowser(navigator.userAgent);
  if(d.getElementById("standard_login")){
  	bodyOnLoad();
  }
  if(d.getElementById("feature-list")){
  	featureSlider();
  }
}

function featureSlider(){
	$('#feature-list li:first').addClass('top first');
	$('.nav .prev').addClass('disabled');
	
	countDisplay();
	
	$totalCount = $('#feature-list > li').size();
	$currentCount = 1
	
	$('.nav .next').click(function(){
		if( $('.nav .next').hasClass('disabled') ) {
			// if disabled
		} else {
			$('.nav .prev.disabled').removeClass('disabled');
			$('#feature-list li.top').removeClass('top').animate({width: 'toggle'}).next().addClass('top');
			if($currentCount >= $totalCount-4){
				$('.nav .next').addClass('disabled');
			}
			$currentCount++
			countDisplay();
		}
	});
	
	$('.nav .prev').click(function(){
		if( $('.nav .prev').hasClass('disabled') ) {
			// if disabled
		} else {
			$currentCount--
			$('.nav .next.disabled').removeClass('disabled');
			$('#feature-list li.top').removeClass('top').prev().animate({width: 'toggle'}).addClass('top');
			if($currentCount == 1){
				$('.nav .prev').addClass('disabled');
			}
			countDisplay();
		}
	});
	
}

function countDisplay() {
	if( $('.count.hide').hasClass('hide') ) {$('.count.hide').removeClass('hide');}
	$totalCount = $('#feature-list > li').size();
	$currentItem = $('#feature-list li.top').prevAll().length;
	$currentItem++
	$currentVisi = $currentItem + 3;
	$('span.count').html($currentItem+'-'+$currentVisi+'<span> of '+$totalCount+'</span>');
}

function cufonReplace(){
	Cufon.replace('#group_nav a, #groupName, #pageName, #features li a',{
		hover: true
	});
}

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 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 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');
}	


/* 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;
}


