var wwfEarthHourLightsOff_staticPath = 'http://static.wwf.org.uk/';
var wwfEarthHourLightsOff_pagePath = 'http://earthhourmap.wwf.org.uk/lightswitch/';
var wwfEarthHourLightsOff_partnerCode = 'ECR001006';

function wwfEarthHourLightsOff_DoFSCommand(command, args) {
	function getPageHeight(){
		
		var yScroll;
		if (window.innerHeight && window.scrollMaxY) {	
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			yScroll = document.body.offsetHeight;
		}
		
		var windowHeight;
		if (self.innerHeight) {	// all except Explorer
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowHeight = document.body.clientHeight;
		}	
		
		return Math.max(windowHeight, yScroll);
	}
	function setStyle(elem, style) {
		for (prop in style) elem.style[prop] = style[prop];
	}

	if (command == 'lightbox') {
	//location.href="https://support.wwf.org.uk/earth_hour/index.php?type=individual";
		var overlay = document.createElement("div");
		overlay.id = "wwf_earth_hour_light_switch_overlay";
		document.body.appendChild(overlay);
		setStyle(overlay, {
			position: 'absolute', top: 0, left: 0, zIndex: 900, width: '100%',
			height: getPageHeight() + 'px',
			backgroundColor: '#000000',	opacity: '0.8', filter: ' alpha(opacity=80)'
		});
		
		var lightboxPosition = document.createElement("div");
		overlay.id = "wwf_earth_hour_light_switch_lightbox_position";
		document.body.appendChild(lightboxPosition);
		setStyle(lightboxPosition, {
			position: 'absolute', top: '40px', left: '0px', zIndex: 910, width: '100%'
		});
		lightboxPosition.align = 'center';
		
		var lightbox = document.createElement("div");
		lightboxPosition.appendChild(lightbox);
		setStyle(lightbox, {
			width: '640px', height: '480px', margin: 'auto',
			padding: '16px',
			backgroundImage: 'url(' + wwfEarthHourLightsOff_staticPath + 'border.png)', position: 'relative'
		})
		lightbox.onclick = function(e) {
			if (!e) var e = window.event;
			e.cancelBubble = true;
			if (e.stopPropagation) e.stopPropagation();
		}
		
		var closeButton = document.createElement('img');
		closeButton.src = wwfEarthHourLightsOff_staticPath + 'close.png';
		closeButton.width = 40;
		closeButton.height = 40;
		setStyle(closeButton, {
			position: 'absolute', top: '-18px', right: '-18px', cursor: 'pointer'
		});
		lightbox.appendChild(closeButton);
		closeButton.onclick = function() {
			document.body.removeChild(overlay);
			document.body.removeChild(lightboxPosition);
		}

		var iframe = document.createElement('iframe');
		iframe.src = wwfEarthHourLightsOff_pagePath + '?pc=' + encodeURIComponent(wwfEarthHourLightsOff_partnerCode);
		iframe.width = 640;
		iframe.height = 480;
		iframe.style.border = '0px';
		iframe.border = 0;
		iframe.frameBorder = 0;

		lightbox.appendChild(iframe);
		
		window.wwfEarthHourLightsOff_close = function() {
			document.body.removeChild(overlay);
			document.body.removeChild(lightboxPosition);
		}
		overlay.onclick = function() {
			window.wwfEarthHourLightsOff_close();
		}
		
		lightboxPosition.onclick = function() {
			document.body.removeChild(overlay);
			document.body.removeChild(lightboxPosition);
		}
	} else if (command == 'close') {
		var lightSwitch = document.getElementById('wwf_earth_hour_light_switch');
		lightSwitch.parentNode.removeChild(lightSwitch);
	}
};


