/* -------------------------------------------------------------- 
	
	TURISME.js
	* Funciones globales
	
-------------------------------------------------------------- */

	
/* EXTENSIONES DE JQUERY
-------------------------------------------------------------- */
	
	jQuery.fn.extend({
		
		exists : function() {
			return this.length > 0;
		},
		
		check : function() {
			return this.each(function() {
				this.checked = true;
			});
		},
		
		uncheck : function() {
			return this.each(function() {
				this.checked = false;
			});
		},
		
		enable : function() {
			return this.each(function() {
				$(this).removeAttr('disabled').removeClass('disabled');
			});
		},
		
		disable : function() {
			return this.each(function() {
				$(this).attr('disabled','disabled').addClass('disabled');
			});
		},
		
		reset : function() {
			return this.each(function() {
				$(this).val('');
			});
		},
		
		innerWrap : function() {
			var a, args = arguments;
			return this.each(function() {
				if (!a)
					a = jQuery.clean(args, this.ownerDocument);
				var b = a[0].cloneNode(true),
				    c = b;
				while ( b.firstChild )
					b = b.firstChild;
				jQuery.each(this.childNodes, function(i, node) { 
					b.appendChild(node); 
				});
				jQuery(this).empty().append(c);
			});
		}
		
		
	});
	
/* VARIABLES GLOBALES
-------------------------------------------------------------- */
	
	var animEnabled = true;
	
	
	
/* MENU
-------------------------------------------------------------- */
	
	$.fn.menu = function() {
		return this.each(function() {
			if (animEnabled) {
				$(this).superfish({
					hoverClass: 'hover',
					delay: 500,
					animation: { height: 'show' }
				});
			}
			else {
				$(this).superfish({
					hoverClass: 'hover',
					delay: 500,
					speed: 1,
					animation: { height: 'show' }
				});
			}
		});
	};
	
	
	
/* 
-------------------------------------------------------------- */
	
	$.fn.highlight = function() {
		return this.each(function() {
			$(this).addClass('selected');
		});
	};
	
	$.fn.unhighlight = function() {
		return this.each(function() {
			$(this).removeClass('selected');
		});
	};
	
	$.fn.activate = function() {
		return this.each(function() {
			if (animEnabled) {
				$(this).animate({ height: 'show', opacity: 'show' });
			}
			else {
				$(this).show();
			}
		});
	};
	
	$.fn.deactivate = function() {
		return this.each(function() {
			if (animEnabled) {
				$(this).animate({ height: 'hide', opacity: 'hide' });
			}
			else {
				$(this).hide();
			}
		});
	};
	
	
	
	
	
/* TOOLTIPS
-------------------------------------------------------------- */
	
	$.fn.tooltip = function(opts) {
		
		opts = $.extend({fade: false, gravity: 's'}, opts || {});
		var tip = null, cancelHide = false;
		
		this.hover(function() {
			
			$.data(this, 'cancel.tooltip', true);
			
			var tip = $.data(this, 'active.tooltip');
			if (!tip) {
				tip = $('<div class="tooltip"><div class="tooltip_wrapper">' + $(this).attr('title') + '</div></div>');
				tip.css({position: 'absolute', zIndex: 100000});
				$(this).attr('title', '');
				$.data(this, 'active.tooltip', tip);
			}
			
			var pos = $.extend({}, $(this).offset(), {width: this.offsetWidth, height: this.offsetHeight});
			tip.remove().css({top: 0, left: 0, visibility: 'hidden', display: 'block'}).appendTo(document.body);
			var actualWidth = tip[0].offsetWidth, actualHeight = tip[0].offsetHeight;
			
			switch (opts.gravity.charAt(0)) {
				case 'n':
					tip.css({top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2}).addClass('tooltip_north');
					break;
				case 's':
					tip.css({top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2}).addClass('tooltip_south');
					break;
				case 'e':
					tip.css({top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth}).addClass('tooltip_east');
					break;
				case 'w':
					tip.css({top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width}).addClass('tooltip_west');
					break;
			}
			
			if (opts.fade) {
				tip.css({opacity: 0, display: 'block', visibility: 'visible'}).animate({opacity: 1});
			} else {
				tip.css({visibility: 'visible'});
			}
			
		}, function() {
			$.data(this, 'cancel.tooltip', false);
			var self = this;
			setTimeout(function() {
				if ($.data(this, 'cancel.tooltip')) return;
				var tip = $.data(self, 'active.tooltip');
				if (opts.fade) {
					tip.stop().fadeOut(function() { $(this).remove(); });
				} else {
					tip.remove();
				}
			}, 100);
			
		});
		
	};
	
	
	
	
	
/* 
-------------------------------------------------------------- */
	
	
	
	
	
	
	
	
	
	
/* 
-------------------------------------------------------------- */
	
	
	
	
	
	
	
	
	
/* 
-------------------------------------------------------------- */
	
	
	
	
	
	
	
/* 
-------------------------------------------------------------- */
	
	
	
	
	
	
	
/* 
-------------------------------------------------------------- */
	
	
	

/* FIN
-------------------------------------------------------------- */
