// Cross-browser implementation of element.addEventListener()

function listen(evnt, elem, func)
	{
	    if (elem.addEventListener)  // W3C DOM
	        elem.addEventListener(evnt,func,false);
	    else if (elem.attachEvent) { // IE DOM
	         var r = elem.attachEvent("on"+evnt, func);
		return r;
    }
    else window.alert('I\'m sorry Dave, I\'m afraid I can\'t do that.');
	}

// Use: listen("event name", elem, func);

// Site Photograph

function set_photograph()
{
  var photo = document.getElementById("f-photograph-wide");
  var photos = get_photographs();

  // Set the photograph
  var r_number = Math.floor(Math.random() * photos[0].length);
  //photo.style.backgroundImage = "url(" + path + photos[r_number] + ")";
  photo.style.backgroundImage = "url(" + photos[0][r_number] + ")";

  // Create the caption  
  var caption = document.createElement("div");
  caption.id = "p-caption";

  var caption_text = document.createTextNode(photos[1][r_number]);
  caption.appendChild(caption_text);
  photo.appendChild(caption);
}

// Page Tools: Print Page

function print_page()
{
	if(window.print)
	{
		window.print();
		return;
	}
}

// Page Tools: Email Link

function email_link()
{
	var page_url = window.location.href;
	var page_title = document.getElementsByTagName("h1");
	var site = "Abington Presbyterian Church";

	if(page_title[0].innerText)
	{
		page_name = page_title[0].innerText;
	}
	else
	{
		page_name = page_title[0].textContent;
	}

	var email_subject = "A Link To The " + site + " Website";
	var email_body = "A link to the '" + escape(page_name) + "' page at the " + site + " website has been sent to you. %0D%0DYou can visit this page at: " + page_url + "%0D%0DThank you.%0D%0D------------------------%0DThis email was auto generated from the " + site + " website.";
	window.open("mailto:?subject=" + email_subject + "&body=" + email_body);

	return false;
}

// Text Size

function text_size(el,ix)
{
	var sizes = new Array("1em","1.15em","1.5em");
	var article = document.getElementById("c-article");
	article.style.fontSize = sizes[ix];

	var div = document.getElementById("text-size");
	var a = div.getElementsByTagName("a");

	for(var i=0; i<a.length; i++)
	{
		a[i].className = "";
	}

	el.className = "on";
}
