var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;
var newsfeed_interval = 5000;
var newsitem_top = 5;

function flash(banner, theWidth, theHeight) {
	output = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"" + theWidth + "\" height=\"" + theHeight + "\" id=\"video2\" align=\"middle\">  ";
	output += "<param name=\"allowScriptAccess\" value=\"sameDomain\" />  ";
	output += "<param name=\"movie\" value=\"" + banner + ".swf\" />  ";
	output += "<param name=\"quality\" value=\"high\" />  ";
	output += "<param name=\"wmode\" value=\"transparent\">  ";
	output += "<embed src=\"" + banner + ".swf\" quality=\"high\" wmode=\"transparent\" width=\"" + theWidth + "\" height=\"" + theHeight + "\" name=\"TFSLogo\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />  ";
	output += "</object>  ";
	document.write(output);
}

function ShowMenu(themenu){

	var el = document.getElementById(themenu);
	
	if (el){
		el.style.visibility = 'visible';
	}
}

function HideMenu(themenu){
	var el = document.getElementById(themenu);
	
	if (el){
		el.style.visibility = 'hidden';
	}
}

function offsite(url){
	var xpos = 0;
	var ypos = 0;
	var width=1024;
	var height=768;
	winOptions = 'toolbar=1,location=1,menubar=1,directories=1,screenx=' +  xpos + ',screeny='+ ypos + ',top='+ ypos +',left=' + xpos + ',status=1,menubar=1,scrollbars=1,resizable=1,width=' + width + ',height=' + height;
	var temp = window.open(url, '', winOptions);
	temp.focus();
}

function validateAmount(amount){
	if(amount.value.match( /^[0-9]+(\.([0-9]+))?$/)){
		return true;
	}else{
		alert('You must enter a valid donation.');
		amount.focus();
		return false;
	}
}

function amountFocus(){
	theElement = document.getElementById("item_price_1");
	theElement.value = "";
	theElement.style.color='black'; 
}

function vote(theID){
	$("#poll").load("/includes/_poll.aspx?answerID=" + theID);
}

function intranet(url){
	if (confirm("You are attempting to visit a BSHSI intranet page. You will only be able to access this page from within the BSHSI internal network or via VPN.")){
		var temp = window.open(url, '_new');
		temp.focus();
	}	
}

function blogToggle(theID){
	var curState = document.getElementById(theID).style.display;

	if (curState){
		if (curState == 'block'){
			document.getElementById(theID).style.display='none';
		}else{
			document.getElementById(theID).style.display='block';
		}
	}else{
		document.getElementById(theID).style.display='block';
	}

}

$(document).ready(function(){

	$("#main_nav li.tab:gt(5)").addClass("reverse");

	$($(".slider > a")).click(function () {
		$(this).next("div").slideToggle("fast");
	});

 	$("a.slideshow").each(function(){ $(this).colorbox({ title:$(this).attr('rev'), opacity:1 }) });	
	$("a.slideshow").colorbox({current:""});

	$(".youtube").colorbox({iframe:true, innerWidth:640, innerHeight:385});
	
	$(".annualmeetingslideshow").colorbox({iframe:true, innerWidth:635, innerHeight:415});
	
	$(".tab").hover(

		function () {
			$(this).addClass('tab_hover');
			$(this).children('ul').show();
		},
	
		function () {
			$(this).removeClass('tab_hover');
			$(this).children('ul').hide();
		}

	);

	$(".menu > li[class!='separator']").hover(	

		function () {
			$(this).addClass('menu_item_on');
			$(this).children('ul').show();
		},
	
		function () {
			$(this).removeClass('menu_item_on');
			$(this).children('ul').hide();
		}

	);

	headline_count = $("#callouts_newsfeed > p").size();

  	$("#callouts_newsfeed > p:eq("+current_headline+")").css('top', newsitem_top + 'px');


 	headline_interval = setInterval(headline_rotate, newsfeed_interval);
  	
	$('#callouts_newsfeed').hover(
		function() {
			clearInterval(headline_interval);
  		}, 
		
		function() {
    			headline_interval = setInterval(headline_rotate, newsfeed_interval);
    			headline_rotate();
  		}
	);

	$("ul.menu").hover( 
		function () {
			$(this).prev().addClass('tabhighlight');
		},
		function () {
             $(this).prev().removeClass('tabhighlight');
		}
	);
	
});

function headline_rotate() {
	current_headline = (old_headline + 1) % headline_count;
	$("#callouts_newsfeed > p:eq(" + old_headline + ")").animate({top: -205},"slow", function(){$(this).css('top', '210px');});
  	$("#callouts_newsfeed > p:eq(" + current_headline + ")").animate({top: newsitem_top},"slow");  
 	old_headline = current_headline;
}




	function recordOutboundLink(link, category, action){  
		try{    
			var pageTracker=_gat._getTracker("UA-204618-66");    
			pageTracker._trackEvent(category, action);
    		setTimeout(null, 100);  
		}catch(err){
		}
	}

