//------------------------------------------------------------------
// ATTACH EVENT LISTENERS
//------------------------------------------------------------------
Event.observe(window, 'load', Util.adjustHeight);
Event.observe(window, 'load', DictionaryTabs.init);
Event.observe(window, 'load', WordEditor.init);
Event.observe(window, 'load', WordView.init);
Event.observe(window, 'load', Permissions.init);
Event.observe(window, 'load', Util.pngFix);
Event.observe(window, 'load', Euroklex.init);
Event.observe(window, 'resize', Util.adjustHeight);
Event.observe(window, 'load', function () {
	if (!$('word-editor') && !$('word-view')) {
		var deleteLinks = Element.select($('content'), 'a.delete');

		for (var i=0; i<deleteLinks.length; i++) {
			Event.observe(deleteLinks[i], 'click', function (event) {
				if (!confirm(i18n.genericDeleteConfirm)) {
					Event.stop(event);
					return false;
				}
			});
		}
	}
	
	new Ajax.Request('/translations/json', {
		method: 'get',
		onComplete: function (transport) {
			i18n = transport.responseJSON;
		}
	});

	if ($('colophon-text')) {
		var theLink = $$('#colophon h3 a')[0];
		
		Event.observe(theLink, 'click', function (event) {
			if ($('colophon-text').getStyle('display') == 'none') {
				$('colophon-text').setStyle({'display': 'block'});
				Element.scrollTo($('colophon-text'));
			} else {
				$('colophon-text').setStyle({'display': 'none'});
			}

			//set the height of the wrapper to the height  of the content
			$('wrapper').setStyle({
				height: $('content').getHeight().toString() + 'px'
			});

			//with the wrapper at minimal height measure the viewport height + scrollofset
			var height = document.viewport.getHeight() + document.viewport.getScrollOffsets().top;

			//reset the wrapper height
			$('wrapper').setStyle({
				height: height.toString() + 'px'
			});

			Event.stop(event);
			return false;
		});
	}
});

var i18n;
