// JavaScript Document

//Used to activate the awards tooltip boxes on the homepage
function awardsHover() {
	var self = this;
	self.awardsImages = ".home-awards li img";
	self.imagePath = "";
	self.init = function() {
		if($(self.awardsImages).length > 0) {
			$(self.awardsImages).each(function() {
				$(this).mouseover(function() {
					self.imagePath = $(this).attr("src");
					var imagePathNew = self.imagePath.split(".");
					imagePathNew = imagePathNew[0] + "-on." + imagePathNew[1];
					$(this).attr("src",imagePathNew);
					var offset = $(this).width();
					$(this).parent().children('.awardDescription').css({ visibility: "visible", display: "block", marginLeft: (offset-232)/2 }).animate({ opacity: 1, top: "-50px" }, 200);
				});
				$(this).mouseout(function() {
					$(this).attr("src",self.imagePath);
					$(this).parent().children('.awardDescription').animate({ opacity: 0, top: "-75px" }, 300, function() { $(this).parent().children('.awardDescription').css({visibility: "hidden"}); });
				});
			});
		}
	}
	self.init();
}

//Used to add the left and right rounded corners of the pdf download modules
function roundPdfModule() {
	var self = this;
	self.pdfModule = new Array(
	   ".internationalRight",
	   ".internationalDownloadsNarrow",
	   ".internationalDownloadsWide"
	);
	self.init = function() {
		for(var i=0; i<self.pdfModule.length; i++) {
			if($(self.pdfModule[i]).length > 0) {
				$(self.pdfModule[i]).append('<span class="left"/>');
				$(self.pdfModule[i]).append('<span class="right"/>');
			}
		}
	}
	self.init();
}

//Because this site uses align=right on a lot of images, I needed to add a classname for styling
function addImgRightAlignPadding() {
	var self = this;
	self.imageAttrName = "align";
	self.imageAttrVal = "right";
	self.init = function() {
		$("img").each(function() {
			if($(this).attr(self.imageAttrName) == self.imageAttrVal) {
				$(this).addClass("right_image");
			}										
		});		
	}
	self.init();
}

//This function is used for the rollover effect on the main navigation
function mainNavRoll() {
	var self = this;
	self.rollinClass = "rollin";
	self.navParent = "ul#nav";
	self.navElement = self.navParent + " li a";
	self.startTop = "";
	self.height = '48px';
	self.bgcolor = '#e7f3fa';
	self.animateSpeed = 90;
	self.excludeID = "partnerLoginButton";
	self.init = function() {
		if($(self.navElement).length > 0) {
			$(self.navParent).append('<li class="' + self.rollinClass + '" style="position:absolute;"></li>');
			$(self.navElement).each(function() {
				if($(this).parent("li").attr("id") != self.excludeID) {
					$(this).mouseover(function() {
						var width = $(this).css('width');
						var position = $(this).parent("li").position();
						self.startTop = (position.top - 55) + "px";
						var endTop = (position.top - 25) + "px";
						var left = (position.left - 5) + "px"
						$(self.navParent + " ." + self.rollinClass).animate({
							'width' : width,
							'height' : self.height,
							'background-xolor' : self.bgcolor,
							'zIndex' : '-1',
							'top' : self.startTop,
							'left': left,
							'opacity' : '0'
						},0,function() {
							$(this).animate({'opacity':'1','top':endTop},self.animateSpeed);
						});
					});
					$(this).mouseout(function() {
						$(self.navParent + " ." + self.rollinClass).animate({'opacity':'0','top':self.startTop},self.animateSpeed);
					});
				}
			});
		}
	}
	self.init();
}


//A function used to scroll the page for jump menus
function scrollToAnchor() {
	var self = this;
	self.init = function() {
		if($("a").length > 0) {
			$("a").each(function() {
				$(this).click(function() {
					var id = $(this).attr("href");
					if(id.indexOf("#") == 0) {
						$('html,body').animate({scrollTop: $(id).offset().top},'slow');
					}
				});
			});
		}
	}
	self.init();
}


function nospam(user,domain) {
    locationstring = "mailto:" + user + "@" + domain;
    window.location = locationstring;
}





$(document).ready(function() {
	var awardsHoverGo = new awardsHover();
	var roundPdfModuleGo = new roundPdfModule();
	var addImgRightAlignPaddingGo = new addImgRightAlignPadding();
	var mainNavRollGo = new mainNavRoll();
	var scrollToAnchorGo = new scrollToAnchor();
});
