/**
 * Link Matches
 *
 * These are applied to each link during onLoad and the appropriate event
 * is attached to the link.
 */

(function(){
	/**
	 * Link object format
	 * obj.expression -> a regular expression object to match href attribute.
	 * obj.click -> function to be added as an event handler
	 */

	var contraception = {
		expression : new RegExp('^http://www\.contraception\.co\.uk'),
		click : function(evt){
		       return;
		}
	};

	var external = {
		expression : new RegExp('^http://.*'),
		click : function(evt){
			alert("You are now leaving this Bayer website - marketing authorisations\nand availability of medicines may differ between the UK and other countries.\n\nBayer is not responsible for the information on the website to which you are linking");
		}
	};

	/**
	 * Each type of link should be added to the links array in order of importance.
	 * The first matching action will be applied.
	 */

	var links = [contraception,external];

	$(document).ready(function(){
		$("a").each(function(){
			var href = $(this).attr('href');

			if(href){
				for(var i = 0;i < links.length;i++){
					if(href.match(links[i].expression)){
						$(this).click(links[i].click);
						break;
					}
				}
			}
		});
	});
})();

