if(window.scriptLoaders == null) {
	window.scriptLoaders = [];
}

var langs = {
	'en': {
		'popupToolTip': 'Click to enlarge'
	},
	'es': {
		'popupToolTip': 'Haz clic para agrandar'
	}
};

var popupImage = function(image, offsetX, offsetY) {
	$('page').style.opacity = '0.25';
	$('page').style.filter = 'alpha(opacity=25)';
	window.scrollTo(0, 0);
	
	var wrapper = document.createElement('div');
	wrapper.setAttribute('id', 'popupImageDiv');
	wrapper.style.position = 'absolute';
	wrapper.style.width = '100%';
	wrapper.style.height = '100%';
	wrapper.style.left = '0';
	wrapper.style.top = '0';
	
	var imageDivContent = document.createElement('div');
	imageDivContent.style.position = 'relative';
	imageDivContent.style.width = '100%';
	imageDivContent.style.height = '100%';
	wrapper.appendChild(imageDivContent);
	
	var windowWidth = 0;
	if(typeof(window.innerWidth) == 'number') {
		windowWidth = window.innerWidth;
	} else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		windowWidth = document.documentElement.clientWidth;
	} else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
		windowWidth = document.body.clientWidth;
	}
	
	windowWidth = $('page').offsetWidth;
	
	var leftOffset = (windowWidth * 1 / 2 - 400) + 'px';
	
	var closeAnchor = document.createElement('a');
	closeAnchor.setAttribute('href', '#');
	closeAnchor.onclick = function() {
		var wrapper = $('popupImageDiv');
		document.getElementsByTagName('body')[0].removeChild(wrapper);
		$('page').style.opacity = '1.0';
		$('page').style.filter = 'alpha(opacity=100)';
	};
	closeAnchor.style.position = 'absolute';
	closeAnchor.style.left = leftOffset;
	closeAnchor.style.top = '0';
	closeAnchor.setAttribute('title', 'Click to close');
	imageDivContent.appendChild(closeAnchor);
	
	var image2 = document.createElement('img');
	var src = image.getAttribute('src').split(new RegExp(/\.[^.]+$/))[0];
	image2.setAttribute('src', src + '_full.jpg');
	image2.setAttribute('width', '800');
	image2.setAttribute('height', '600');
	image2.setAttribute('alt', '');
	image2.style.paddingTop = '25px';
	
	closeAnchor.appendChild(image2);
	
	var body = document.getElementsByTagName('body')[0];
	body.appendChild(wrapper);
};

var scriptLoader = function() {
	var images = getElementsByClass('popupImage', $('content'));
	
	for(var i=0; i < images.length; i++) {
		var image = images[i];
		image.setAttribute('title', window.langs[window.lang]['popupToolTip']);
		image.onmouseover = function() {
			this.style.cursor = 'pointer';
		};
		image.onmouseout = function() {
			this.style.cursor = 'auto';
		};
		image.onclick = function(e) {
			e = (e != null) ? e : window.event;
			popupImage(this, e.clientX, e.clientY);
		};
	}
};

scriptLoaders = scriptLoaders.concat([scriptLoader]);