/*
 * jqModal - Minimalist Modaling with jQuery
 *   (http://dev.iceburg.net/jquery/jqmodal/)
 *
 * Copyright (c) 2007,2008 Brice Burgess <bhb@iceburg.net>
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 * 
 * $Version: 16/10/2008 +r14 (versió personalitzada per a l'Ajuntament de Barcelona)
 */
 
 
(function($) {
	
	var lang = $("html").attr("lang") || $("html").attr("xml:lang") || 'ca';
	var b = '';
	
	jQuery.each(jQuery.browser, function(i, val) {
		if (val) b = i;
	});
	
	$.fn.jqm = function(o) {
		var p = {
			ajax: '@href',
			ajaxText: '',
			closeButton: true,
			closeClass: 'jqm-close',
			overlay: 50,
			overlayClass: 'jqm-overlay',
			target: F,
			toTop: F,
			trigger: '.jqm',
			onShow: F,
			onHide: F,
			onLoad: F
		};
		
		return this.each (function() {
			if (this._jqm)
				return H[this._jqm].c = $.extend({},H[this._jqm].c,o);
			s++;
			this._jqm = s;
			
			H[s] = {
				c:$.extend(p,$.jqm.params,o),
				a:F,
				w:$(this)
					.addClass('jqm-window')
					.addClass('jqmID'+s)
					.jqmViewport()
					.jqmAddTrigger(p.trigger),
				s:s
			};
		});
	};

	$.fn.jqmCloseButton = function(e,cb,cc) {
		if (cb) {
			switch (lang) {
				case 'es':
					var txt = "Cerrar";
					break;
				case 'en':
					var txt = "Close";
					break;
				default:
					var txt = "Tancar";
			}
			var bt = $(document.createElement('input'));
				bt.attr({
					type: 'button',
					className: cc,
					value: txt
				}).bind('click', function() { 
					$(e).jqmHide();
				});
			var ct = $(document.createElement('p'));
				ct.attr({
					className: 'jqm-content-close'
				}).append(bt);
				
			$(this).prepend(ct);
		}
	};
	$.fn.jqmAddClose = function(e) {
		return hs(this,e,'jqmHide');
	};
	$.fn.jqmAddTrigger = function(e) {
		return hs(this,e,'jqmShow');
	};
	$.fn.jqmShow = function(t) {
		return this.each( function() {
			$.jqm.open(this._jqm,t);
		});
	};
	$.fn.jqmHide = function(t) {
		return this.each( function() {
			$.jqm.close(this._jqm,t);
		});
	};
	$.fn.jqmViewport = function() {
		var hCss = ( $(this).css('height') != 'auto' ) ? parseInt($(this).css('height')) : 0;
		var vH = parseInt($(window).height());
			vH = vH-Math.round((vH>800)?vH*50/100:vH*15/100);
		return (hCss>vH || hCss==0) ? $(this).height(vH) : $(this).height(hCss);
	};

	$.jqm = {
		hash: {},
		open: function(s,t) {
			var h = H[s];
			var c = h.c;
			var cc = '.'+c.closeClass;
			var co = 0;
			var sm = 0;
			var z = (parseInt(h.w.css('z-index')));
				z = (z>0)?z:3000;
				
			o = $('<div></div>').css({
				position: 'fixed',
				width: '100%',
				height: '100%',
				top: 0,
				left: 0,
				'z-index': z-1,
				opacity: c.overlay/100
			});
			
			if (h.a) return F;
			h.t = t;
			h.a = true;
			h.w.css('z-index',z);
			h.w.jqmCloseButton(h.w,c.closeButton,c.closeClass);
			
			if (b=='opera') $('object,select').not(h.w+':has(object,select)').css('display', 'none');
			else  $('object,select').not(h.w+':has(object,select)').css('visibility', 'hidden');
			
			h.w.mousewheel(function(e, delta) {
				if (b=='opera') {
					if (delta > 0) {
						this.scrollTop += delta - 15;
					} else if (delta < 0) {
						this.scrollTop += delta + 15;
					}
				} else {
					if (delta > 0) {
						this.scrollTop -= delta + 15;
					} else if (delta < 0) {
						this.scrollTop -= delta - 15;
					}
				}
				e.preventDefault();
			});
			
			if (!A[0]) L('bind');
			A.push(s);
			if (c.overlay > 0) h.w.jqmAddClose(o);
			else o = F;
			h.o = (o)?o.addClass(c.overlayClass).prependTo('body'):F;
			h.o.mousewheel(function(e, delta) { e.preventDefault(); });
		
			if (ie6) {
				$('body').css({
					width: '100%',
					height: '100%'
				});
				if (o) {
					o = o.css({position:'absolute'})[0];
					for(var y in {Top:1,Left:1}) o.style.setExpression(y.toLowerCase(),"(_=(document.documentElement.scroll"+y+" || document.body.scroll"+y+"))+'px'");
				}
			}
			if (c.ajax) {
				var r = c.target||h.w;
					r = (typeof r == 'string')?$(r,h.w):$(r);
				var u = c.ajax;
					u = (u.substring(0,1) == '@')?$(t).attr(u.substring(1)):u;

				if (!u.match(/^#/)) {
					r.html(c.ajaxText).load(u,function() {
						if (c.onLoad)
							c.onLoad.call(this,h);
						h.w.jqmCloseButton(this,c.closeButton,c.closeClass);
					});
				}
			}
			if (c.toTop && h.o) {
				h.w.before('<span id="jqmP'+h.w[0]._jqm+'"></span>').insertAfter(h.o);
			}
			(c.onShow)?c.onShow(h).focus():h.w.show().focus();
			
			$('input,select,textarea,a')
				.bind('focus', function() {
					$('input,select,textarea,a', h.w)[0].focus();
				});
			
			return F;
		},
		close: function(s) {
			var h = H[s];
			var c = h.c;
			
			h.w.find('.'+c.closeClass)
				.parent()
				.remove();
			
			if (b=='opera') $('object,select').not(h.w+':has(object,select)').css('display', 'block');
			else $('object,select').not(h.w+':has(object,select)').css('visibility', 'visible');
			
			if (!h.a) return F;
			h.a = F;
			if (A[0]) {
				A.pop();
				if (!A[0]) L('unbind');
			}
			if (h.c.toTop && h.o) {
				$('#jqmP'+h.w[0]._jqm).after(h.w).remove();
			}
			if (h.c.onHide) {
				h.c.onHide(h);
			} else {
				h.w.hide();
				if (h.o) { h.o.hide(); } //h.o.remove() -> Opera 9.x no refresca bé
			}
			if (ie6) {
				$('body').css({
					width: 'auto',
					height: 'auto'
				});
			}
			$('input,select,textarea,a')
				.unbind('focus');
				
			return F;
		},
		params: {}
	};
	
	var s 	= 0;
	var H 	= $.jqm.hash;
	var A 	= [];
	var ie6 = $.browser.msie&&($.browser.version == "6.0");
	var F 	= false;
	
	var L = function(t) {
		$()[t]("keypress",m)[t]("keydown",m)[t]("mousedown",m);
	};
	var m = function(e) {
		var h = H[A[A.length-1]];
		var r = (!$(e.target).parents('.jqmID'+h.s)[0]);
		if (e.keyCode==27) {
			$('.jqmID'+h.s).jqmHide();
		} else if (r) {
			f(h);
		}
		return !r;
	};
	var f = function(h) {
		try {
			if ($('input,select,textarea,a', h.w).length > 0)  {
				$('input,select,textarea,a', h.w)[0].focus();
			}
		} catch(_) {}
	};
	var hs = function(w,t,c) {
		return w.each( function() {
			var s = this._jqm;
			$(t).each(function() {
				if (!this[c]) {
					this[c] = [];
					$(this).click( function() {
						for(var i in {jqmShow:1,jqmHide:1})
						for(var s in this[i]) {
							if (H[this[i][s]]) H[this[i][s]].w[i](this);
						}
						return F;
					});
				}
				this[c].push(s);
			});
		});
	};
})(jQuery);


/*
 * Copyright (c) 2006 Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 *
 * $LastChangedDate: 2007-12-20 09:02:08 -0600 (Thu, 20 Dec 2007) $
 * $Rev: 4265 $
 *
 * Version: 3.0
 * 
 * Requires: $ 1.2.2+
 */

eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(5($){$.6.j.4={L:5(){9 b=$.6.j.4.i;7($.8.f)$(2).o(\'y.4\',5(a){$.d(2,\'h\',{x:a.x,l:a.l,s:a.s,r:a.r})});7(2.q)2.q(($.8.f?\'v\':\'4\'),b,n);m 2.w=b},D:5(){9 a=$.6.j.4.i;$(2).k(\'y.4\');7(2.u)2.u(($.8.f?\'v\':\'4\'),a,n);m 2.w=5(){};$.A(2,\'h\')},i:5(a){9 c=U.T.S.P(O,1);a=$.6.N(a||M.6);$.t(a,$.d(2,\'h\')||{});9 b=0,K=J;7(a.e)b=a.e/I;7(a.p)b=-a.p/3;7($.8.H)b=-a.e;a.d=a.d||{};a.G="4";c.z(b);c.z(a);g $.6.F.E(2,c)}};$.Q.t({4:5(a){g a?2.o("4",a):2.R("4")},C:5(a){g 2.k("4",a)}})})(B);',57,57,'||this||mousewheel|function|event|if|browser|var||||data|wheelDelta|mozilla|return|mwcursorposdata|handler|special|unbind|pageY|else|false|bind|detail|addEventListener|clientY|clientX|extend|removeEventListener|DOMMouseScroll|onmousewheel|pageX|mousemove|unshift|removeData|jQuery|unmousewheel|teardown|apply|handle|type|opera|120|true|returnValue|setup|window|fix|arguments|call|fn|trigger|slice|prototype|Array'.split('|'),0,{}))

