//
// Nuestros tips son especiales			
function makiExtendTooltip(objects, options) {
	var positionOffset = { "x":0, "y":0 };
	var className = "";	
	if(options.delay==undefined) options.delay = 800;
	if(options.offsetx==undefined) options.offsetx = 0;
	if(options.offsety==undefined) options.offsety = 0;
	$$(objects).each(function(el) {
		if(el.title) {
			switch(options.position) {
				case "bottom": 
				case "": 
					positionOffset.x = ((el.getStyle("width").toInt()/2)-91) + options.offsetx;
					positionOffset.y = (el.getStyle("height").toInt()-6) + options.offsety;
					break;
				case "right":
					positionOffset.x = ((el.getStyle("width").toInt()+15)) + options.offsetx;
					positionOffset.y = (-10) + options.offsety;
					className = "tipDerecho";
					el.title = "<div class='tipDerechoArrow'></div>" + el.title;
					break;
			}
			new Tips(el, {
				"className": className,
				"fixed": true,
				"showDelay": options.delay,
				"offsets": { "x": positionOffset.x, "y": positionOffset.y }
			});
		}
	});
}
function makiExtendTooltipToRight(objects, cdelay) {
	if(cdelay==undefined) cdelay = 800;
	$$(objects).each(function(el) {
		if(el.title) {
			el.title = "<div class='tipDerechoArrow'></div>" + el.title;
			var nTip = new Tips(el, {
				"className": "tipDerecho",
				"fixed": true,
				"showDelay": cdelay,
				"offsets": { "x": (el.getStyle("width").toInt()+15), "y": -10 }
			});
		}
	});
}
		
//
// Mover un objeto dentro de otro
function makiMoveToDestination(elSource, elDestination, options) {
	if(options==undefined) var options = {};
	if(options.position==undefined) options.position = "inside";
	switch(options.position) {
		case "inside": $(elSource).injectInside(elDestination); break;
		case "before": $(elSource).injectBefore(elDestination); break;
		case "after":  $(elSource).injectAfter(elDestination); break;
		case "top":    $(elSource).injectTop(elDestination); break;
	}	
	$(elSource).setStyle("display", "");
}

//
// auto hover para links (esto si quieres te lo copias tal cual, de regalo)
function autoChangehOverClass(objects) {
	//
	// Tema auto hOver images
	$$(objects).each(function(el) {
		var normalClass = el.getProperty("class");
		var hoverClass = normalClass + "-hover";
		if(el.getProperty("rel")=="selected") {
			el.addClass(hoverClass);
		} else {
			el.addEvent("mouseenter", function() {
				this.addClass(hoverClass);			
			});
			el.addEvent("mouseleave", function() {
				this.removeClass(hoverClass);
			});		
		}
	});
}

function autoChangehOverClassAndStyle(objects) {
	//
	// Tema auto hOver images
	$$(objects).each(function(el) {
		var normalClass = el.getProperty("class");
		var hoverClass = normalClass + "-hover";
		var selectedClass = normalClass + "-selected";
		if(el.getProperty("rel")=="selected") {
			el.addClass(selectedClass);
			if(el.get("selectedStyles")!="") {
				el.setStyles(eval("(" + el.get("selectedStyles") + ")"));
			} else {
				el.setStyles(eval("(" + el.get("hoverStyles") + ")"));
			}
		} else {
			el.setStyles(eval("(" + el.get("normalStyles") + ")"));
			el.addEvent("mouseenter", function() {
				this.addClass(hoverClass);
				this.setStyles(eval("(" + this.get("hoverStyles") + ")"));
			});
			el.addEvent("mouseleave", function() {
				this.removeClass(hoverClass);
				this.setStyles(eval("(" + this.get("normalStyles") + ")"));
			});		
		}
	});
}

//
// auto hover para imágenes con preload (esto si quieres te lo copias tal cual, de regalo)
function autohOverImages(objects) {			
	//
	// Tema auto hOver images
	var autohOverPreload = [];
	$$(objects).each(function(img) {
		var src = img.getProperty("src");
		var extension = src.substring(src.lastIndexOf("."),src.length)
		img.addEvent("mouseenter", function() { img.setProperty("src",src.replace(extension,"-hover" + extension)); });
		img.addEvent("mouseleave", function() { img.setProperty("src",src); });
		autohOverPreload.push(src.replace(extension,"-hover" + extension));
	});
	new Asset.images(autohOverPreload);	
}
			
//
// auto hover input boxes
function autohOverInputBoxes(objects) {
	var boxAutohOverPreload = [];
	$$(objects).each(function(el) {
		//
		// Config & init
		var usesClass = el.getProperty("class");
		var src = el.getProperty("rel");
		var extension = src.substring(src.lastIndexOf('.'),src.length);
		var hOverIMG = src.replace(extension,'-hover' + extension);
		boxAutohOverPreload.push(hOverIMG);
		el.setStyle("background-image", "url('" + src + "')");
		//
		// Eventos
		el.addEvent("focus", function() {
			this.setStyle("background-image", "url('" + hOverIMG + "')");
			this.removeClass(usesClass);
			this.addClass(usesClass + "Focus");
		});
		el.addEvent("blur", function() {
			this.setStyle("background-image", "url('" + this.getProperty("rel") + "')");
			this.removeClass(usesClass + "Focus");
			this.addClass(usesClass);
		});
	});
	new Asset.images(boxAutohOverPreload);
}

//
// Asignar ids según su name -> cambiar els a objects $$
function makiExtendAsignIdByName(els) {
	els.each(function(el) {
		el.id = el.name;
	});
}

//
// Alinear a su contenedor
function valignToCenter(me, container) {
    me.setStyles({      
      top: ((container.getCoordinates().height/2)-(me.getCoordinates().height/2))
	});
}
function halignToCenter(me, container) {
    me.setStyles({
      left: ((container.getCoordinates().width/2)-(me.getCoordinates().width/2))
	});	
}

//
// Un parpadeo pulse
var PulseFade = new Class({
			
	//implements
	Implements: [Options,Events],

	//options
	options: {
		min: 0,
		max: 1,
		duration: 200,
		times: 5
	},
	
	//initialization
	initialize: function(el,options) {
		//set options
		this.setOptions(options);
		this.element = $(el);
		this.times = 0;
	},
	
	//starts the pulse fade
	start: function(times) {
		if(!times) times = this.options.times * 2;
		this.running = 1;
		this.fireEvent('start').run(times -1);
	},
	
	//stops the pulse fade
	stop: function() {
		this.running = 0;
		this.fireEvent('stop');
	},
	
	//runs the shizzle
	run: function(times) {
		//make it happen
		var self = this;
		var to = self.element.get('opacity') == self.options.min ? self.options.max : self.options.min;
		self.fx = new Fx.Tween(self.element,{
			duration: self.options.duration / 2,
			onComplete: function() {
				self.fireEvent('tick');
				if(self.running && times)
				{
					self.run(times-1);
				}
				else
				{
					self.fireEvent('complete');
				}
			}
		}).start('opacity',to);
	}
});

//
// Right
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

//
// Left
function Left(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(0, n);
    }
}

//
// Trim
function trim(str) {
	return str.replace(/^(\s|\&nbsp;)*|(\s|\&nbsp;)*$/g,"");
}

//
//IsNumeric
function IsNumeric(input){
    var RE = /^-{0,1}\d*\,{0,1}\d+$/;
    return (RE.test(input));
}

