/*******************************************************************************************
 * downloadExtra
 * Written by Craig Francis
 * Allow a download link to open in a popup, and the main window show a thank you page
 *******************************************************************************************/

	var downloadExtra = new function() {

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

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

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

			this.init = function() {

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

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

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

					var links = document.getElementsByTagName('a');
					for (var k = (links.length - 1); k >= 0; k--) {
						if (cssjs('check', links[k], 'jsDownloadExtra')) {
							links[k].onclick = function() {

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

								if (oWin == null || typeof(oWin) == 'undefined') {

									return true; // Pop-up blocker

								} else {

									window.location = '/download/';
									return false;

								}

							}
						}
					}

			}

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

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

	}
