/**
 * @author gavin.williams
 */

var EmailLinks = (function(){

	Events = {
		bind: function bind(){
			this.bindLinks();
		},
		/**
		 * Attaches an event to a DOM element
		 * @param {HTMLElement} element
		 * @param {Function} event
		 */
		attachEvent: function attachEvent(element, event, callback){
			if(document.attachEvent){
				element.attachEvent('on' + event, callback);
			} else if(document.addEventListener){
				element.addEventListener(event, callback, false);
			}
		},
		bindLinks: function bindLinks(){
			var links = document.getElementsByTagName('a'), regEx = new RegExp('emailemail');
			for(var i = 0; i < links.length; i++){
				if(regEx.test(links[i].href)){
					this.attachEvent(links[i], 'click', function(){
						var url = window.location;
						window.location = 'mailto:yourfriend@somewhere.com?subject=A Link Has Been Recommended To You&body=This link has been recommended to you: ' + url;
						return false;
					});
				}
			}
		},
		init: function init(){
			this.bind();
		}
	};
	
	return {
		init: function init(){
			Events.init();
		}
	}
	
})();

window.onload = function(){
	EmailLinks.init();
}

/*function mailpage()
{
	mail_str = "mailto:?subject=Check out the " + document.title;
	mail_str += "&body=I thought you might be interested in the " + document.title;
	mail_str += ". You can view it at, " + location.href;
	location.href = mail_str;
}*/
