function addBreadCrumb(){
	var bc = document.getElementById('bread-crumb');
	if(bc){
		var settings = document.documentElement.lastChild.className;
		var crumb = settings.split(" ");
		if(crumb[crumb.length-1]=="three"){crumb.pop();}
		if(crumb[crumb.length-1]=="tertiary"){crumb.pop();}
		if(crumb[crumb.length-1]=="us-print"){crumb.pop();}
		for(var k=0;k<crumb.length;k++){
			
			var li = document.createElement('li');
			var a = document.createElement('a');
			var node = $('#header-nav .'+crumb[k])[0];
			a.href = node.firstChild.href;
			
			var t = node.firstChild.firstChild.nodeValue;
			if(t.length > 27){
				t = t.substr(0,24)+"\u2026";
			}
			a.appendChild(document.createTextNode(t));
			li.appendChild(a);
			if(k==crumb.length-1){li.className="last"};
			bc.appendChild(li);
		}
	}
}

function findLinks(){
	var a = document.getElementsByTagName('a');
	for(var k=0;k<a.length;k++){
		if(/baxter-site/.test(a[k].className)){
			if(/(MSIE 6)|(MSIE 7)/.test(navigator.userAgent)){
				a[k].className = "baxter-site no-bg";
				var sp = document.createElement('span')
				sp.appendChild(document.createTextNode(' '));
				sp.className="external";
				a[k].appendChild(sp);
			}
		}
		if(/application-link/.test(a[k].className)){
			if(/(MSIE 6)|(MSIE 7)/.test(navigator.userAgent)){
				a[k].className = "application no-bg";
				var sp = document.createElement('span')
				sp.appendChild(document.createTextNode(' '));
				sp.className="external";
				a[k].appendChild(sp);
			} else {
				a[k].className="application-link external";	
			}
			a[k].onclick = function(){
				dcsMultiTrack('DCS.dcsuri',this.href);
				return true;
			}
			continue;
		}
		if(/application/.test(a[k].className)){
			a[k].onclick = function(){
				dcsMultiTrack('DCS.dcsuri',this.href);
				return true;
			}
		}
		
		if(/external/.test(a[k].className)){
			a[k].href = '/external/external_site.html?url=' + a[k].href;
			if(/(MSIE 6)|(MSIE 7)/.test(navigator.userAgent)){
				a[k].className = "external no-bg";
				var sp = document.createElement('span')
				sp.appendChild(document.createTextNode(' '));
				sp.className="external";
				a[k].appendChild(sp);
			}
			a[k].onclick = function(){
				window.open(this.href,"_blank");
				return false;	
			}
		} else if(/pdf/.test(a[k].className)){
			if(/(MSIE 6)|(MSIE 7)/.test(navigator.userAgent)){
				a[k].className = "pdf no-bg";
				var sp = document.createElement('span')
				sp.appendChild(document.createTextNode(' '));
				sp.className="pdf";
				a[k].appendChild(sp);
			}
			if(/baxter.com/.test(a[k].href)){
				a[k].onclick = function(){
					dcsMultiTrack('DCS.dcsuri',this.href+"?WT.svl=BiosciencePIs&site="+document.location.host);
					window.open(this.href+"?WT.svl=BiosciencePIs&site="+document.location.host,"_blank");
					return false;
				}
			} else {
				a[k].onclick = function(){
					dcsMultiTrack('DCS.dcssip',document.location.hostname,'DCS.dcsuri',this.href,'WT.dl','20','WT.z_pdfdownload',this.pathname,'WT.z_pdfdownloadcount','1');
					window.open(this.href,"_blank");
					return false;
				}
			}
		} else if(/order-form|web-form/.test(a[k].className)){
			a[k].onclick = function(){window.open(this.href,'form','width=720,resizable=yes,scrollbars=yes');return false;}
		}
	}
}

function setExternal(){
	var f = document.getElementById('frame');
	f.height = document.documentElement.clientHeight-180;
	f.src = document.location.search.replace("?url=","");
	window.onresize = function(){
		document.getElementById('frame').height = document.documentElement.clientHeight-180;
	}
}

function printChecklistUS(){
	document.getElementById('us-print').onclick = function(){
		$('body').removeClass('cc-print');
		$('body').removeClass('ged-print');
		$('body').addClass('us-print');
		window.print();
	}
	document.getElementById('cc-print').onclick = function(){
		$('body').removeClass('ged-print');
		$('body').removeClass('us-print');
		$('body').addClass('cc-print');
		window.print();
	}
	document.getElementById('ged-print').onclick = function(){	
		$('body').removeClass('cc-print');
		$('body').removeClass('us-print');
		$('body').addClass('ged-print');
		window.print();
	}
}

function insertBanner(){
	var f = new Flash($('#banner')[0],"/flash/scholarship.swf",1020,370,10,true);
	f.insert();
}

function updateMenu(){
	setTimeout(function(){Cufon.replace('#header-nav > ul > li > a',{fontFamily:'menu'},false);}, 10);
}

function ieMenuFix(){
	if($('#header-nav').length){
		$('#header-nav .scholarship')[0].onmouseover = function(){$(this).addClass("show");}
		$('#header-nav .scholarship')[0].onmouseleave = function(){$(this).removeClass("show");}
		$('#header-nav .education')[0].onmouseover = function(){$(this).addClass("show");}
		$('#header-nav .education')[0].onmouseleave = function(){$(this).removeClass("show");}
		$('#header-nav .career')[0].onmouseover = function(){$(this).addClass("show");}
		$('#header-nav .career')[0].onmouseleave = function(){$(this).removeClass("show");}
		$('#header-nav .health')[0].onmouseover = function(){$(this).addClass("show");}
		$('#header-nav .health')[0].onmouseleave = function(){$(this).removeClass("show");}
		$('#header-nav .community')[0].onmouseover = function(){$(this).addClass("show");}
		$('#header-nav .community')[0].onmouseleave = function(){$(this).removeClass("show");}
		
		$('.scholarship #header-nav ul .scholarship ul li:first-child').css("background","transparent url(/images/ui/tape-bottom.png) no-repeat 0 0");
		$('.education #header-nav ul .education ul li:first-child').css("background","transparent url(/images/ui/tape-bottom.png) no-repeat 0 0");
		$('.career #header-nav ul .career ul li:first-child').css("background","transparent url(/images/ie/main-nav-highlight-tape-140-2.png) no-repeat 0 -46px");
		$('.health #header-nav ul .career ul li:first-child').css("background","transparent url(/images/ie/main-nav-highlight-tape-163.png) no-repeat 138px -47px");
		$('.health #header-nav ul .health ul li:first-child').css("background","transparent url(/images/ui/tape-bottom.png) no-repeat 0 0");
		$('.community #header-nav ul .community ul li:first-child').css("background","transparent url(/images/ie/main-nav-highlight-tape-140.png) no-repeat 0 0");
		$('#left-nav ul li ul li ul li:first-child').css("background","transparent url(/images/ie/subnav-top.png) no-repeat 19px 3px");
		$('#left-nav ul li ul li ul li:first-child').css("padding-top","20px");
	}
}


function setCookie(){
	document.cookie = "resourceFlyer=findoutforsure; path=/;"
}

function hasCookie(){
	var cookies = document.cookie.split(';');
	for(var i=0;i < cookies.length;i++){
		var c = cookies[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf("source") == 0) return true;//cookie is set
	}
	return false;//cookie is not set
}

function shadowBox(){
	if(!document.getElementById('shadow-box')){
		$('body').prepend('<div id="shadow-box">&nbsp;</div><div id="vid-outer"></div>');
		$('#shadow-box').fadeTo(0,.5);
		if($.browser.msie){
			$('#shadow-box').height($(window).height());
		}
	}
	$('#shadow-box').fadeTo(200,.5).show();
}

function unloadVidPlayer(){
	$('#vid-inner').fadeTo(300,0,function(){
		$('#vid-inner').hide();
		if($.browser.msie){$('#vid-inner').remove();}
	});
	$('#shadow-box').fadeTo(200,0,function(){
		$('#shadow-box').hide();
	});	
}



function loadVidPlayer(vidName){
	$.get('/videoplayer/video-overlay.html',function(data){
		vidRaw = vidName.match(/[^\.]+/);
		shadowBox();
		$('#vid-outer').html(data);
		if(/nick|nicholas/.test(vidRaw)){
	   		$('#title').html("Nicholas&rsquo; Interview");
	    }else if(/grant/.test(vidRaw)){
		   $('#title').html("Grant&rsquo;s Interview");
	    }
		var innerClass;
		if(/grant-full/.test(vidRaw)){
			innerClass = "nicholas-video";
		}else if(/nicholas-full/.test(vidRaw)){
			innerClass = "grant-video";
		}else{
			innerClass = "fork-in-road";
		}
		$('#vid-inner').removeClass().addClass(innerClass);	
		Cufon.replace('#vid-outer h2, #vid-outer h3');
		if('swfobject' in window && $('#vid-placeholder').length){		
			swfobject.embedSWF('/videoplayer/videoholder.swf','vid-placeholder','560','355','9.0.0','/swf/expressInstall.swf',{"flvpathraw":vidRaw},{"wmode":"transparent"},null,function(e){});
		}
	});
}

function init(){
	if(arguments.callee.doOnce){return;}
	arguments.callee.doOnce=true;
	if(/MSIE 6/.test(navigator.userAgent)){ieMenuFix();}
	
	if(document.location.search == "?resourceflyer=findoutforsure" && !hasCookie()){
		setCookie();	
	}
	if(hasCookie()){
		var a = document.getElementsByTagName('a');
		for(var k=0;k<a.length;k++){
			if(/https:\/\/webforms\.baxterbioscience\.com\/edua\/register\.jspa/.test(a[k].href)){
				a[k].href = "https://webforms.baxterbioscience.com/edua/register.jspa?source=BXEAWF0103";
			}
		}
	}
	
	
	
	addBreadCrumb();
	findLinks();
	if(document.getElementById('external')){setExternal();}
	if('Cufon' in window){Cufon.now();}
	$('#header-nav > ul > li').hover(updateMenu,updateMenu);
	if(document.getElementById('banner')){insertBanner();}
	if(document.getElementById('htc-submit')){initHTCLocator();}
	if(document.getElementById('us-print')){printChecklistUS();}
	
	if($('#scholarship-tabs').length){
		$('#text').addClass('js-text');
		$('#scholarship-tabs li').removeClass('tab-active');
		$('#scholarship-tabs li .content').hide();
		$('#scholarship-tabs li:eq(0) .content').show();
		$('#scholarship-tabs li:eq(0)').addClass('tab-active');
		$('#scholarship-tabs').height($('#scholarship-tabs').find('div.content').outerHeight(true));
		Cufon.refresh();
		$('#scholarship-tabs li').click(function(){
			$('#scholarship-tabs li').removeClass('tab-active');
			$('#scholarship-tabs li div.content').hide();
			$(this).find('div.content').show();
			$(this).addClass('tab-active');
			$('#scholarship-tabs').height($(this).find('div.content').outerHeight(true));
			var activeTab = $('#scholarship-tabs').children('li').index($(this)) +1;
			if(/university-tabs/.test($('#scholarship-tabs').attr('class'))){
				$('#scholarship-tabs').css('background','url(/images/ui/tabs/scholarship-tabs-'+activeTab+'.png) 0 0 no-repeat');
			}else if(/ged-tabs/.test($('#scholarship-tabs').attr('class'))){
				$('#scholarship-tabs').css('background','url(/images/ui/tabs/ged-tab-'+activeTab+'.png) 0 0 no-repeat');
			}else if(/career-tabs/.test($('#scholarship-tabs').attr('class'))){
				$('#scholarship-tabs').css('background','url(/images/ui/tabs/career-planning-tab-'+activeTab+'.png) 0 0 no-repeat');
			}
			else if(/health-tabs/.test($('#scholarship-tabs').attr('class'))){
				$('#scholarship-tabs').css('background','url(/images/ui/tabs/health-landing-tab-'+activeTab+'.png) 0 0 no-repeat');
			}
			Cufon.refresh();
		});
		if(window.location.hash){
			$('#scholarship-tabs li').removeClass('tab-active');
			$('#scholarship-tabs li div.content').hide();
			$((window.location.hash)).siblings('div.content').show();
			$((window.location.hash)).parent().addClass('tab-active');
			$('#scholarship-tabs').height($((window.location.hash)).siblings('div.content').outerHeight(true));
			var activeTab = $('#scholarship-tabs').children('li').index($(window.location.hash).parent()) +1;
			if(/university-tabs/.test($('#scholarship-tabs').attr('class'))){
				$('#scholarship-tabs').css('background','url(/images/ui/tabs/scholarship-tabs-'+activeTab+'.png) 0 0 no-repeat');
			}else if(/ged-tabs/.test($('#scholarship-tabs').attr('class'))){
				$('#scholarship-tabs').css('background','url(/images/ui/tabs/ged-tab-'+activeTab+'.png) 0 0 no-repeat');
			}else if(/career-tabs/.test($('#scholarship-tabs').attr('class'))){
				$('#scholarship-tabs').css('background','url(/images/ui/tabs/career-planning-tab-'+activeTab+'.png) 0 0 no-repeat');
			}
			else if(/health-tabs/.test($('#scholarship-tabs').attr('class'))){
				$('#scholarship-tabs').css('background','url(/images/ui/tabs/health-landing-tab-'+activeTab+'.png) 0 0 no-repeat');
			}
			Cufon.refresh();	
		}
	}
	/**/
	//if($('a[rel^="video-launch_"]').length){			
		$('a#xBtn').live('click',function(){
			unloadVidPlayer();
			return false;
		});	
		
		$('a[rel^="video-launch_"]').live('click',function(){
			var vidName = this.rel.match(/^(?:video-launch_)(.*)/)[1];
			
			if('dcsMultiTrack' in window){
				if(this.search && this.search.match(/^\?([^=]+)=1$/) && this.search.match(/^\?([^=]+)=1$/)[1]){
					dcsMultiTrack('WT.dl','22',this.search.match(/^\?([^=]+)=1$/)[1],'1');
				}
			}
			
			loadVidPlayer(vidName);
			return false;
		});
		
		$('#return-to-page').live('click',function(){
			unloadVidPlayer();
			return false;
		});
		
	//}
	
	$('#shadow-box').live('click',unloadVidPlayer);
	
	if($.browser.msie && $.browser.version <= 6){
		scrollPos = document.documentElement.scrollTop;
		$('#shadow-box').height($(window).height());
		$(window).resize(function(){
			$('#shadow-box').height($(window).height());
		});
		$(window).scroll(function(){
			//scrollPos = document.documentElement.scrollTop;
			//$('#shadow-box').css({"top":scrollPos+"px"});
			//$('#vid-outer').css({"top":scrollPos+100+"px"});
		});
		if($('.video-co').length){
			$('.video-co img[class^=avatar]').each(function(){
				$(this).parent().addClass($(this).attr('class'));
				$(this).removeClass();
			});
		}
	}
	
	if(document.location.search.match(/nicholasvideo=1/)){
		loadVidPlayer('nicholas-full');
	}

}

if('Cufon' in window){
	Cufon.replace('#banner-static .recipients h1',{fontFamily:'header'});
	Cufon.replace('#header-nav > ul > li > a',{fontFamily:'menu'});
	Cufon.replace('#description h1',{fontFamily:'header'});
	Cufon.replace('#description h2',{fontFamily:'header'});
	Cufon.replace('#description .get-started .title',{fontFamily:'header'});
	Cufon.replace('#text h1',{fontFamily:'header'});
	Cufon.replace('#text h2',{fontFamily:'header'});
	Cufon.replace('#text h2 a.share-this',{fontFamily:'header',hover:true});
	Cufon.replace('#home-callouts li .title',{fontFamily:'header'});
	Cufon.replace('#right-nav li .title',{fontFamily:'header'});
	
	Cufon.replace('#external h2',{fontFamily:'header'});
	
	Cufon.replace('#sitemap .scholarship > a',{fontFamily:'header',hover:true});
	Cufon.replace('#sitemap .education > a',{fontFamily:'header',hover:true});
	Cufon.replace('#sitemap .career > a',{fontFamily:'header',hover:true});
	Cufon.replace('#sitemap .health > a',{fontFamily:'header',hover:true});
	Cufon.replace('#sitemap .community > a',{fontFamily:'header',hover:true});
	
	Cufon.replace('#recipients .location',{fontFamily:'header',hover:true});
	Cufon.replace('#scholarship-tabs h4',{fontFamily:'header'});
	Cufon.replace('#scholarship-tabs > li > h3',{fontFamily:'header'});
	Cufon.replace('#scholarship-tabs > .tab-active > h3',{fontFamily:'header'});
	Cufon.replace('.home #pillars ul li h3',{fontFamily:'header'});
	Cufon.replace('.home #callouts h3',{fontFamily:'header'});
	
	//Cufon.replace('#left-nav > ul > li > ul > li > a',{fontFamily:'a1hc'});
	//Cufon.replace('#right-col h3,#aralast-np-left-callout h3',{fontFamily:'a1hc'});
	//Cufon.replace('#quick-links h3',{fontFamily:'a1h'});
}
	
$(document).ready(init);
