Effect.MoveMy = Class.create();
Object.extend(Object.extend(Effect.MoveMy.prototype, Effect.Base.prototype), {
  initialize: function(element) {
    this.element = $(element);
    var options = Object.extend({
      x:    0,
      mode: 'relative'
    }, arguments[1] || {});
    this.start(options);
  },
  setup: function() {
    this.element.makePositioned();
    this.originalLeft = parseFloat(this.element.getStyle('left') || '0');
    if(this.options.mode == 'absolute') {
      this.options.x = this.options.x - this.originalLeft;
    }
  },
  update: function(position) {
    this.element.setStyle({
      left: Math.round(this.options.x  * position + this.originalLeft) + 'px'
    });
  }
});

		//transition: Effect.Transitions.exponential = function(pos) {return 1-Math.pow(1-pos,2);}
		//transition: Effect.Transitions.slowstop = function(pos) {return 1-Math.pow(0.5,20*pos);}

var Popup = {
  open: function(options)
  {
    this.options = {
      url: '#',
      width: 600,
      height: 500,
      name:"_blank",
      location:"no",
      menubar:"no",
      toolbar:"no",
      status:"yes",
      scrollbars:"yes",
      resizable:"yes",
      left:"",
      top:"",
      normal:false
    }
    Object.extend(this.options, options || {});

    if (this.options.normal){
        this.options.menubar = "yes";
        this.options.status = "yes";
        this.options.toolbar = "yes";
        this.options.location = "yes";
    }

    this.options.width = this.options.width < screen.availWidth?this.options.width:screen.availWidth;
    this.options.height=this.options.height < screen.availHeight?this.options.height:screen.availHeight;
    var openoptions = 'width='+this.options.width+',height='+this.options.height+',location='+this.options.location+',menubar='+this.options.menubar+',toolbar='+this.options.toolbar+',scrollbars='+this.options.scrollbars+',resizable='+this.options.resizable+',status='+this.options.status
    if (this.options.top!="")openoptions+=",top="+this.options.top;
    if (this.options.left!="")openoptions+=",left="+this.options.left;
    window.open(this.options.url, this.options.name,openoptions );
    return false;
  }
}


Effect.MoveAndResizeTo = Class.create();
Object.extend(Object.extend(Effect.MoveAndResizeTo.prototype, Effect.Base.prototype), {
	initialize: function(element, toTop, toLeft, toWidth, toHeight) {
    	this.element      = $(element);
    	this.toTop        = toTop;
    	this.toLeft       = toLeft;
    	this.toWidth      = toWidth;
    	this.toHeight     = toHeight;
    	this.originalTop  = parseFloat(Element.getStyle(this.element,'top')  || 0);
    	this.originalLeft = parseFloat(Element.getStyle(this.element,'left') || 0);
    	this.originalWidth  = parseFloat(Element.getStyle(this.element,'width')  || 0);
    	this.originalHeight = parseFloat(Element.getStyle(this.element,'height') || 0);
    	this.effectiveTop = this.toTop;
    	this.effectiveLeft = this.toLeft;
    	this.effectiveWidth = this.toWidth 
            - parseFloat(Element.getStyle(this.element,'margin-left') || 0) 
            - parseFloat(Element.getStyle(this.element,'margin-right') || 0);
    	this.effectiveHeight = this.toHeight
            - parseFloat(Element.getStyle(this.element,'margin-top') || 0) 
            - parseFloat(Element.getStyle(this.element,'margin-bottom') || 0);
    	this.options = arguments[5] || {};
    	if (this.effectiveWidth < 0) this.effectiveWidth = 0;
    	if (this.effectiveHeight < 0) this.effectiveHeight = 0;
    	if (this.originalTop == this.effectiveTop &&
           	this.originalLeft == this.effectiveLeft &&
        	this.originalWidth == this.effectiveWidth &&
        	this.originalHeight == this.effectiveHeight) {return;}
    	this.start(this.options);},
  	update: function(position) {
    	topd  = this.effectiveTop * (position) + this.originalTop * (1 - position);
    	leftd = this.effectiveLeft * (position) + this.originalLeft * (1 - position);
    	widthd  = this.effectiveWidth * (position) + this.originalWidth * (1 - position);
    	heightd = this.effectiveHeight * (position) + this.originalHeight * (1 - position);
    	this.setPosition(topd, leftd, widthd, heightd);},
  	setPosition: function(topd, leftd, widthd, heightd) {
    	this.element.style.top = topd+'px';
    	this.element.style.left = leftd+'px';
    	this.element.style.width = widthd+'px';
    	this.element.style.height = heightd+'px';}
});

Effect.PhaseIn = function(element) {
  element = $(element);
  new Effect.BlindDown(element, arguments[1] || {});
  new Effect.Appear(element, arguments[2] || arguments[1] || {});
}

Effect.PhaseOut = function(element) {
  element = $(element);
  new Effect.Fade(element, arguments[1] || {});
  new Effect.BlindUp(element, arguments[2] || arguments[1] || {});
}

Effect.Phase = function(element) {
  element = $(element);
  if (element.style.display == 'none')
    new Effect.PhaseIn(element, arguments[1] || {}, arguments[2] || arguments[1] || {});
  else new Effect.PhaseOut(element, arguments[1] || {}, arguments[2] || arguments[1] || {});
}

// CHANGES MADE FROM BLINDUP
// CHANGE from 'scaleX: false,' to scaleY: false

Effect.BlindLeft = function(element) {
  element = $(element);
  element.makeClipping();
  return new Effect.Scale(element, 0,
    Object.extend({ scaleContent: false, 
      scaleY: false,                     
      restoreAfterFinish: true,
      afterFinishInternal: function(effect) {
        effect.element.hide().undoClipping();
      } 
    }, arguments[1] || {})
  );
}

// CHANGES MADE FROM BLINDDOWN
// CHANGE from 'scaleX: false,' to scaleY: false
// CHANGE afterSetup function statement's "makeClipping().setStyle({height: '0px'})" to width: '0px'

Effect.BlindRight = function(element) {
  element = $(element);
    var elementDimensions = element.getDimensions();
  return new Effect.Scale(element, 100, Object.extend({ 
    scaleContent: false, 
    scaleY: false,
    scaleFrom: 0,
    scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
    restoreAfterFinish: true,
    afterSetup: function(effect) {
      effect.element.makeClipping().setStyle({width: '0px'}).show(); 
    },  
    afterFinishInternal: function(effect) {
      effect.element.undoClipping();
    }
  }, arguments[1] || {}));
}

Effect.Center = function(element)
{
    try
    {
        element = $(element);
    }
    catch(e)
    {
        return;
    }

    var my_width  = 0;
    var my_height = 0;

    if ( typeof( window.innerWidth ) == 'number' )
    {

        my_width  = window.innerWidth;
        my_height = window.innerHeight;
    }
    else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
    {

        my_width  = document.documentElement.clientWidth;
        my_height = document.documentElement.clientHeight;
    }
    else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
    {

        my_width  = document.body.clientWidth;
        my_height = document.body.clientHeight;
    }

    element.style.position = 'absolute';
    element.style.display  = 'block';
    element.style.zIndex   = 99;

    var scrollY = 0;

    if ( document.documentElement && document.documentElement.scrollTop )
    {
        scrollY = document.documentElement.scrollTop;
    }
    else if ( document.body && document.body.scrollTop )
    {
        scrollY = document.body.scrollTop;
    }
    else if ( window.pageYOffset )
    {
        scrollY = window.pageYOffset;
    }
    else if ( window.scrollY )
    {
        scrollY = window.scrollY;
    }

    var elementDimensions = Element.getDimensions(element);

    var setX = ( my_width  - elementDimensions.width  ) / 2;
    var setY = ( my_height - elementDimensions.height ) / 2 + scrollY;

    setX = ( setX < 0 ) ? 0 : setX;
    setY = ( setY < 0 ) ? 0 : setY;

    element.style.left = setX + "px";
    element.style.top  = setY + "px";

}

Effect.SlideRight = function(element) {
  element = $(element);
  Element.cleanWhitespace(element);
  // SlideDown need to have the content of the element wrapped in a container element with fixed height!
  var oldInnerRight = Element.getStyle(element.firstChild, 'right');
  var elementDimensions = Element.getDimensions(element);
  return new Effect.Scale(element, 100, Object.extend({ 
    scaleContent: false, 
    scaleY: false, 
    scaleFrom: 0,
    scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
    restoreAfterFinish: true,
    afterSetup: function(effect) { with(Element) {
      makePositioned(effect.element);
      makePositioned(effect.element.firstChild);
      if(window.opera) setStyle(effect.element, {top: ''});
      makeClipping(effect.element);
      setStyle(effect.element, {width: '0px'});
      show(element); }},
    afterUpdateInternal: function(effect) { with(Element) {
      setStyle(effect.element.firstChild, {right:
        (effect.dims[0] - effect.element.clientWidth) + 'px' }); }},
    afterFinishInternal: function(effect) { with(Element) {
      undoClipping(effect.element); 
      undoPositioned(effect.element.firstChild);
      undoPositioned(effect.element);
      setStyle(effect.element.firstChild, {right: oldInnerRight}); }}
    }, arguments[1] || {})
  );
}

Effect.SlideLeft = function(element) {
  element = $(element);
  Element.cleanWhitespace(element);
  var oldInnerRight = Element.getStyle(element.firstChild, 'right');
  return new Effect.Scale(element, 0, 
   Object.extend({ scaleContent: false, 
    scaleY: false, 
    scaleMode: 'box',
    scaleFrom: 100,
    restoreAfterFinish: true,
    beforeStartInternal: function(effect) { with(Element) {
      makePositioned(effect.element);
      makePositioned(effect.element.firstChild);
      if(window.opera) setStyle(effect.element, {top: ''});
      makeClipping(effect.element);
      show(element); }},  
    afterUpdateInternal: function(effect) { with(Element) {
      setStyle(effect.element.firstChild, {right:
        (effect.dims[0] - effect.element.clientWidth) + 'px' }); }},
    afterFinishInternal: function(effect) { with(Element) {
        [hide, undoClipping].call(effect.element); 
        undoPositioned(effect.element.firstChild);
        undoPositioned(effect.element);
        setStyle(effect.element.firstChild, {right: oldInnerRight}); }}
   }, arguments[1] || {})
  );
}

Effect.Bounce = Class.create();
Object.extend(Object.extend(Effect.Bounce.prototype, Effect.Base.prototype), {
  initialize: function(element) {
    this.element = $(element);
    var options = Object.extend({
        x:0, y:200,
        acceleration: 9.81,
        transition: Effect.Transitions.linear,
        mode: 'relative'
    }, arguments[1] || {});
    this.start(options);
  },
  setup: function() {
    Element.makePositioned(this.element);
    this.originalLeft = parseFloat(Element.getStyle(this.element,'left') || '0');
    this.originalTop  = parseFloat(Element.getStyle(this.element,'top')  || '0');
    if(this.options.mode == 'absolute') {
      this.options.x = this.options.x - this.originalLeft;
    }
  },
  mytransition: function(pos){
    var temp = (pos < 0.5 ? 0.5-pos : 0.5+(1-pos)); 
    return (pos < 0.5 ? this.options.acceleration/2*temp*temp : this.options.acceleration/2*(1-temp)*(1-temp) ) *8 /this.options.acceleration - 1;
  },
  update: function(position) {
    Element.setStyle(this.element, {
        left: this.options.x  * position + this.originalLeft + 'px',
    top:  this.originalTop + this.options.y * this.mytransition(position)   + 'px'
    });
  }
});


