// JavaScript Document


// Kick on the fancybox...
jQuery(document).ready(function() {
		
	// Scroll bar
	
	
	
	//print function
	$("div.eui_page_print").click(function(){
		window.print();
	});
	
	//News Accordion
	$("h2.jsAccordionTrigger").click(function(){
		$(this).next(".jsAccordion").slideToggle(500,function callback() {
			
		});
		$(this).toggleClass("eui_page_h2_active");
		
	});
	
	// Press release pages: Need to update the Back links
	var arrUrlVars = getUrlVars();
	var strOpen = arrUrlVars["open"];
    var strPressResources = arrUrlVars["press-resources"];
	if (typeof(strOpen) != "undefined"){
		$("a").each(function() {
			var $this = $(this);
			// Only modify "Back" links on press release pages
			if ($this.text() == "Back") {
				var strCurrUrl = $this.attr("href");
				var newUrl = strCurrUrl + "?open=" + strOpen;
				$this.attr("href", newUrl);
			}
		});
	} else if (typeof(strPressResources) != "undefined") {
		$("a").each(function() {
			var $this = $(this);
			// Only modify "Back" links on press release pages
			if ($this.text() == "Back") {
				var strCurrUrl = $this.attr("href");
				var newUrl = "../newsroom/press-resources.php";
				$this.attr("href", newUrl);
			}
		});    
    }
	
});

$("a").click(function(event){
	event.preventDefault();
	var url = $(this).attr('href');

	$("div.eui_content_area").fadeOut(500, function(){
		document.location.href = url;
	});
	
  	return false;

});

function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}


(function($) {
	$.fn.vCenter = function(options) {
		var pos = {
			sTop : function() {
				return window.pageYOffset
				|| document.documentElement && document.documentElement.scrollTop
				||  document.body.scrollTop;
			},
		wHeight : function() {
				return window.innerHeight
				|| document.documentElement && document.documentElement.clientHeight
				|| document.body.clientHeight;
			}
		};
		return this.each(function(index) {
			if (index == 0) {
				var $this = $(this);
				var elHeight = $this.height();
				var elTop = pos.sTop() + (pos.wHeight() / 2) - (elHeight / 2);
				$this.css({
					position: 'absolute',
					marginTop: '0',
					top: elTop
				});
			}
		});
	};
	$.fn.InitVideoPopup = function(options) {
		$(".column-video a.watch-video").click(function() {
			var $this = $(this);
			var $video = $this.parent().siblings(".container-video-hidden").clone(true);
			var $body = $("body");
			var intWidth = $body.width();
			var intHeight = $body.height();
			$video.append('<div id="button-popup-close"><a href="#">X</a></div>');
			$body.append('<div id="background-greyout">&nbsp;</div>');
			$("#background-greyout").height(intHeight).fadeIn(500, function() {
				$("#background-greyout").append($video);
				$video.show().vCenter();
				var intLeft = ((intWidth - $video.width())/2);
				$video.css("left", intLeft);
			}).click(function() {
				$video.hide();
				$("#background-greyout").fadeOut(500, function() {
					$(this).remove();
				});
				return false;
			});
			$("#button-popup-close a").click(function() {
				$("#background-greyout").click();
			});
			return false;
		});
		
	}
})(jQuery);
	

