var isIE = 0//@cc_on || 1;
try { top.location.href; } catch(e) { top.location.href = window.location.href; } 
try { 
	var TopLocationTester = top.location.href;
} catch(e) {
	top.location.href = window.location.href;
} 

try {document.execCommand("backgroundimagecache", false, true)} catch (e) {}

var toggle = function(obj) {
	if (Element.hasClassName(obj,"expanded")){
		Element.removeClassName(obj,"expanded");
		Element.addClassName(obj,"collapsed");
	} else if (Element.hasClassName(obj,"collapsed")){
		Element.removeClassName(obj,"collapsed");
		Element.addClassName(obj,"expanded");	
	}
}

var flashinstalled = jaaulde.utils.flashsniffer.installed();
var CAROUSELDELAY = 5000;
var CurrentCarouselArticleTopicID = null;
var ShowCarouselImage = function (ArticleTopicID) {
	for (var i=0; i<CarouselArticleTopics.length; i++) {
		Element.removeClassName("CarouselLink_" + CarouselArticleTopics[i].ArticleTopicID, "hover");
	}
	Element.addClassName("CarouselLink_" + ArticleTopicID, "hover");
	
	if ($("CarouselImage_" + CurrentCarouselArticleTopicID)) {
		$("CarouselImage_" + CurrentCarouselArticleTopicID).fade({
			afterFinish : function() {
				$("CarouselImage_" + CurrentCarouselArticleTopicID).style.display = "";
				$("CarouselImage_" + CurrentCarouselArticleTopicID).style.zIndex = 1;
			}
		});
		$("CarouselImage_" + CurrentCarouselArticleTopicID).style.zIndex = 2;
	}
	if ($("CarouselImage_" + ArticleTopicID)) {
		$("CarouselImage_" + ArticleTopicID).style.display = "";
		$("CarouselImage_" + ArticleTopicID).style.zIndex = 1;
	}
	CurrentCarouselArticleTopicID = ArticleTopicID;
}
var CarouselGoToArticle = function (source) {
	for (var i=0; i<CarouselArticleTopics.length; i++) {
		if (CarouselArticleTopics[i].ArticleTopicID == CurrentCarouselArticleTopicID) {
			pageTracker._trackEvent(source,$("CarouselTopic_"+CurrentCarouselArticleTopicID).value,$("CarouselTitle_"+CurrentCarouselArticleTopicID).value);
			location.href = siteroot + language + "/article/index/" + CarouselArticleTopics[i].ArticleShortName;
			if(window.event) window.event.returnValue=false;
			break;
		}
	}
	return false;
}

var fontSizeCurrent = 3;
var fontSize = {minimum:1, maximum: 5};
Event.observe(window, "load" ,function() {
	var smallfontbuttons, largefontbuttons = false;
	var animationLock = false;
	var CarouselAnimationID = 0;
	var inSectionTooltip = false;
	var sectionTooltipTimeout = 0;
	Behaviour.register({
		".expander a.sharea" : function(title) {
			title.onclick = function(){toggle(title.parentNode.parentNode)};//attach it only once!
		},
		".expander a.referenceslink" : function(title) {
			title.onclick = function(){toggle(title.parentNode)};//attach it only once!
			if (location.hash == "#references") toggle(title.parentNode)
		},
		".smallerfont" : function(button) {
			if (smallfontbuttons) return;
			smallfontbuttons = true;
			Event.observe(button, "click", function() {
				if (typeof(pageTracker) != "undefined") pageTracker._trackPageview("/articleevent/DecreaseTextSize");
				if (fontSizeCurrent > fontSize.minimum) {
					fontSizeCurrent--;
					for (var i = fontSize.minimum; i <= fontSize.maximum; i++) {
						Element.removeClassName(document.body, "size" + i);
					}
					Element.addClassName(document.body, "size" + fontSizeCurrent);
					var other = $$(".biggerfont");
					for (var element, i = 0; element = other[i]; i++) {
						element.style.display = "";
					}
					var other2 = $$(".biggerfontdisabled");
					for (var element, i = 0; element = other2[i]; i++) {
						element.style.display = "none";
					}
				}
				if (fontSizeCurrent <= fontSize.minimum) {
					var other = $$(".smallerfont");
					for (var element, i = 0; element = other[i]; i++) {
						element.style.display = "none";
					}
					var other2 = $$(".smallerfontdisabled");
					for (var element, i = 0; element = other2[i]; i++) {
						element.style.display = "";
					}
				}
			}.bind(button));
		},
		".biggerfont" : function(button) {
			if (largefontbuttons) return;
			largefontbuttons = true;
			Event.observe(button, "click", function() {
				if (typeof(pageTracker) != "undefined") pageTracker._trackPageview("/articleevent/IncreaseTextSize");
				if (fontSizeCurrent < fontSize.maximum) {
					fontSizeCurrent++;
					for (var i = fontSize.minimum; i <= fontSize.maximum; i++) {
						Element.removeClassName(document.body, "size" + i);
					}
					Element.addClassName(document.body, "size" + fontSizeCurrent);
					var other = $$(".smallerfont");
					for (var element, i = 0; element = other[i]; i++) {
						element.style.display = "";
					}
					var other2 = $$(".smallerfontdisabled");
					for (var element, i = 0; element = other2[i]; i++) {
						element.style.display = "none";
					}
				}
				if (fontSizeCurrent >= fontSize.maximum) {
					var other = $$(".biggerfont");
					for (var element, i = 0; element = other[i]; i++) {
						element.style.display = "none";
					}
					var other2 = $$(".biggerfontdisabled");
					for (var element, i = 0; element = other2[i]; i++) {
						element.style.display = "";
					}
				}
			}.bind(button));
		},
		".savetoclipboard" : function(link) {
			var count = $("clipboardcount");
			var message = link.title;
			link.title ="";
			if (count) {
				Event.observe(link, "click", function() {
					if (message) this.innerHTML = message;
					count.innerHTML = parseInt(count.innerHTML) + 1;
					Element.addClassName(this, "saved");
					Element.cleanWhitespace(this.parentNode.parentNode);
					Element.cleanWhitespace(this.parentNode.nextSibling);
					Element.removeClassName(this.parentNode.nextSibling.firstChild, "hidden");
				}.bind(link));
			}
		},
		"a.tooltip" : function(link) {
			var offset;
			if (Element.hasClassName(link, "articlelink")) offset = {left : -20, top : 100};
			else if (Element.up($(link), ".articleoption")) offset = {left : -370, top : 0}
			else offset = {left : -100, top : 20};
			if (link.rel) {
				var tooltip = document.getElementById("contextualdescription");
				var target = $(link.rel);
				if (tooltip && target) {
					Event.observe(link, "mouseover", function() {
						var position = Position.cumulativeOffset(this);
						tooltip.innerHTML = target.innerHTML;
						tooltip.style.top = position[1] + offset.top + "px";
						tooltip.style.left = position[0] + offset.left + "px";
						Element.removeClassName(tooltip, "hidden");
						//this.title = "";
					}.bind(link));
					Event.observe(link, "mouseleave" in link.attributes ? "mouseleave" : "mouseout", function() {
						Element.addClassName(tooltip, "hidden");
						//this.title = tooltip.innerHTML;
					}.bind(link));
				}
			}
		},
		"area.tooltip" : function(link) {
			var offset;
			offset = {left : -25, top : 25};
			if (link.target) {
				var tooltip = document.getElementById("contextualdescription");
				var target = $(link.target);
				link.target = "_self";
				if (tooltip && target) {
					Event.observe(link, "mouseover", function() {
						var position = Position.cumulativeOffset($("mapper"));//bla
						var coords = link.coords.split(",");
						tooltip.innerHTML = target.innerHTML;						
						tooltip.style.top = (position[1] + parseInt(coords[1]) + offset.top) + "px";
						tooltip.style.left = (position[0] + parseInt(coords[0]) + offset.left) + "px";
						
						Element.removeClassName(tooltip, "hidden");
						//this.title = "";
					}.bind(link));
					Event.observe(link, "mouseleave" in link.attributes ? "mouseleave" : "mouseout", function() {
						Element.addClassName(tooltip, "hidden");
						//this.title = tooltip.innerHTML;
					}.bind(link));
				}
			}
		},
		"div.left a[name]" : function(link) {
			var tooltip = document.getElementById("sectioninfotooltip");
			if (isIE) {
				var tooltipmask = document.getElementById("sectioninfotooltipmask");
				tooltipmask.innerHTML = "<iframe border='0' src='about:blank'></iframe>"
				tooltipmask.style.position = "absolute"
			}
			Event.observe(link, "mouseover", function() {
				var position = Position.cumulativeOffset(link);
				tooltip.innerHTML = link.name;						
				tooltip.style.top = position[1] + "px";
				tooltip.style.left = position[0] + 220 + "px";
				Element.removeClassName(tooltip, "hidden");
				
				if (isIE) {
					Element.removeClassName(tooltipmask, "hidden");
					tooltipmask.style.top = tooltip.style.top;
					tooltipmask.style.left = tooltip.style.left;
					tooltipmask.firstChild.style.width = tooltip.offsetWidth + "px";
					tooltipmask.firstChild.style.height = tooltip.offsetHeight + "px";
				}
				
				clearTimeout(sectionTooltipTimeout);
			})
			Event.observe(link, "mouseleave" in link.attributes ? "mouseleave" : "mouseout", function() {
				sectionTooltipTimeout = setTimeout(function() {
					if (!inSectionTooltip) Element.addClassName(tooltip, "hidden");
					if ($("sectioninfotooltipmask")) Element.addClassName($("sectioninfotooltipmask"), "hidden");
				}, 10);
			});
		},
		"#sectioninfotooltip" : function(tooltip) {
			Event.observe(tooltip, "mouseover", function() {
				inSectionTooltip = true;
			})
			Event.observe(tooltip, "mouseleave" in tooltip.attributes ? "mouseleave" : "mouseout", function() {
				inSectionTooltip = false;
				Element.addClassName(tooltip, "hidden");
				if ($("sectioninfotooltipmask")) Element.addClassName($("sectioninfotooltipmask"), "hidden");
			})
		},
		"#carouselpanel" : function(carousel) {
			ShowCarouselImage(CarouselArticleTopics[0].ArticleTopicID);
			CarouselAnimationID = setInterval(function () {
				for (var i=0; i<CarouselArticleTopics.length; i++) {
					if (CarouselArticleTopics[i].ArticleTopicID == CurrentCarouselArticleTopicID) {
						if (i == CarouselArticleTopics.length-1) ShowCarouselImage(CarouselArticleTopics[0].ArticleTopicID);
						else ShowCarouselImage(CarouselArticleTopics[i+1].ArticleTopicID);
						break;
					}
				}
			}, CAROUSELDELAY);
		},
		"#carousel a" : function(link) {
			$(link).observe("click", function() {
				var ATID = String($(link).id);
				var CurrentID = ATID.substr(ATID.indexOf("_")+1);
				if(CurrentCarouselArticleTopicID == CurrentID)
					CarouselGoToArticle("Home Latest Articles");
				else {
					clearInterval(CarouselAnimationID);
					if (ATID && ATID.indexOf("CarouselLink_") == 0) ShowCarouselImage(Number(CurrentID));
				}
			});
		},
		"#featuredprevious" : function(link) {
			Event.observe(link, "click", function() {
				if (!animationLock) {
					animationLock = true;
					var track = $("track")
					var a = track.select("a").last();
					var x = track.offsetLeft;
					a.parentNode.insertBefore(a.cloneNode(true), track.firstChild);
					track.style.left = track.offsetLeft - 128 + "px";
					new Effect.Move("track", {
						x : 128,
						duration : 0.5,
						mode : "relative",
						afterFinish : function() {
							a.parentNode.removeChild(a);
							animationLock = false;
						}
					})
				}
			})
		},
		"#featurednext" : function(link) {
			Event.observe(link, "click", function() {
				if (!animationLock) {
					animationLock = true;
					var track = $("track")
					var a = track.select("a:first-child")[0];
					var x = track.offsetLeft;
					a.parentNode.appendChild(a.cloneNode(true));
					new Effect.Move("track", {
						x : -128,
						duration : 0.5,
						mode : "relative",
						afterFinish : function() {
							a.parentNode.removeChild(a);
							track.style.left = x + "px"
							animationLock = false;
						}
					})
				}
			})
		}
	});
	Behaviour.apply();
	ParseAnchors(document.body);
});


var Cookie={
	set:function(c_name,value) {
		var today = new Date;
		today.setDate(today.getDate()+365);
		document.cookie=c_name + "=" + escape(value) + ";expires=" + today.toGMTString() + ";path=/";
	},
	get:function(c_name) {
		if (document.cookie.length>0) { 
			c_start=document.cookie.indexOf(c_name + "=");
			if (c_start!=-1) { 
				c_start=c_start + c_name.length+1; 
				c_end=document.cookie.indexOf(";",c_start);
				if (c_end==-1) c_end=document.cookie.length;
				return unescape(document.cookie.substring(c_start,c_end));
			} 
		}
		return null;
	},
	remove:function(c_name) {this.set(c_name,"",-1);}
}

var search = function(SearchText){
	//don't escape SearchText, it breaks french characters
	if (String(SearchText).toLowerCase() == "pfizer") location.href = siteroot + language + "/about_pfizer?SearchText=" + SearchText;
	else location.href = siteroot + language + "/search?SearchText=" + SearchText;
}

var clearSearch = function() {
	var sI = $("searchInput");
	
	if (String(sI.getAttribute("clearable")) == "true") {
		sI.value = "";
		sI.setAttribute("clearable", "false");
	}
}

var modals = {};
var openModal = function(el, contentPath, width){
	if (modals[contentPath]) return;
	modals[contentPath] = true;
	var html = document.createElement("div");
	html.id = "openModalDiv";
	document.body.appendChild(html);
	html = $(html);
	html.innerHTML = "\
		<div class='modal-container'>\
			<div class='modal-content'>\
				<a href='javascript:;' class='modal-close-button'>&nbsp;</a>\
				<div class='modal-body'></div>\
			</div>\
		</div>'\
	";
	html.hide()
	var y = window.pageYOffset || document.documentElement.scrollTop;
	var modalWidth = width ? width : 720;
	html.select(".modal-container").invoke("setStyle", {top : "0", left: "0"})
	html.select(".modal-content").invoke("setStyle", {
		top : ((document.viewport.getHeight() / 2) - 200 + y) + "px",
		left : ((document.viewport.getWidth() / 2) - modalWidth/2) + "px",
		width : (width ? width : modalWidth) + "px"
	})
	html.select(".modal-close-button").invoke("observe", "click", function() {
		html.remove(html);
		modals[contentPath] = false
	})
	new Ajax.Updater(html.select(".modal-body")[0], siteroot + contentPath, {evalScripts: true, method: "GET", onComplete : html.show.bind(html)});
}

var biowins = {};
var openBio = function(el,contentEl){
	if($$(".padded")) $$(".modal-container").each(function(e){e.addClassName("hidden")});  // remove existing modal window
	var html = document.createElement("div");
	document.body.appendChild(html);
	if (biowins[contentEl] && biowins[contentEl].parentNode) {
		biowins[contentEl].remove();
		biowins[contentEl] = null;
	}
	biowins[contentEl] = html;
	html = $(html);
	html.innerHTML = "\
		<div class='modal-container'>\
			<div class='modal-content'>\
				<a href='javascript:;' class='modal-close-button'>&nbsp;</a>\
				<div class='modal-body padded'></div>\
			</div>\
		</div>'\
	";
	var y = window.pageYOffset || document.documentElement.scrollTop;
	html.select(".modal-container").invoke("setStyle", {top : "0", left: "0"})
	html.select(".modal-content").invoke("setStyle", {
		top : ((document.viewport.getHeight() / 2) - 200 + y) + "px",
		left : ((document.viewport.getWidth() / 2) - 360) + "px"
	})
	html.select(".modal-close-button").invoke("observe", "click", html.remove.bind(html))
	var newContentEl = html.select(".modal-body")[0];
	newContentEl.innerHTML = $(contentEl).innerHTML;
	
	ParseAnchors(newContentEl);
}

var SigningIn = false;
var DoSignIn = function (Url, Message) {
	if (!SigningIn) {
		SigningIn = true;
		var Parameters = {};
		for (var i=0; i<document.getElementById("SignInForm").elements.length; i++) {
			var Elem = document.getElementById("SignInForm").elements[i];
			if (Elem.type == "checkbox") {
				if (Elem.checked) Parameters[Elem.name] = Elem.value; 
			} else {
				Parameters[Elem.name] = Elem.value; 
			}
		}
		new Ajax.Updater("SignInFormDiv", Url, {
			method:"post",
			parameters:Parameters
		});
	}
}

var toggleDiv = function (target, elements) {	
	for (var element, i = 0; element = elements[i]; i++) {
		if (el = document.getElementById(element)) {			
			el.style.display = 'none';
		}
	}
	if (target = document.getElementById(target)) target.style.display = 'block';
}
var myToggleClass = function (target, elements) {
	for (var element, i = 0; element = elements[i]; i++) {
		if (element = $(element)) {
			element.removeClassName("selected");
		}
	}
	if (target = $(target)) {
		target.addClassName("selected");
	}
}

var flashFocus = function() {}

var showDiv = function(element, target){
	if(element != '0'){
		document.getElementById(element).style.display = 'none';
		document.getElementById(target).style.display = 'block';
	}
	else {
		var list = document.getElementsByTagName("ul");	
		for (var i=0;i<list.length;i++) {
			if(list[i].id != ''){
				if(list[i].id != target.value){
					document.getElementById(list[i].id).style.display = 'none';
				}
			}
		}
		document.getElementById(target.value).style.display = 'block';			
	}		
}

var shownewsletter = function(){
	el = document.getElementById("overlaynewsletter");
	el.style.visibility = "visible";
	if (typeof(pageTracker) != "undefined") pageTracker._trackPageview(siteroot + language + "/subscribe/sample");
}

var closeshowletter = function(id){document.getElementById(id).style.visibility = "hidden";}

var SelectTab = function(TabName) {window.location.href = "#" + TabName.toLowerCase();}

// ---------------------------------- Graffiti -----------------------------------------------
var VideoWatchDurationTimeoutID = null;
var VideoWatchDurationInterval = 10;
var TimeStarted = null;
var SecondsRemaining = VideoWatchDurationInterval;

var vidComplete = function() {
	$("modal-container2a").setStyle({ display: "none"});
	$("graffitimodalcontainer").setStyle({background:"#fff"});
}

var closeGaffiti = function() {
	StopVideoWatchDuration(true);
	$("modal-container2a").setStyle({ display: "none"});
	$("graffitimodalcontainer").setStyle({background:"#fff"});
	Element.addClassName("graffitimodalcontainer", "hidden");
}

var openGraffitiModal = function(GotoShare, CEID) {
	var graffiti = new SWFObject(siteroot + "local/flash/" + language + "/graffiti_page.swf","graffiti","703","484","7");
	graffiti.addVariable("videoSource", siteroot + "local/flash/" + language + "/graffiti_90.flv");
	if (GotoShare) graffiti.addVariable("gotoShare", "true");
	
	var CEIDStrings = {};
	CEIDStrings["1"] = "one";
	CEIDStrings["2"] = "two";
	CEIDStrings["3"] = "three";
	CEIDStrings["4"] = "four";
	CEIDStrings["5"] = "five";
	
	if (typeof(CEID) != "undefined" && CEID) graffiti.addVariable("endTag_str", CEIDStrings[String(CEID)]);
	else graffiti.addVariable("endTag_str", "0");
	graffiti.write("graffitiflash");
	Element.removeClassName("graffitimodalcontainer", "hidden");
	
	if (GotoShare) sharePressed();
	else backPressed();
}

var sharePressed = function () {
	StopVideoWatchDuration(true);
	if (typeof(pageTracker) != "undefined") pageTracker._trackPageview(siteroot + language + "/topic/index/be%20brave/watch_video/share");
}

var backPressed = function () {
	var WLS = String(window.location.search);
	if (WLS == "?") WLS = "";	
	if (typeof(pageTracker) == "undefined") {
		Event.observe(
				window, 
				"load", 
				function () {
					if (typeof(pageTracker) != "undefined") {
						pageTracker._trackPageview(siteroot + language + "/topic/index/be%20brave/watch_video" + WLS);
					}
				}
		);
	} else {
		if (typeof(pageTracker) != "undefined") {
			pageTracker._trackPageview(siteroot + language + "/topic/index/be%20brave/watch_video" + WLS);
		}
	}
}

var sendPressed = function (FE, YE, FN, YN, CEID) {
	document.getElementById("CardEndingID").value = CEID;
	document.getElementById("YourName").value = YN;
	document.getElementById("YourEmail").value = YE;
	document.getElementById("FriendsName").value = FN;
	document.getElementById("FriendsEmail").value = FE;
	document.getElementById("GraffitiForm").submit();
}

var previewPressed = function () {
	if (typeof(pageTracker) != "undefined") pageTracker._trackPageview(siteroot + language + "/topic/index/be%20brave/watch_video/share/preview");
}

var CreateFlashCounter = function (ElemID) {
	var flashcounter = new SWFObject(siteroot + "local/flash/counter.swf","counter","156","46","7");
	flashcounter.addParam("wmode", "transparent");
	flashcounter.addVariable("totalRaised", donationtotal);
	flashcounter.write(ElemID);
}

var playPressed = function () {
	StartVideoWatchDuration();
	$("modal-container2a").setStyle({ display: "block"});
	$("graffitimodalcontainer").setStyle({background:"#333"});
	$("modal-mask2a").setStyle({height : document.body.offsetHeight + "px", width : "" + document.body.offsetWidth + "px"});
	if (typeof(pageTracker) != "undefined") {
		pageTracker._trackPageview(siteroot + language + "/topic/index/be%20brave/watch_video/play");
		pageTracker._setVar("watch_graffiti");
	}
}

var watchAgainPressed = function () {
	StartVideoWatchDuration();
	$("modal-container2a").setStyle({ display: "block"});
	$("graffitimodalcontainer").setStyle({background:"#333"});
	$("modal-mask2a").setStyle({height : document.body.offsetHeight + "px", width : "" + document.body.offsetWidth + "px"});
	if (typeof(pageTracker) != "undefined") pageTracker._trackPageview(siteroot + language + "/topic/index/be%20brave/watch_video/watch_again");
}

var pausedPressed = function () {	
	StopVideoWatchDuration();
	$("modal-container2a").setStyle({ display: "none"});
	$("graffitimodalcontainer").setStyle({background:"#fff"});
}

var videoFinished = function () {
	StopVideoWatchDuration(true);
	new Ajax.Request(siteroot + language + "/be_brave/videofinished/" + document.getElementById("CardViewID").value);
}

var StartVideoWatchDuration = function () {	
	clearTimeout(VideoWatchDurationTimeoutID);
	TimeStarted = new Date();
	VideoWatchDurationTimeoutID = setTimeout(DoVideoWatchDuration, SecondsRemaining*1000);
}

var DoVideoWatchDuration = function () {
	var CVID = document.getElementById("CardViewID");	
	if (CVID && String(CVID.value).replace(/(^\s+)(\s+$)/g, "") != "") {
		new Ajax.Request(siteroot + language + "/be_brave/updateduration/" + CVID.value);		
		TimeStarted = new Date();
		SecondsRemaining = VideoWatchDurationInterval;
		VideoWatchDurationTimeoutID = setTimeout(DoVideoWatchDuration, VideoWatchDurationInterval*1000);
	}
}

var StopVideoWatchDuration = function (ResetSecondsRemaining) {
	clearTimeout(VideoWatchDurationTimeoutID);
	VideoWatchDurationTimeoutID = null;
	var Now = new Date();
	if (ResetSecondsRemaining) {
		SecondsRemaining = VideoWatchDurationInterval;
		TimeStarted = null;
	} else if (TimeStarted != null) {
		SecondsRemaining = SecondsRemaining - ((Number(Now) - Number(TimeStarted))/1000);
	}
}

var UnHighlightStarsTimeoutID;
var UnHighlightStars = function () {
	for (var i=1; i<=5; i++) {
		var Star = document.getElementById("Star" + i);
		if (Star) Star.className = String(Star.className).replace(/starselected/g, "").replace(/(^\s+)|(\s+$)/g, "");
	}
}

var HighlightStar = function (StarNumber, Highlight) {
	clearTimeout(UnHighlightStarsTimeoutID);
	if (Highlight) {
		UnHighlightStars();
		for (var i=1; i<=StarNumber; i++) {
			var Star = document.getElementById("Star" + i);
			if (String(Star.className).indexOf("starselected") < 0) {
				Star.className = String(Star.className) + " starselected";
			}
		}
	} else {
		UnHighlightStarsTimeoutID = setTimeout(UnHighlightStars, 1000);
	}
}

var RateArticle = function (R) {
	document.getElementById("RatingForm").style.display = "none";
	document.getElementById("StarThankyouDiv").style.display = "";

	if (typeof(pageTracker) != "undefined") pageTracker._trackPageview("/articleevent/RateThisModule");
	document.getElementById("Rating").value = String(R);
	document.getElementById("RatingFormSubmit").click();
}

// ----------------------------------------------------------------------------------------------------
var showModal = function(el){
	var CloseText = location.href.indexOf("/en/") > - 1 ? "Close" : "Fermer";
	var html = document.createElement("div");
	document.body.appendChild(html);
	html = $(html);
	html.innerHTML = "\
		<div class='modal-container'>\
			<div class='modal-mask'>" +
				/*@cc_on 
				"<iframe frameborder='0' src='javascript:document.write(\"<html><body></body></html>\");document.close();'></iframe>" +
				@*/
			"</div>\
			<div class='modal-content house'>\
				<a href='javascript:;' class='modal-close-button'>" + CloseText + "</a>\
				<div class='modal-body'></div>\
			</div>\
		</div>\
	";
	html.select(".modal-mask").invoke("setStyle", {height : document.body.offsetHeight + "px", width : document.body.offsetWidth + "px"});
	var y = window.pageYOffset || document.documentElement.scrollTop;
	html.select(".modal-container").invoke("setStyle", {top : "0", left: "0"})
	html.select(".modal-content").invoke("setStyle", {
		top : ((document.viewport.getHeight() / 2) - 200 + y) + "px",
		left : ((document.viewport.getWidth() / 2) - 360) + "px"
	})
	html.select(".modal-close-button").invoke("observe", "click", html.remove.bind(html))
	html.select(".modal-body")[0].innerHTML = $(el).innerHTML;
}
var room1 = function(){showModal("room1");}
var room2 = function(){showModal("room2");}
var room3 = function(){showModal("room3");}
var room4 = function(){showModal("room4");}

// ------------------------------ Poll Stuff -----------------------------------
var SelectPollAnswer = function (PAID) {
	for (var i=0; i<PollAnswerIDs.length; i++) {
		Element.removeClassName("PollAnswer_" + PollAnswerIDs[i], "selected");
	}
	
	Element.addClassName("PollAnswer_" + PAID, "selected");
	$("PollAnswerID").value = String(PAID);
}
// -----------------------------------------------------------------------------

var showABC = function(id) {
	$$("#abccontainer div.abcchar").invoke("addClassName", "hidden");
	$(id).removeClassName("hidden");
}

var showSimplifyTip = function(el, id) {
	$$("div.simplifytop a").invoke("removeClassName", "selected");
	$(el).addClassName("selected");
	$$("#simplifycontainer div.simplifytip").invoke("addClassName", "hidden");
	$(id).removeClassName("hidden");
}

var showEsteemCalendarDay = function(id) {
	$$("#esteemcalendar div.esteemcalendarday").invoke("addClassName", "hidden");
	$(id).removeClassName("hidden");
}

var videos;
var showVideos = function() {
	$("videoscontainer").removeClassName("hidden");
	$("videosmask").removeClassName("hidden");
	videos = new SWFObject(siteroot + "local/flash/videoSelector" + (location.href.indexOf("/fr/") > 0 ? "_fr" : "") + ".swf", "videoplayer", 1003, 598, 8);
	videos.addParam("allowScriptAccess", "sameDomain");
	videos.addParam("wmode", "transparent");
	videos.write("videoscontainer");
	pageTracker._trackPageview("/seeourfilms/");
}
var closeVideos = function() {
	$("videoscontainer").addClassName("hidden");
	$("videoscontainer").innerHTML = "";
	$("videosmask").addClassName("hidden");
	if (videos) videos.innerHTML = "";
}
var getVideoGaId = function(id) {
	switch (id) {
		case "breathe" : return "Breathe_" + language
		case "brave" : return "Be_Brave_" + language
		case "weCan" : return "We_Can_" + language
		case "breatheFR" : return "Breathe_fr"
		case "braveFR" : return "Be_Brave_fr"
		case "weCanFR" : return "We_Can_fr"
	}
}
var videoClick = function(id) {pageTracker._trackPageview("/seeourfilms/" + getVideoGaId(id) + "/");}
var videoStart = function(id) {pageTracker._trackPageview("/seeourfilms/" + getVideoGaId(id) + "/start/");}
var videoEnd = function(id) {pageTracker._trackPageview("/seeourfilms/" + getVideoGaId(id) + "/end/");}

var DELAY = 5000;
var INTERVAL = 0;
var slideshow = function(e) {
	e = $(e)
	if(e.hasClassName("pause")) {
		e.removeClassName("pause");
		clearInterval(INTERVAL)
		return;
	}
	e.toggleClassName("pause");
	INTERVAL = setInterval(nextframe, DELAY);
}

var nextframe = function() {
	$$(".slideshow .frame").each(function(el){
		if(!el.hasClassName("hidden")){
			if (!el.next(0)) {
				$("slideshowplay").removeClassName("pause");
				clearInterval(INTERVAL);
			}
			if(el.next(0) && !el.next(0).hasClassName("controller")){
				el.next(0).removeClassName("hidden");
				el.addClassName("hidden");
				throw $break;
			}
		}
	})
}

var previousframe = function() {
	$$(".slideshow .frame").each(function(el){
		if(!el.hasClassName("hidden")){				
			if(el.previous()){
				el.previous().removeClassName("hidden");
				el.addClassName("hidden");
			}
		}
	})
}

// Breathe -----------------------------------------------------------------------------------
var showBreatheModal = function () {
	if (typeof(pageTracker) != "undefined") pageTracker._trackPageview("/" + language + "/article/index/Breathe/watch_video/");
}

var closeBreatheModal = function () {
	StopVideoWatchDuration(true);
	$("BreatheDiv").addClassName("hidden");
	$("breatheflash").innerHTML = "";
	if (LoadBreatheAudio) LoadBreatheAudio();
	
	document.getElementById("BreatheTitleMeta").name = "xtitle";
	document.getElementById("BreatheDescriptionMeta").name = "xdescription";
	document.getElementById("BreatheImageLink").rel = "ximage_src";
	document.getElementById("ArticleTitleMeta").name = "title";
	document.getElementById("ArticleDescriptionMeta").name = "description";
	document.getElementById("ArticleImageLink").rel = "image_src";
}

var SetDefaultBreatheText = function(Elem) {
	if (String(Elem.value).replace(/(^\s+)|(\s+$)/g, "") == "") {
		Elem.value = String(Elem.getAttribute("defaulttext"));
	}
}

var RemoveDefaultBreatheText = function(Elem) {
	if (String(Elem.value).replace(/(^\s+)|(\s+$)/g, "") == String(Elem.getAttribute("defaulttext"))) {
		Elem.value = "";
	}
}

var loadbreatheflash = function(playerdiv) {
	var filename;		
	if (language == "fr") filename = "PFI-BREATHE-4141-14-68F_VP6_250K.flv";
	else filename = "PFI-BREATHE-4141-13-68E_VP6_250K.flv";
	
	if (flashinstalled) {
		var breatheso = new SWFObject(siteroot + 'local/flash/VideoPlayer_BREATHE.swf', 'breathevideo', 492, 310, 9);
		breatheso.addVariable('videoSource', siteroot + 'local/flash/flv/' + filename)
		breatheso.addParam("allowFullScreen","true")
		breatheso.write(playerdiv);
	} else {
		if (language == "fr") filename = "PFI-BREATHE-4141-14-68F.mp4";
		else filename = "PFI-BREATHE-4141-13-68E.mp4";		
		$(playerdiv).innerHTML = "<a href='"+ siteroot + "local/flash/" + filename + "'><img src='" + siteroot + "local/images/mobile_play.jpg' /></a>";
	}
}

var videoBigPlayBreathe = function () {breathePlayPressed();}

var videoPlayPauseyBreathe = function () {
	if (VideoWatchDurationTimeoutID == null) breathePlayPressed();
	else breathePausePressed();
}

var breathePlayPressed = function() {
	var TrackPlay = TimeStarted == null;	
	StartVideoWatchDuration();	
	if (TrackPlay && typeof(pageTracker) != "undefined") {
		pageTracker._trackPageview("/" + language + "/article/index/Breathe/watch_video/play/");
		if (!document.getElementById("PlayAgain") || document.getElementById("PlayAgain").value != "true") pageTracker._trackEvent("Breathe Video", "Watch Video", "Play");
		pageTracker._setVar("watch_breathe")
	}
}

var breathePausePressed = function() {StopVideoWatchDuration();}

var videoStopBreathe = function() {StopVideoWatchDuration(true);}

var videoEndBreathe = function() {
	StopVideoWatchDuration(true);
	if (document.getElementById("CardViewID")) new Ajax.Request(siteroot + language + "/be_brave/videofinished/" + document.getElementById("CardViewID").value);	
	if (typeof(pageTracker) != "undefined") pageTracker._trackPageview("/" + language + "/article/index/Breathe/watch_video/end/");
}

var BreatheIndexLoaded = function(RunParseAnchors) {
	loadbreatheflash("breatheflash");
	if (RunParseAnchors) {
		ParseAnchors($("BreatheDiv"));
		if (typeof(pageTracker) != "undefined") pageTracker._trackPageview("/" + language + "/article/index/Breathe/watch_video/");
	}
}

var BreatheFormLoaded = function() {
	if (typeof(pageTracker) != "undefined") pageTracker._trackPageview("/" + language + "/article/index/Breathe/watch_video/share_email/");
}

var BreathePreviewLoaded = function() {
	loadbreatheflash("breathevideo");	
	if (typeof(pageTracker) != "undefined") pageTracker._trackPageview("/" + language + "/article/index/Breathe/watch_video/share_email/preview/")
}

var BreatheThankYouLoaded = function() {
	if (typeof(pageTracker) != "undefined") pageTracker._trackPageview("/" + language + "/article/index/Breathe/watch_video/share_email/thank_you/")
}

var DoBreatheShare = function () {
	if (typeof(pageTracker) != "undefined") pageTracker._trackEvent("Breathe Video", "Share Video", "Email");
	new Ajax.Updater("BreatheDiv", siteroot + language + "/breathe/form", { method:"get" });
}

var DoBreatheShareAgain = function () {
	if (typeof(pageTracker) != "undefined") pageTracker._trackEvent("Breathe Video", "Share Video", "Email Again");
	new Ajax.Updater("BreatheDiv", siteroot + language + "/breathe/form", { method:"get" });
}

var DoBreatheWatchAgain = function() {
	if (typeof(pageTracker) != "undefined") pageTracker._trackEvent("Breathe Video", "Watch Video", "Play Again");
	new Ajax.Updater("BreatheDiv", siteroot + language + "/breathe/index?PlayAgain=true", { method:"get" });
}
// -------------------------------------------------------------------------------------------

// Paralympics -------------------------------------------------------------------------------
var modalTimeout = 0
var ParalympicsEBookClick = function () {
	if (typeof(pageTracker) != "undefined") pageTracker._trackPageview("/" + language + "/paralympics/kofc/index.html/");
	if (document.getElementById("openModalDiv")) {
		var html = $("openModalDiv");
		html.remove.bind(html)();
	}
	clearTimeout(modalTimeout);
	modalTimeout = setTimeout(function () { openModal(this, language + "/paralympics/questionaire", "450"); }, 5000);	
	if (typeof(pageTracker) != "undefined") pageTracker._trackPageview("/" + language + "/paralympics/download/KofC-" + (language == "fr" ? "French - KofC - Flipbook - FINAL.pdf" : "Kids of Courage Print ONLINE PRINT LAYOUT.pdf") + "/");
}

var ParalympicsShareLoaded = function (TryAgain) {
	if (typeof(pageTracker) != "undefined") pageTracker._trackPageview("/" + language + "/paralympics/share_email/" + (TryAgain ? "tryagain/" : ""));
}

var ParalympicsShareThankyouLoaded = function (TryAgain) {
	if (typeof(pageTracker) != "undefined") pageTracker._trackPageview("/" + language + "/paralympics/share_email/submit/");
}

var ParalympicsSurveyLoaded = function (TryAgain) {
	if (typeof(pageTracker) != "undefined") pageTracker._trackPageview("/" + language + "/paralympics/questionnaire/" + (TryAgain ? "tryagain/" : ""));
}

var ParalympicsSurveyThankyouLoaded = function (TryAgain) {
	if (typeof(pageTracker) != "undefined") pageTracker._trackPageview("/" + language + "/paralympics/questionnaire/submit/");
}

var ParalympicsPlayPressedOnce = false;
var ParalympicsPlayPressed = function() {
	if (VideoWatchDurationTimeoutID == null) StartVideoWatchDuration();
	else StopVideoWatchDuration();
	
	if (!ParalympicsPlayPressedOnce) {
		if (typeof(pageTracker) != "undefined") pageTracker._trackPageview("/" + language + "/paralympics/audio_play/start/");
		ParalympicsPlayPressedOnce = true;
	}
}

var ParalympicsAudioEnd = function() {
	StopVideoWatchDuration(true);
	if (document.getElementById("CardViewID")) new Ajax.Request(siteroot + language + "/be_brave/videofinished/" + document.getElementById("CardViewID").value);	
	if (typeof(pageTracker) != "undefined") pageTracker._trackPageview("/" + language + "/paralympics/audio_play/end/");
}

var openParalympicsVideoModal = function(el){
	var html = document.createElement("div");
	html.id = "openModalDiv";
	$$(".bgtop")[0].appendChild(html);
	html = $(html);
	html.innerHTML = "\
		<div class='modal-container paralympicsvideomodal'>\
			<div class='modal-mask'>" +
				/*@cc_on 
				"<iframe frameborder='0' src='javascript:document.write(\"<html><body></body></html>\");document.close();'></iframe>" +
				@*/
			"</div>\
			<div class='modal-content'>\
				<a href='javascript:;' class='modal-close-button'>" + (language == "en" ? "Close" : "Fermer") + "</a>\
				<div id='ParalympicsVideoDiv' class='modal-body'></div>\
			</div>\
		</div>\
	";
	html.show();
	var y = window.pageYOffset || document.documentElement.scrollTop;
	html.select(".modal-mask").invoke("setStyle", {height : document.body.offsetHeight + "px", width : 100 + "%"});
	html.select(".modal-container").invoke("setStyle", {top : "0", left: "0"})
	html.select(".modal-content").invoke("setStyle", {
		top : 64 + "px",
		left : 140 + "px"
	});
	html.select(".modal-close-button").invoke("observe", "click", function() {
		//html.remove(html);
		closeParalympicsVideoModal();
	});
	goToParalympicsVideoModal();
	
	document.getElementById("ParalympicsVideoTitleMeta").name = "title";
	document.getElementById("ParalympicsVideoDescriptionMeta").name = "description";
	document.getElementById("ParalympicsTitleMeta").name = "xtitle";
	document.getElementById("ParalympicsDescriptionMeta").name = "xdescription";
}

var closeParalympicsVideoModal = function () {
	StopVideoWatchDuration(true);
	var html = $("openModalDiv");
	html.remove(html);
	
	document.getElementById("ParalympicsVideoTitleMeta").name = "xtitle";
	document.getElementById("ParalympicsVideoDescriptionMeta").name = "xdescription";
	document.getElementById("ParalympicsTitleMeta").name = "title";
	document.getElementById("ParalympicsDescriptionMeta").name = "description";
}

var goToParalympicsVideoModal = function(ViewAgain) {
	if (ViewAgain) pageTracker._trackEvent("Paralympics Video", "Watch Video", "Play Again");

	var el = $("ParalympicsVideoDiv");
	new Ajax.Updater(el, siteroot + language + "/paralympics/video" + (ViewAgain ? "?PlayAgain=true" : ""), {
		evalScripts: true,
		method: "GET",
		onComplete: function() {
			el.up().removeClassName("thankyoumodal");
		}
	});
}
var goToParalympicsShareModal = function(ShareAgain) {
	if (typeof(pageTracker) != "undefined") {
		pageTracker._trackEvent("Paralympics Video", "Share Video", "Email" + (ShareAgain ? " Again" : ""));
	}
	var el = $("ParalympicsVideoDiv");
	new Ajax.Updater(el, siteroot + language + "/paralympics/sharevideo/", {
		evalScripts: true,
		method: "GET",
		onComplete: function() {
			el.up().removeClassName("thankyoumodal");
		}
	})
}

var loadparalympicsvideoflash = function() {
	var paralympicsvideoso = new SWFObject(siteroot + "local/flash/VideoPlayer_ChinUp_" + language + ".swf", "paralympicsvideoswf", 492, 306, 7);
	//paralympicsvideoso.addParam("wmode", "transparent");
	paralympicsvideoso.addParam("allowFullScreen", "true");
	paralympicsvideoso.addVariable("videoSource", siteroot + "local/flash/flv/PFI-Chinups_" + language + ".flv");
	paralympicsvideoso.write("paralympicsflashcontainer");
}

var ParalympicsVideoVideoLoaded = function() {
	loadparalympicsvideoflash();
	ParseAnchors($("ParalympicsVideoDiv"));
	if (typeof(pageTracker) != "undefined") pageTracker._trackPageview("/" + language + "/paralympics/watch_video/");
}

var ParalympicsVideoShareLoaded = function(TryAgain) {
	if (typeof(pageTracker) != "undefined") pageTracker._trackPageview("/" + language + "/paralympics/watch_video/share_email/" + (TryAgain ? "tryagain/" : ""));
}

var ParalympicsVideoThanksLoaded = function() {
	ParseAnchors($("ParalympicsVideoDiv"));
	if (typeof(pageTracker) != "undefined") pageTracker._trackPageview("/" + language + "/paralympics/watch_video/share_email/thank_you/")
}

//paralympics video tracking
var paralympicsVideoPlayPressed = function () {
	var TrackPlay = TimeStarted == null;
	
	StartVideoWatchDuration();
	
	if (TrackPlay && typeof(pageTracker) != "undefined") {
		pageTracker._trackPageview("/" + language + "/paralympics/watch_video/play/");
		if (!document.getElementById("PlayAgain") || document.getElementById("PlayAgain").value != "true") pageTracker._trackEvent("Paralympics Video", "Watch Video", "Play");
		pageTracker._setVar("watch_paralympics")
	}
}

var paralympicsVideoPausePressed = function() {StopVideoWatchDuration();}

// flash calls
var videoStopChinup = function() {StopVideoWatchDuration(true);}

var videoEndChinup = function() {
	StopVideoWatchDuration(true);
	if (document.getElementById("CardViewID")) new Ajax.Request(siteroot + language + "/be_brave/videofinished/" + document.getElementById("CardViewID").value);
	
	if (typeof(pageTracker) != "undefined") pageTracker._trackPageview("/" + language + "/paralympics/watch_video/end/");
}

var videoStartChinup = function() {}

var videoBigPlayChinup = function() {paralympicsVideoPlayPressed();}

var videoPlayPauseyChinup = function() {
	if (VideoWatchDurationTimeoutID == null) paralympicsVideoPlayPressed();
	else paralympicsVideoPausePressed();
}
// -------------------------------------------------------------------------------------------

//for new slideshow articles template
var showNextSlide = function(end){
	var currentSlide = $("slidenum").innerHTML;
	var nextSlide = parseInt(currentSlide) + 1;
	if(nextSlide <= end){
		$("frame" + currentSlide).addClassName("hidden")
		$("frame" + nextSlide).removeClassName("hidden")
		$("slidenum").innerHTML = nextSlide;
		$$(".controllbar .selected")[0].next(".frameblock").addClassName("selected");
		$$(".controllbar .selected")[0].removeClassName("selected");		
	}
}

var showPreviousSlide = function(){
	var currentSlide = $("slidenum").innerHTML;
	var previousSlide = parseInt(currentSlide) - 1;
	if(previousSlide > 0){
		$("frame" + currentSlide).addClassName("hidden")
		$("frame" + previousSlide).removeClassName("hidden")
		$("slidenum").innerHTML = previousSlide;
		$$(".controllbar .selected")[0].previous(".frameblock").addClassName("selected");
		$$(".controllbar .selected")[1].removeClassName("selected");		
	}
}