/*******************************************************************************************
 * popupPdf
 * Written by Craig Francis
 * Allow the
 *******************************************************************************************/

	var popupPdf = new function() {

		//--------------------------------------------------
		// Old browsers

			if (!document.getElementById || !document.getElementsByTagName) {
				return;
			}

		//--------------------------------------------------
		// Initialisation

			this.init = function() {

				//--------------------------------------------------
				// Debug

					console.log('popupPdf.js: Initialisation');

				//--------------------------------------------------
				// Get the references

					var links = document.getElementsByTagName('a');
					for (var k = (links.length - 1); k >= 0; k--) {
						if (links[k].href && links[k].href.match(/\.(pdf|doc)$/)) {

							links[k].onclick = popupPdf.launch;

							if (links[k].title === '') {
								links[k].title = 'Opens in a new window';
							}

							cssjs('add', links[k], 'jsPopupActive');

						}
					}

				//--------------------------------------------------
				// Get a reference to the

					popupPdf.myElement = document.getElementById('myElement');
					if (!popupPdf.myElement) {
						return;
					}

			}

		//--------------------------------------------------
		// Function called when the link is used

			this.launch = function(input) {

				//--------------------------------------------------
				// Try to open the window

					var oWin = window.open(this.href);

				//--------------------------------------------------
				// If the pop-up was successfully created, then return
				// false (don't use normal href link), otherwise
				// return true (so the browser links as normal).

					if (oWin == null || typeof(oWin) == 'undefined') {
						return true;
					} else {
						oWin.focus();
						return false;
					}

			}

		//--------------------------------------------------
		// On page load

			addLoadEvent(function() {
				popupPdf.init();
			});

	}

