// ALZ namespace
var ALZ = {};


/* Omniture tracking passthrough class
------------------------------------------------------*/
ALZ.TrackerClass = function() {
	this.init = function() {
		this.initFooterLinks();
		this.initRightModuleLinks();
	};
	
	// track footer logo links
	this.initFooterLinks = function() {
		$("#footer .logos a").each(function(i, item) {
			switch(i) {
				case 0:
					$(this).bind("click", {"linktype":"Docs"}, ALZ.tracker.trackFooterLink);
					break;
				case 1:
					$(this).bind("click", {"linktype":"NIA"}, ALZ.tracker.trackFooterLink);
					break;
				case 2:
					$(this).bind("click", {"linktype":"Alzheimers"}, ALZ.tracker.trackFooterLink);
					break;
				case 3:
					$(this).bind("click", {"linktype":"Fidelity"}, ALZ.tracker.trackFooterLink);
					break;
				case 4:
					$(this).bind("click", {"linktype":"Beene"}, ALZ.tracker.trackFooterLink);
					break;
				default:
					break;
			}
		});
	};
	
	this.trackFooterLink = function(evt) {
		ALZ.tracker.send("Exit: " + evt.data.linktype);
	};
	
	// track right module links
	this.initRightModuleLinks = function() {


		$("#right .watchmore a").each(function() {
	
var destination = $(this).attr("href");
var exitdomain = destination.replace("http://", "").replace("www.","").split("/")[0]; 
			if ($(this).hasClass("sitelink")) {
				$(this).bind("click", {"module":"Watch More", "linktype":"Site Link","nexturl":exitdomain}, ALZ.tracker.trackLink);
			} else if ($(this).hasClass("exitlink")) {
				$(this).bind("click", {"module":"Watch More", "linktype":"Exit Link","nexturl":exitdomain}, ALZ.tracker.trackLink);
			} else if ($(this).hasClass("storelink")) {
				$(this).bind("click", {"module":"Watch More", "linktype":"Store Link","nexturl":exitdomain}, ALZ.tracker.trackLink);
			}
		});
		$("#right .learnmore a").each(function() {
var destination = $(this).attr("href");
var exitdomain = destination.replace("http://", "").replace("www.","").split("/")[0]; 
			if ($(this).hasClass("sitelink")) {
				$(this).bind("click", {"module":"Learn More", "linktype":"Site Link","nexturl":exitdomain}, ALZ.tracker.trackLink);
			} else if ($(this).hasClass("exitlink")) {
				$(this).bind("click", {"module":"Learn More", "linktype":"Exit Link","nexturl":exitdomain}, ALZ.tracker.trackLink);
			} else if ($(this).hasClass("storelink")) {
				$(this).bind("click", {"module":"Learn More", "linktype":"Store Link","nexturl":exitdomain}, ALZ.tracker.trackLink);
			}
		});
		$("#right .domore a").each(function() {
var destination = $(this).attr("href");
var exitdomain = destination.replace("http://", "").replace("www.","").split("/")[0]; 		
			if ($(this).hasClass("sitelink")) {
				$(this).bind("click", {"module":"Do More", "linktype":"Site Link","nexturl":exitdomain}, ALZ.tracker.trackLink);
			} else if ($(this).hasClass("exitlink")) {
				$(this).bind("click", {"module":"Do More", "linktype":"Exit Link","nexturl":exitdomain}, ALZ.tracker.trackLink);
			} else if ($(this).hasClass("storelink")) {
				$(this).bind("click", {"module":"Do More", "linktype":"Store Link","nexturl":exitdomain}, ALZ.tracker.trackLink);
			}
		});
	};
	
	this.trackLink = function(evt) {
		ALZ.tracker.send("Module: " + evt.data.module + ": " + evt.data.linktype +": " + evt.data.nexturl);
	};
	
	this.send = function(str) {
		//alert(str);
		if (typeof specialProp == 'function')
			specialProp(str);
	};
};
ALZ.tracker = new ALZ.TrackerClass();





/* Global nav and subnav functionality
------------------------------------------------------*/
ALZ.NavClass = function() {
	this.subnav;
	this.current = 0;
	this.timeout = 123;
	
	this.init = function() {
		this.subnav = $('#subnav div.sub');

		var navitems = $('#nav ul li');
		for (var i=0; i < navitems.length; i++) {
			if ($(navitems[i]).hasClass("active-nav"))
				this.current = i;
		}

		var navitems = $('#nav ul li a');
		for (var i=0; i < navitems.length; i++) {
			$(navitems[i]).bind("mouseover", {id:i, subnav:this.subnav}, this.highlight);
			$(navitems[i]).bind("mouseout", {subnav:this.subnav, curr:this.current}, this.unhighlight);
		}
		
		// mouse handling for subnav
		$("#subnav").bind("mouseover", this.subnavOver);
		$("#subnav").bind("mouseout", this.unhighlight);
		
		// trigger the first subnav
		$(navitems[this.current]).trigger("mouseover", {id:this.current, subnav:this.subnav});
		
		// display the subnav
		$('#subnav ol').show();
	};
	
	this.subnavOver = function() {
		clearTimeout(ALZ.nav.timeout);
	};
	
	this.highlight = function(evt) {
		clearTimeout(ALZ.nav.timeout);
		for (var i=0; i < evt.data.subnav.length; i++) {
			if (i == evt.data.id)
				$(evt.data.subnav[i]).show();
			else
				$(evt.data.subnav[i]).hide();
		}
	};

	this.unhighlight = function(evt) {
		clearTimeout(ALZ.nav.timeout);
		ALZ.nav.timeout = setTimeout(ALZ.nav.resetHighlight, 100);
	};

	this.resetHighlight = function() {
		for (var i=0; i < ALZ.nav.subnav.length; i++) {
			if (i == ALZ.nav.current)
				$(ALZ.nav.subnav[i]).show();
			else
				$(ALZ.nav.subnav[i]).hide();
		}
	};
};
ALZ.nav = new ALZ.NavClass();



/* Commenting system
------------------------------------------------------*/
ALZ.CommentsClass = function() {
	this.thread;
	this.page;
	this.totalPages;
	this.commentingState;
//	this.service = "http://172.27.0.194:8888/";
//	this.service = "http://alzheimers.behaviordesign.com/json.php";
	this.service = "http://hbotapadmin.com/";
	
	// error messages, used for both client and server side error handling
	this.errorMsgs = {
		"SERVER_ERROR":"A server error occured. Please try again later.",
		"THREAD_MISSING":"The thread is invalid.",
		"NAME_MISSING":"Please enter your name.",
		"NAME_TOO_LONG":"Your name is too long. Please make it shorter.",
		"EMAIL_INVALID":"Please enter a valid email address.",
		"EMAIL_TOO_LONG":"Your email is too long. Please make it shorter.",
		"COMMENT_MISSING":"Please enter your comment.",
		"COMMENT_TOO_LONG":"Your comment is too long. Please make it shorter.",
		"DOC_OPTIN_NO_EMAIL":"To opt-in to the HBO Documentaries, please provide a valid email address.",
		"AGREE_TERMS_MISSING":"You must agree to the terms and conditions in order to post your comment.",
		"IP_BANNED":"Comments from your IP address have been banned.",
		"COMMENTS_LOCKED":"Commenting is currently locked. New comments cannot be added.",
		"COMMENTS_CLOSED":"Commenting is currently closed. New comments cannot be added.",
		"NOT_ENOUGH_CHOCOLATE_CHIPS":"This cookie looked really good. However, when I bit into it; it was way too salty and didn't have enough chocolate chips."
	};
	
	this.showForm = function() {
		ALZ.tracker.send("Comments: Add");
		$('#addCommentForm').slideDown("normal", function() {
			self.scrollTo(0, parseInt($("#addCommentForm").offset().top));
		});
	};
	
	this.getComments = function(params) {
		this.thread = params.thread;
		
		$.getJSON(ALZ.comments.service + "?action=get&thread=" + params.thread + "&page=" + params.page + "&callback=?",
			function(data){
				// get the commenting system state (0=open, 1=locked, 2=closed)
				if (data.current_state != undefined)
					ALZ.comments.commentingState = data.current_state;
				else
					ALZ.comments.commentingState = 0;
					
				// check if comments are completely closed
				if (ALZ.comments.commentingState >= 2) {
					$("#comments .loading").text("Comments are currently disabled.");
					return;
				}
				
				// clear the old comments
				$("#comments ul").empty();
				
				// if the comments result is empty, show message
				if (data.comments.length <= 0) {
					$('<li class="loading">There are no comments yet.</li>').appendTo("#comments ul");
				} else {
					// add each comment to the list
					$.each(data.comments, function(i,item){
						var comment = item.comment.replace(/\n/g, "<br/>");
						var entry = '<li><span class="meta"><p class="name">' + item.name + '</p><p class="date">' + item.time + '</p></span><span class="comment"><p>' + comment + '</p><p class="flag" id="flag' + item.id + '">';
						if (ALZ.comments.commentingState == 0)
							entry += '<a href="javascript:ALZ.flagComment(' + item.id + ')" title="Click to flag this comment as inappropriate.">Flag as inappropriate</a></p></span>';
						entry += '</li>';
						if (params.first && i >= 3)
							$(entry).appendTo("#comments ul").fadeOut(0);
						else
							$(entry).appendTo("#comments ul").fadeOut(0).fadeIn();
					});
				}
				
				// show buttons
				$("#comments .buttons").fadeIn();
				
				// if 3 or less comments, hide see all comments button
				if (data.comments.length <= 3) {
					$("#comments .buttons .showallcomments").hide();
				}
				
				// if comments locked, don't show add button
				if (ALZ.comments.commentingState == 1) {
					$("#comments .buttons .showcommentform").hide();
					$("#comments .buttons .showallcomments").css("margin-left", "377px");
				}
				
				// update pagination
				ALZ.comments.updatePagination(data.page, data.totalPages);
				if (!params.first)
					ALZ.comments.showPagination();
			}
		);
	};
	
	this.showAll = function() {
		ALZ.tracker.send("Comments: See All");
		$("#comments li").fadeIn();
		ALZ.comments.showPagination();
		$("#comments .buttons .showallcomments").hide();
	};
	
	this.updatePagination = function(page, total) {
		this.page = page;
		this.totalPages = total;
	};
	
	this.showPagination = function() {
		var buf = '';
		$("#comments .pagination").empty();
		if (this.totalPages > 1) {
			if (this.page == 1)
				buf += '<span>Previous</span>';
			else
				buf += '<span><a href="javascript:ALZ.getComments({thread:' + this.thread + ', page:' + (parseInt(this.page)-1) + '})">Previous</a></span>';
			for (var i=1; i <= this.totalPages; i++) {
				buf += (i == this.page) ? '<span class="current">' : '<span>'; 
				buf += '<a href="javascript:ALZ.getComments({thread:' + this.thread + ', page:' + i + '})">' + i + '</a></span>';
			}
			if (this.page == this.totalPages)
				buf += '<span>Next</span>';
			else
				buf += '<span><a href="javascript:ALZ.getComments({thread:' + this.thread + ', page:' + (parseInt(this.page)+1) + '})">Next</a></span>';
			$(buf).appendTo("#comments .pagination");
		}
	};

	// comment is flagged as inappropriate; notify service and replace link with text
	this.flagComment = function(id) {
		$.getJSON(ALZ.comments.service + "?action=flag&id=" + id + "&callback=?",
			function(data){
				// if id is positive, update flag link
				if (data.id > 0) {
					if ($("#flag" + data.id))
						$("#flag" + data.id).html("Flagged as inappropriate");
				}
			}
		);
	};
	
	this.resetForm = function() {
		$("#addCommentForm").each(function() {
			this.reset();
		});
	};

	// post the comment form but validate first
	this.postComment = function() {
		if (ALZ.comments.validate()) {
			ALZ.tracker.send("Comments: Post");

			n = encodeURIComponent($("#addCommentForm #name").attr("value"));
			em = encodeURIComponent($("#addCommentForm #email").attr("value"));
			c = encodeURIComponent($("#addCommentForm #message").attr("value"));
			o = encodeURIComponent($("#addCommentForm #documentaries_optin").attr("checked"));
			
			// hide submit button and show sending text
			$("#addCommentForm .submit").hide();
			$("#addCommentForm .sending").show();

			$.getJSON(ALZ.comments.service + "?action=post&thread=" + ALZ.comments.thread + "&name=" + n + "&email=" + em + "&comment=" + c + "&documentaries_optin=" + o + "&callback=?",
				function(data){
					// show submit button and hide sending text
					$("#addCommentForm .sending").hide();
					$("#addCommentForm .submit").show();

					// if id is positive, add new comment to top of list
					if (data.id > 0) {
						var item = data;
						var entry = $('<li><span class="meta"><p class="name">' + item.name + '</p><p class="date">' + item.time + '</p></span><span class="comment"><p>' + item.comment + '</p><p class="flag" id="flag' + item.id + '"><a href="javascript:ALZ.flagComment(' + item.id + ')" title="Click to flag this comment as inappropriate.">Flag as inappropriate</a></p></span></li>');
						entry.prependTo("#comments ul").fadeOut(0).fadeIn();
						self.scrollTo(0, parseInt($("#comments").offset().top));

						// reset and hide the form
						ALZ.comments.resetForm();
						$("#addCommentForm").hide();
					} else {
						// if errors, display them
						if (data.errors.length > 0) {
							ALZ.comments.showErrors(data.errors);
						}
					}
				}
			);
		}
	};
	
	this.validate = function() {
		var errors = [];
		
		// name must be non blank
		var name = $("#addCommentForm #name").attr("value");
		if (name == '')
			errors.push("NAME_MISSING");

		// email not required, but if filled in must be simply valid
		var email = $("#addCommentForm #email").attr("value");
		if (email != '') {
			var re = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
			if (!re.test(email))
				errors.push("EMAIL_INVALID");
		}
		
		// comment must be non blank
		var message = $("#addCommentForm #message").attr("value");
		if (message == '')
			errors.push("COMMENT_MISSING");
			
		// optin for hbo documentaries requires email
		var optin = $("#addCommentForm #documentaries_optin").attr("checked");
		if (optin && email == '') {	
			errors.push("DOC_OPTIN_NO_EMAIL");
		}
		
		// agree to terms of use checkbox
		var terms = $("#addCommentForm #agree_terms").attr("checked");
		if (!terms) {
			errors.push("AGREE_TERMS_MISSING");
		}		

		// clear errors
		$("#addCommentForm .error").fadeOut(0);

		// check if errors exist
		if (errors.length > 0) {
			this.showErrors(errors);
			return false;
		}
		
		return true;
	};
	
	this.showErrors = function(errorArray) {
		var buf = '';
		for (var i=0; i < errorArray.length; i++) {
			buf += '<p>' + this.errorMsgs[errorArray[i]] + '</p>';
		}
		$("#addCommentForm .error").html(buf).fadeIn();
	};
};
ALZ.comments = new ALZ.CommentsClass();
ALZ.showCommentForm = ALZ.comments.showForm;
ALZ.showAllComments = ALZ.comments.showAll;
ALZ.getComments = ALZ.comments.getComments;
ALZ.flagComment = ALZ.comments.flagComment;
ALZ.postComment = ALZ.comments.postComment;



/* Inline image slideshow module
------------------------------------------------------*/
ALZ.SlideshowClass = function() {
	this.slides = [];
	this.arrowleft;
	this.arrowright;
	this.current = 0;
	this.total;
	
	this.init = function(ss) {
		li = $(ss).find('li');
		
		this.total = li.length;
		if (this.total <= 1)
			return;
			
		for (var i=0; i < li.length; i++) {
			this.slides.push($(li[i]));
			if (i != 0) {
				$(this.slides[i].find("img")[0]).css("left", "-500px");
				$(this.slides[i].find("p")[0]).hide();
			} else {
				$(this.slides[i].find("img")[0]).css("left", "3px");
				$(this.slides[i].find("img")[0]).show();
				$(this.slides[i].find("p")[0]).show();
			}
		}
		
		this.arrowleft = $(ss).find('.arrowleft');
		this.arrowright = $(ss).find('.arrowright');
		
		this.arrowleft.bind("click", {ref:this}, this.prevSlide);
		this.arrowright.bind("click", {ref:this}, this.nextSlide);
	};
	
	this.nextSlide = function(evt) {
		var ref = evt.data.ref;
		var img;
		var p;
		
		img = ref.slides[ref.current].find("img");
    $(img[0]).animate({left:"-360px"}, 500);
		p = ref.slides[ref.current].find("p");
    $(p[0]).fadeOut();
    
    ref.current = ref.getNextSlide();

		img = ref.slides[ref.current].find("img");
    $(img[0]).css("left", "366px").animate({left:"3px"}, 500);
		p = ref.slides[ref.current].find("p");
    $(p[0]).fadeIn();
	};

	this.prevSlide = function(evt) {
		var ref = evt.data.ref;
		var img;
		var p;
		
		img = ref.slides[ref.current].find("img");
    $(img[0]).animate({left:"366px"}, 500);
		p = ref.slides[ref.current].find("p");
    $(p[0]).fadeOut();
    
    ref.current = ref.getPrevSlide();

		img = ref.slides[ref.current].find("img");
    $(img[0]).css("left", "-360px").animate({left:"3px"}, 500);
		p = ref.slides[ref.current].find("p");
    $(p[0]).fadeIn();
	};
	
	this.getNextSlide = function() {
		if (this.current >= this.total - 1)
			return 0;
		else
			return (this.current + 1);
	};

	this.getPrevSlide = function() {
		if (this.current <= 0)
			return (this.total - 1);
		else
			return (this.current - 1);
	};
};
ALZ.slideshows = [];



/* Show/hide supplementary videos module
------------------------------------------------------*/
ALZ.SupplementaryModuleClass = function() {
	this.more;
	
	this.init = function() {
		this.more = $("#right .supplementary ul.more");
		$("#right .supplementary p.more").bind("click", {more:this.more}, this.toggleMore);
	};
	
	this.toggleMore = function(evt) {
		evt.data.more.slideToggle();
		return false;
	};
};



/* Font sizer tool
------------------------------------------------------*/
ALZ.FontSizerClass = function() {
	this.size = 0;
	this.sizable = [
		{"element":"#content #left p", "small":"1.2em", "large":"1.4em"},
		{"element":"#content #left #comments ul li span.meta p.name", "small":"1em", "large":"1.2em"},
		{"element":"#content #left #comments ul li span.meta p.date", "small":"1em", "large":"1.2em"},
		{"element":"#content #left #comments ul li span.comment p.flag", "small":".9em", "large":"1em"},
		{"element":"#content .collaboratorsmain h1", "small":"1.8em", "large":"2.2em"},
		{"element":"#content .collaboratorsmain h2", "small":"1.2em", "large":"1.4em"},
		{"element":"#content .collaboratorsmain h3", "small":"1.2em", "large":"1.4em"},
		{"element":"#content .collaboratorsmain dl h4", "small":"1.2em", "large":"1.4em"},
		{"element":"#content .collaboratorsmain dl p", "small":"1.2em", "large":"1.4em"},
		{"element":"#content .collaboratorsmain dl p.person", "small":"1em", "large":"1.2em"},
		{"element":"#content .gethelp-1 h4","small":"1.2em", "large":"1.4em"},
		{"element":"#content .gethelp-2 h4","small":"1.2em", "large":"1.4em"},
		{"element":"#content .gethelp-1 p","small":"1.2em", "large":"1.4em"},
		{"element":"#content .gethelp-2 p","small":"1.2em", "large":"1.4em"},
		{"element":"#content .gethelpmain h3","small":"1.8em", "large":"2.2em"},
		{"element":"#content .gethelpmain h4","small":"1.2em", "large":"1.4em"},
		{"element":"#content .gethelpmain p","small":"1.2em", "large":"1.4em"},
		{"element":"#content .impact-1 h1","small":"1.8em", "large":"2.2em"},
		{"element":"#content .impact-1 h2","small":"1.4em", "large":"1.6em"},
		{"element":"#content .impact-2 h3","small":"1.4em", "large":"1.6em"},
		{"element":"#content .impact-2 h4","small":"1.2em", "large":"1.4em"},
		{"element":"#content .impact-1 p","small":"1.2em", "large":"1.4em"},
		{"element":"#content .impact-2 p","small":"1.2em", "large":"1.4em"},
		{"element":"#content .screeningsmain p","small":"1.2em", "large":"1.4em"}

	];
	
	this.toggleSize = function() {
		if (this.size == 0) {
			this.size = 1;
		} else {
			this.size = 0;
		}
		this.updateSize();
		ALZ.tracker.send('Tool: Font');
	};
	
	this.updateSize = function() {
		if (this.size == 0) {
			// set small font sizes
			for (var i=0; i < this.sizable.length; i++) {
				$(this.sizable[i]["element"]).css("font-size", this.sizable[i]["small"]);
			}
			$("#tools .font a").css("background-position", "2px 4px");
		} else {
			// set large font sizes
			for (var i=0; i < this.sizable.length; i++) {
				$(this.sizable[i]["element"]).css("font-size", this.sizable[i]["large"]);
			}
			$("#tools .font a").css("background-position", "2px -17px");
		}
		this.saveSize();
	};
	
	this.saveSize = function() {
		// save a cookie with size
		$.cookie('ALZ.fontSize', this.size);
	};

	this.loadSize = function() {
		// load a cookie with size
		this.size = $.cookie('ALZ.fontSize');
		if (this.size != 0 && this.size != 1)
			this.size = 0;
		this.updateSize();
	};
};
ALZ.fontSizer = new ALZ.FontSizerClass();



/* Email tool
------------------------------------------------------*/
ALZ.EmailClass = function() {
	this.subject = escape("HBO's The Alzheimer's Project");
	this.body = escape("Take a look at this pioneering new documentary series about Alzheimer's:\n" + location.href + "\n\n");
	
	this.getMailTo = function() {
		var buf = "mailto:?subject=" + this.subject + "&body=" + this.body;
		return buf;
	};
};



/* Window popup
------------------------------------------------------*/
ALZ.winOpen = function(height, width, uri) {
	window.open(uri, "popup", "toolbar=no, location=no, resizable=yes, scrollbars=yes, status=no, height="+height+", width="+width);
}

// toggle the two momentum in science videos
ALZ.changeMomentumOrigVideo = function(id) {
	
if (id == 1) {

		$("#videoplayer").empty();
		$("#videoplayer").flash({
			src: "flash/VideoPlayer.swf",
			width: 600,
			height: 343,
			wmode: "opaque",
			allowFullScreen: true,
			allowScriptAccess: "always",
			flashvars: { xmlPath: 'flash/xml/definition.xml', id: '2' }}, { version: 9 });

		/*
		$("#videoplayer embed").attr("id", "momentum");
		document.getElementById("momentum").loadvideo(2);
		*/
		
		$($("#left p.video")[0]).show();
		$($("#left p.video")[1]).hide();

} else {

		$("#videoplayer").empty();
		$("#videoplayer").flash({
			src: "flash/VideoPlayer.swf",
			width: 600,
			height: 343,
			wmode: "opaque",
			allowFullScreen: true,
			allowScriptAccess: "always",
			flashvars: { xmlPath: 'flash/xml/definition.xml', id: '3' }}, { version: 9 });

		/*
		$("#videoplayer embed").attr("id", "momentum");
		document.getElementById("momentum").loadvideo(3);
		*/

		$($("#left p.video")[0]).hide();
		$($("#left p.video")[1]).show();

}


}




// toggle the two momentum in science videos
ALZ.changeMomentumVideo = function(id) {
	
if (id == 1) {
		// show part 1a; video id 2a
		$("#videoplayer").empty();
		$("#videoplayer").flash({
			src: "flash/VideoPlayer.swf",
			width: 600,
			height: 343,
			wmode: "opaque",
			allowFullScreen: true,
			allowScriptAccess: "always",
			flashvars: { xmlPath: 'flash/xml/definition.xml', id: '2a' }}, { version: 9 });

		/*
		$("#videoplayer embed").attr("id", "momentum");
		document.getElementById("momentum").loadvideo(2);
		*/
		
		$($("#left p.video")[0]).show();
		$($("#left p.video")[1]).hide();
		$($("#left p.video")[2]).hide();
		$($("#left p.video")[3]).hide();
}

if (id == 2) {
		// show part 1b; video id 2b
		$("#videoplayer").empty();
		$("#videoplayer").flash({
			src: "flash/VideoPlayer.swf",
			width: 600,
			height: 343,
			wmode: "opaque",
			allowFullScreen: true,
			allowScriptAccess: "always",
			flashvars: { xmlPath: 'flash/xml/definition.xml', id: '2b' }}, { version: 9 });

		/*
		$("#videoplayer embed").attr("id", "momentum");
		document.getElementById("momentum").loadvideo(3);
		*/

		$($("#left p.video")[0]).hide();
		$($("#left p.video")[1]).show();
		$($("#left p.video")[2]).hide();
		$($("#left p.video")[3]).hide();
}

if (id == 3) {
		// show part 2a; video id 3a
		$("#videoplayer").empty();
		$("#videoplayer").flash({
			src: "flash/VideoPlayer.swf",
			width: 600,
			height: 343,
			wmode: "opaque",
			allowFullScreen: true,
			allowScriptAccess: "always",
			flashvars: { xmlPath: 'flash/xml/definition.xml', id: '3a' }}, { version: 9 });

		/*
		$("#videoplayer embed").attr("id", "momentum");
		document.getElementById("momentum").loadvideo(3);
		*/

		$($("#left p.video")[0]).hide();
		$($("#left p.video")[1]).hide();
		$($("#left p.video")[2]).show();
		$($("#left p.video")[3]).hide();
}

if (id == 4) {
		// show part 2a; video id 3b
		$("#videoplayer").empty();
		$("#videoplayer").flash({
			src: "flash/VideoPlayer.swf",
			width: 600,
			height: 343,
			wmode: "opaque",
			allowFullScreen: true,
			allowScriptAccess: "always",
			flashvars: { xmlPath: 'flash/xml/definition.xml', id: '3b' }}, { version: 9 });

		/*
		$("#videoplayer embed").attr("id", "momentum");
		document.getElementById("momentum").loadvideo(3);
		*/

		$($("#left p.video")[0]).hide();
		$($("#left p.video")[1]).hide();
		$($("#left p.video")[2]).hide();
		$($("#left p.video")[3]).show();
}

}


// toggle the two caregivers videos
ALZ.changeCaregiversVideo = function(id) {
	if (id == 1) {
		// show part 1; video id 2
		$("#videoplayer").empty();
		$("#videoplayer").flash({
			src: "flash/VideoPlayer.swf",
			width: 600,
			height: 343,
			wmode: "opaque",
			allowFullScreen: true,
			allowScriptAccess: "always",
			flashvars: { xmlPath: 'flash/xml/definition.xml', id: '6a' }
		}, { version: 9 });

		/*
		$("#videoplayer embed").attr("id", "momentum");
		document.getElementById("momentum").loadvideo(2);
		*/
		
		$($("#left p.video")[0]).show();
		$($("#left p.video")[1]).hide();
	} else {
		// show part 2; video id 3
		$("#videoplayer").empty();
		$("#videoplayer").flash({
			src: "flash/VideoPlayer.swf",
			width: 600,
			height: 343,
			wmode: "opaque",
			allowFullScreen: true,
			allowScriptAccess: "always",
			flashvars: { xmlPath: 'flash/xml/definition.xml', id: '6b' }
		}, { version: 9 });

		/*
		$("#videoplayer embed").attr("id", "momentum");
		document.getElementById("momentum").loadvideo(3);
		*/

		$($("#left p.video")[0]).hide();
		$($("#left p.video")[1]).show();
	}
}


// toggle the two memory loss videos
ALZ.changeMemoryLossVideo = function(id) {
	if (id == 1) {
		// show part 1; video id 2
		$("#videoplayer").empty();
		$("#videoplayer").flash({
			src: "flash/VideoPlayer.swf",
			width: 600,
			height: 343,
			wmode: "opaque",
			allowFullScreen: true,
			allowScriptAccess: "always",
			flashvars: { xmlPath: 'flash/xml/definition.xml', id: '4a' }
		}, { version: 9 });

		/*
		$("#videoplayer embed").attr("id", "momentum");
		document.getElementById("momentum").loadvideo(2);
		*/
		
		$($("#left p.video")[0]).show();
		$($("#left p.video")[1]).hide();
	} else {
		// show part 2; video id 3
		$("#videoplayer").empty();
		$("#videoplayer").flash({
			src: "flash/VideoPlayer.swf",
			width: 600,
			height: 343,
			wmode: "opaque",
			allowFullScreen: true,
			allowScriptAccess: "always",
			flashvars: { xmlPath: 'flash/xml/definition.xml', id: '4b' }
		}, { version: 9 });

		/*
		$("#videoplayer embed").attr("id", "momentum");
		document.getElementById("momentum").loadvideo(3);
		*/

		$($("#left p.video")[0]).hide();
		$($("#left p.video")[1]).show();
	}
}


/* DOM ready
------------------------------------------------------*/
$(document).ready(function() {
	// global nav
	ALZ.nav.init();
	
	// get font size from cookie
	ALZ.fontSizer.loadSize();
	
	// slideshow
	var ss = $("div.slideshow");
	for (var i=0; i < ss.length; i++) {
		var ss_temp = new ALZ.SlideshowClass();
		ss_temp.init(ss[i]);
		ALZ.slideshows.push(ss_temp);
	}
	
	// supplementary module
	if ($("#right .supplementary")) {
		ALZ.supplementaryModule = new ALZ.SupplementaryModuleClass();
		ALZ.supplementaryModule.init();
	}
	
	// activate bookmarking
	if ($("#tools .bookmark a")) {
		$("#tools .bookmark a").jFav();
		$("#tools .bookmark a").bind("click", bookmarkClicked);
	};
	function bookmarkClicked(evt) {
		ALZ.tracker.send('Tool: Bookmark');
	}
	
	// activate email link
	if ($("#tools .email a")) {
		$("#tools .email a").attr("href", new ALZ.EmailClass().getMailTo());
		$("#tools .email a").bind("click", emailClicked);
	};
	function emailClicked(evt) {
		ALZ.tracker.send('Tool: Email');
	}
	
	// track share tool
	if ($("#tools .share a")) {
		$("#tools .share a").bind("click", shareClicked);
	};
	function shareClicked(evt) {
		ALZ.tracker.send('Tool: Share');
	}
	
	// track print tool
	if ($("#tools .print a")) {
		$("#tools .print a").bind("click", printClicked);
	};
	function printClicked(evt) {
		ALZ.tracker.send('Tool: Print');
	}
	
	// track footer links and right module links
	ALZ.tracker.init();
	
	// embed homepage flash if it exists
	if ($("#dynamiclead")) {
		$("#dynamiclead").flash({
				src: "flash/home.swf",
				width: 960,
				height: 450,
				allowFullScreen: true,
				flashvars: { xmlPath: 'flash/xml/home_definition.xml' }
			}, { version: 9 }, null, function(htmlOptions) {
				var url = String(location).split('?');
				url.splice(1,0,'?hasFlash=true&');
				url = url.join('');
				var msg = '<a href="http://www.adobe.com/go/getflashplayer"><img src="images/structure/noflash.jpg" /></a>';
				this.innerHTML = '<span class="alt">'+this.innerHTML+'</span>';
				jQuery(this)
					.addClass('flash-update')
					.prepend(msg);
			}
		);
	}
	
	// embed video player if it exists
	if ($("#videoplayer")) {
		// check rel for video id; default is 1 (trailer)
		var rel = $("#videoplayer").attr("rel");
		var videoID = 1;
		if (rel && rel.indexOf("video-") != -1) {
			videoID = rel.substr(6);
		}

		// embed the flash
		$("#videoplayer").flash({
			src: "flash/VideoPlayer.swf",
			width: 600,
			height: 343,
			wmode: "opaque",
			allowFullScreen: true,
			flashvars: { xmlPath: 'flash/xml/definition.xml', id: videoID }
		}, { version: 9 });
	}
	
	// embed glossary videos
	var gv = $(".glossaryVideo .video");
	if (gv.length > 0) {
		for (var i=0; i < gv.length; i++) {
			$(gv[i]).flash({
				src: "flash/VideoPlayer.swf",
				width: 600,
				height: 343,
				wmode: "opaque",
				allowFullScreen: true,
				flashvars: { xmlPath: 'flash/xml/definition.xml', id: $(gv[i]).attr('id').substr(6) }
			}, { version: 9 });
		}
	}
	
	// any link that goes outside the site spawns a new window
	var baseURL = "http://" + location.href.replace("http://", "").split("/")[0];
	$("a").each(function() {
		if (this.href.indexOf("javascript:") == -1) {
			if (this.href.indexOf(baseURL) == -1)
				$(this).click(function() { window.open(this); return false; });
		}
	});
	
// highlight current link of subnav menu



var pageURL = location.href.replace("http://", "").split("/")[2];


$("#right .module.science-nav ul li a").each(function() {
		if ($(this).attr('href') == pageURL) {
$(this).addClass("activeScienceNav");}
});

var protein = "#TB_inline?height=415&width=940&inlineId=protein";
var stroke = "#TB_inline?height=415&width=940&inlineId=stroke";
var susceptibilitygenes = "#TB_inline?height=415&width=940&inlineId=susceptibilityGene";

var pib = "#TB_inline?height=415&width=940&inlineId=pittsburghCompoundB";

$('a.thickbox').each(function() {

if ($(this).attr('href') == protein) {
$(this).replaceWith("protein");	
}

if ($(this).attr('href') == stroke) {
$(this).replaceWith("stroke");	
}

if ($(this).attr('href') == susceptibilitygenes) {
$(this).replaceWith("susceptibility genes");	
}

if ($(this).attr('href') == pib) {
$(this).replaceWith("Pittsburgh Compound B (PiB) ");	
}



});

$("a[href='http://store.hbo.com/entry.point?entry=3558258&source=HBO_AD:3558258:42809_alzheimersdvdandbook_alzheimerssitead']").attr('href', 'http://store.hbo.com/index.php?v=100615&ecid=PRF-TV2-800220&PA=PRF-TV2-800220');


$("a[href='http://store.hbo.com/entry.point?entry=3542743&cp=3558258&source=HBO_AD:3542743:409_alzheimersbook_alzheimerstextlink']").attr('href', 'http://store.hbo.com/index.php?v=100175&ecid=PRF-TV2-800222&PA=PRF-TV2-800222');

$("a[href='http://store.hbo.com/entry.point?entry=3473174&cp=3558258&source=HBO_AD:3473174:409_alzheimersdvd_alzheimerstextlink']").attr('href', 'http://store.hbo.com/index.php?v=100615&ecid=PRF-TV2-800221&PA=PRF-TV2-800221');




$("a[href='http://www.nia.nih.gov/']").attr('href', 'http://www.nia.nih.gov/alzheimers');


$("a[href='http://www.nia.nih.gov/Alzheimers/ResearchInformation/ClinicalTrials/']").attr('href', 'http://www.nia.nih.gov/Alzheimers/ResearchInformation/participateADresearch.htm');
	
	
	
	// load comments
	if ($("#comments") && $("#comments").attr("class")) {
		if ($("#comments").attr("class").substr(0, 7) == "thread-") {
			var thread = $("#comments").attr("class").substr(7);
			ALZ.comments.getComments({"thread":thread, "page":"1", "first":"true"});
		}
	}
});



