function addBreadCrumb(){
	var bc = document.getElementById('bread-crumb');
	var settings = document.documentElement.lastChild.className;
	var crumb = settings.split(" ");
	//crumb.pop();
	crumb.shift();
	for(var k=0;k<crumb.length;k++){
		var li = document.createElement('li');
		var a = document.createElement('a');
		var node = Sizzle('#nav .'+crumb[k])[0];
		a.href = node.firstChild.href;
		a.appendChild(document.createTextNode(node.firstChild.firstChild.nodeValue));
		li.appendChild(a);
		if(k==crumb.length-1){li.className="last"};
		bc.appendChild(li);
	}
	Cufon.replace('#bread-crumb li a',{fontFamily:'a1hc'});
}

function findAnimations(){
	var animations = Sizzle('.animation-image, .big-animation-image');
	if(animations.length){
		var animationPopUpJS = document.createElement('script');
		animationPopUpJS.type = "text/javascript";
		animationPopUpJS.src = "/js/AnimationPopUp.js";
		document.documentElement.firstChild.appendChild(animationPopUpJS);
		
		if(!('Tween' in window)){
			var tweenJS = document.createElement('script');
			tweenJS.type = "text/javascript";
			tweenJS.src = "/js/Tween.js";
			document.documentElement.firstChild.appendChild(tweenJS);
		}
		for(var p=0;p<animations.length;p++){
			animations[p].onclick = function(){
				this.apu = new AnimationPopUp(this); 
				this.apu.display();
				return false;
			}
		}
			

	}
}

function findAKA(){
	if(!('Tween' in window)){
		var tweenJS = document.createElement('script');
		tweenJS.type = "text/javascript";
		tweenJS.src = "/js/Tween.js";
		document.documentElement.firstChild.appendChild(tweenJS);
	}
	var ast = Sizzle('a.ast');
	var aka = document.getElementById('aka');
	
	for(a in ast){
		ast[a].aka = aka;
		ast[a].onclick = function(){
			if(!this.aka.hTween){
				this.aka.hTween = new Tween(this.aka,"height",0,this.aka.scrollHeight,250,'','px',"easeSin",true);
				this.aka.mTween = new Tween(this.aka,"marginBottom",0,18,250,'','px',"easeSin",true);
			}
			this.aka.hTween.play();
			this.aka.mTween.play();
			return false;
		}
	}
}

function insertFlash(){
	var flash = {
		"dr-butler-movie":{swf:"/flash/drbutler.swf",w:400,h:440,v:8,c:true},
		"pbs-video":{swf:"/flash/hbhm.swf",w:422,h:425,v:8,c:true}
	}
	for(m in flash){
		if(document.getElementById(m)){
			flash[m].m = new Flash(document.getElementById(m),flash[m].swf,flash[m].w,flash[m].h,flash[m].v,flash[m].c);
			flash[m].m.insert();
		}
	}
}

function findLinks(){
	var a = document.getElementsByTagName('a');
	for(var k=0;k<a.length;k++){
		if(/external/.test(a[k].className)){
			a[k].href = '/external/external_site.html?url=' + a[k].href;
		} else if(/pdf/.test(a[k].className)){
			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.dcsuri',this.href,'WT.dl','20','WT.ti',"download: "+this.innerHTML,'WT.z_pdfdownload',this.pathname,'WT.z_pdfdownloadcount','1');
					window.open(this.href,"_blank");
					return false;
				}
			}
		} else if(/order-form|register-form/.test(a[k].className)){
			a[k].onclick = function(){window.open(this.href,'form','width=760,resizable=yes,scrollbars=yes');return false;}
		} else if(/elearning-start/.test(a[k].className)){
			a[k].onclick = function(){window.open(this.href, "case_study", "width=800,height=530,toolbar=no,status=no,scollbars=no,resizable=yes");return false;}
		}
	}
	
	var f = document.getElementsByName('s');
	for(var r=0;r<f.length;r++){
		f[r].onfocus = function(){
			if(this.value == "Search"){
				this.value = "";
			}
		}
		f[r].onblur = function(){
			if(this.value == ""){
				this.value = "Search";	
			}
		}
	}

}

function actions(){
	if('Cufon' in window){Cufon.now();}
	if(document.getElementById('gallery-image') && document.getElementById('gallery-list') && 'AlphaOneGallery' in window){
		var list = ["/images/home/home1.jpg","/images/home/home2.jpg","/images/home/home3.jpg"];
		var alts = ["Wayne Vicknair, ARALAST NP augmentation therapy Patient","Loyde Mattern, ARALAST NP augmentation therapy Patient","Melodie Beck, ARALAST NP augmentation therapy Patient"];
		var a1g = new AlphaOneGallery(document.getElementById('gallery-image'),document.getElementById('gallery-list'),list,alts);
	}
	if(document.getElementById('news-ticker') && 'NewsTicker' in window){
		var nt = new NewsTicker(document.getElementById('news-ticker'));
	}
	if(document.getElementById('bread-crumb') && 'Sizzle' in window){
		addBreadCrumb();	
	}
	if(document.getElementById('glossary') && 'Glossary' in window){
		var g = new Glossary(document.getElementById('glossary-nav'),document.getElementById('glossary'));	
	}
	findAnimations();
	findAKA();
	findLinks();
	
	if('Tour' in window){
		var items = ['it-could-be-alpha-1','whats-the-difference','am-i-at-risk','find-out-for-sure'];
		var AATTour = new Tour(items,document.getElementById('tour-content'),document.getElementById('tour-top')/*,document.getElementById('tour-controller')*/);
	}
	
	if('Flash' in window){insertFlash();}
	if('SymptomChecker' in window && document.getElementById('checker')){var sc = new SymptomChecker(document.getElementById('checker'));}
	if('SymptomResults' in window && document.getElementById('symptom-checker-results')){var sr = new SymptomResults(document.location.search);}
}

function init(){
	if(arguments.callee.doOnce){return;}
	arguments.callee.doOnce=true;
	actions();
}
if(document.addEventListener){document.addEventListener("DOMContentLoaded",init,null);}
window.onload=init;


if('Cufon' in window){
	Cufon.replace('h1',{fontFamily:'a1h'});
	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'});
	Cufon.replace('#tour-nav ul li a',{fontFamily:'a1hc'});
	Cufon.replace('#tour .tour-controller a',{fontFamily:'a1hc'});
	Cufon.replace('#press-release h1',{fontFamily:'a1h-bold'});
}