function _(messageId) {
	return typeof(translate[messageId]) === 'undefined' ? messageId : translate[messageId];
}

var Core = {

	/**
	 * Zmiana obrazka po wskazaniu kursorem.
	 */
	hoverImage: function() {
		$('img.hoverImage, input.hoverImage').mouseenter(function(){
			if ($(this).hasClass('active') === false) {
				$(this).attr('src', $(this).attr('src').replace('.gif', '_on.gif'));
				$(this).attr('src', $(this).attr('src').replace('.jpg', '_on.jpg'));
				$(this).attr('src', $(this).attr('src').replace('.png', '_on.png'));
			}
		}).mouseleave(function(){
			if ($(this).hasClass('active') === false) {
				$(this).attr('src', $(this).attr('src').replace('_on.gif', '.gif'));
				$(this).attr('src', $(this).attr('src').replace('_on.jpg', '.jpg'));
				$(this).attr('src', $(this).attr('src').replace('_on.png', '.png'));
			}
		});
	},

	/**
	 * Opis w polach tekstowych.
	 */
	inputDescription: function(form, element, description) {
		if (element.val() === '') {
			element.val(description);
		}

		element.focus(function(){
			if ($(this).val() === description) {
				$(this).val('');
			}
		}).blur(function(){
			if ($(this).val() === '') {
				$(this).val(description);
			}
		});

		form.submit(function(){
			if (element.val() === description) {
				element.val('');
			}
		});
	},

	/**
	 * Otwiera okno popup.
	 */
	openWindow : function( href, width, height ) {
		return window.open(href, 'window', 'width=' + (width | 650) + ', height=' + (height | 650) +
			', menubar=no, toolbar=no, location=no, scrollbars=yes, resizable=no, status=no');
	},

	/**
	 * Blokoda ponownego wysłania formularz.
	 */
	preventSubmit: function(element) {
		element.submit(function(){

			if ($(this).data('submitted') === true) {
				alert('Formularz został już wysłany. Proszę czekać...');

				return false;
			}
			else
				$(this).data('submitted', true);

			return true;
		});
	}

};

$(document).ready(function() {

	// Zamień pierwszą literę oraz każdą przed "_" na wielkie.
	var controller = Core.controller.replace(/(^|_)([a-z])/g, function(m, p1, p2) {
		return p1 + p2.toUpperCase();
	});

	Core.init();

	if (window[controller] != undefined) {

		if (typeof window[controller]['init'] == 'function') {
			window[controller]['init']();
		}

		if (typeof window[controller][Core.action] == 'function') {
			window[controller][Core.action]();
		}
	}

});

