Element.extend({
	up: function(selector) {
		var param = selector.match(/^(\w*|\*)(?:#([\w-]+)|\.([\w-]+))?(?:\[(\w+)(?:([*^$]?=)["']?([^"'\]]*)["']?)?])?$/);
		var tagName = this.tagName.toLowerCase();
		//PARAM ARRAY: 0 = full string: 1 = tag; 2 = id; 3 = class; 4 = attribute; 5 = operator; 6 = value;
		if (!param) return;
		param[1] = param[1] || '*';
		// id
		if (param[2]){
			if ((tagName == param[1] || param[1] == '*') && this.getProperty("id") == param[2]) {
				return this;
			} else {
				if ($(this.getParent()).up)
					return $(this.getParent()).up(selector);
				else
					return null;
			}
			
		} else if (param[3]) {
			// class
			if ((tagName == param[1] || param[1] == '*') && this.className == param[3]) {
				return this;
			} else {
				if ($(this.getParent()).up)
					return $(this.getParent()).up(selector);
				else
					return null;
			}
		} else if (tagName == param[1]) {
			return this;					
		} else {
			if (this.getParent()) {
				return $(this.getParent()).up(selector);
			}
		}
	}
});


Fx.InnovaSlide = Fx.Slide.extend({
	initialize: function(el, options){
        this.parent(el, options);
        this.setOptions({'direction' : 'normal'}, this.options);    
    },
    
	vertical: function(){
		this.margin = 'top';
		this.layout = 'height';
		this.offset = this.element.offsetHeight;
		return [this.element.getStyle('margin-top').toInt(), this.wrapper.getStyle('height').toInt()];
	},

	horizontal: function(){
		this.margin = 'left';
		this.layout = 'width';
		this.offset = this.element.offsetWidth;
		return [this.element.getStyle('margin-left').toInt(), this.wrapper.getStyle('width').toInt()];
	},

    normal: function() {
        return [-this.offset, 0]
    },

    reverse: function() {
        return [this.offset, 0]
    },

	slideIn: function(mode, direction){
		return this.start(this[direction || this.options.direction](), [0, this.offset]);
	},

	slideOut: function(mode){
		return this.start([2*this.offset, this.offset], [-this.offset, 0]);
	},

	hide: function(mode){
		this[mode || this.options.mode]();
		return this.set([-this.offset, 0]);
	},

	show: function(mode){
		this[mode || this.options.mode]();
		return this.set([0, this.offset]);
	},
    
	increase: function(){
        var margin = (this.now[0].toInt());
        var height =  (this.now[1].toInt());
        if (window.ie) {
		    this.element.setStyle('margin-'+this.margin, margin+this.options.unit);
        } else {
		    this.wrapper.setStyle(this.layout, height+this.options.unit);
        }
	}

});

function includeCss(cssName){
    var head = $$('head');
    var csss = head.getElements('link');
    var node = (csss.length > 0) ? csss.getLast().getLast() : head.getLast();
    var importer = new Element('link', {'rel': 'stylesheet', 'href' : cssName, 'type':'text/css', 'media' : 'screen'});
    importer.injectAfter(node);
}

Fx.Transitions.extend({
	Jump: function(p, x) {
		var j = x[0] || 3;
		var a = x[1] || -40;
		return p + Math.round(Math.abs(Math.sin(j * p * Math.PI)) * a);
	},
	
	Tremble: function(p, x) {
		a = (x ? x[0] : 30);
		return Math.floor(Math.random() * (a + 1)) - Math.round(a / 2);
	},
	
	Shake: function(p, x) {
		var s = (x ? x[0] : 40);
		return Math.sin(p * Math.PI * s);
	},
	
	Wobble: function(p, x) {
		w = x[0] || 3;
		var r = ((2 * w) + 1) * Math.PI * p;
		return ((-Math.cos(r) + 1) / 2) * c;
	}
});
