/*
 * Ajuntament de Barcelona - Javascript Open Window (JOW)
 * www.bcn.cat / www.bcn.es
 *
 * Revision: jquery-jow.js | nº3, 2008-12-17 14:00h
*/


$(document).ready( function() {
	if ($.fn.jow) {
		$.fn.jow($.jowOptions);
	}
});

(function($) {

	$.extend($.fn, {

		jow : function(opts) {
			var config = {
				lang			: $("html").attr("lang") || $("html").attr("xml:lang") || 'ca',
				selector	: 'a.obrir-finestra, a.open-window'
			};
			var options = $.extend({
				pathImg		: 'http://www.bcn.cat/imatges'
			}, opts || {});

			$.fn.warning = function() {
				switch(config.lang) {
					case 'es':
						return "Se abre en ventana nueva";
						break;
					case 'en':
						return "Open new window";
						break;
					default:
						return "S'obre en finestra nova";
				}
			}

			return $(config.selector).each( function() {
				if ($(this).children().is("img"))
					$(this).children("img").attr("alt", $(this).children("img").attr("alt")+' ('+ $(this).warning() + ')');
				else
					$(this).append(' <img src="'+ options.pathImg +'/ico-obrir-finestra.png" alt="'+ $(this).warning() +'" />');

				$(this).bind('click', function(e) {
					//$(this).attr({target: '_blank'});
					window.open($(this).attr("href"), '', 'menubar, location, toolbar, directories, status, resizable, scrollbars');
					e.preventDefault();
				});
			});
		}

	});

})(jQuery);

