document.observe("dom:loaded", function() 
{  
  if (!Prototype.Browser.IE) 
  {
    var menuItems = $$('#header .menu a');
	
  	menuItems.each(function(menuItem)
  	{
  	  Element.observe(menuItem, 'mouseover', function(e) 
  		{			
  			new Effect.Morphbgpos(this, {
        	style: 'background-position: 10px -50px;', 
        	duration: .2
        });
        Event.stop(e);
  		});
		
  		Element.observe(menuItem, 'mouseout', function(e) 
  		{			
  			new Effect.Morphbgpos(this, {
        	style: 'background-position: 10px 0px;', 
        	duration: .2
        });
        Event.stop(e);
  		});
  	});
  } 
	
	var links = $$('a');
	
	links.each(function(link)
	{
	  /*
		if (!link.hasClassName('noFade'))
		{
			Element.observe(link, 'mouseover', function(e) 
			{
				new Effect.Morph(link, {style: 'color: #ec008c', duration: 0.2});
				Event.stop(e);
			});

			Element.observe(link, 'mouseout', function(e) 
			{
				new Effect.Morph(link, {style: 'color: #00acec', duration: 0.2});
				Event.stop(e);
			});
		}
		*/
		
		if (link.hasClassName('blank'))
		{
			Element.observe(link, 'click', function(e) 
			{
				window.open(link.href);
				Event.stop(e);
			});
		}
		
		if (link.hasClassName('scroll'))
		{
      Element.observe(link, 'click', function(e)
      {
        var target = link.hash.replace('#', '');

        // Scroll to appropriate section.
    		new Effect.ScrollTo($(target), 
    		{ 
    		  duration: 1.0, 
    		  transition: Effect.Transitions.EaseFromTo
    		});
    		Event.stop(e);
      })
	  }
	});

  if (globals.isCommentPreview)
  {
    Element.scrollTo('headingPreview');
  }
});


/* 
transitions.js
Based on Easing Equations v2.0 
(c) 2003 Robert Penner, all rights reserved. 
This work is subject to the terms in http://www.robertpenner.com/easing_terms_of_use.html
Adapted for Scriptaculous by Ken Snyder (kendsnyder ~at~ gmail ~dot~ com) June 2006 
*/

// Overshooting Transitions 

// Elastic (adapted from "EaseOutElastic") 
Effect.Transitions.Elastic = function(pos) { 
    return -1*Math.pow(4,-8*pos) * Math.sin((pos*6-1)*(2*Math.PI)/2) + 1; 
}; 
// SwingFromTo (adapted from "BackEaseInOut") 
Effect.Transitions.SwingFromTo = function(pos) { 
    var s = 1.70158; 
    if ((pos/=0.5) < 1) return 0.5*(pos*pos*(((s*=(1.525))+1)*pos - s)); 
    return 0.5*((pos-=2)*pos*(((s*=(1.525))+1)*pos + s) + 2); 
}; 
// SwingFrom (adapted from "BackEaseIn") 
Effect.Transitions.SwingFrom = function(pos) { 
    var s = 1.70158; 
    return pos*pos*((s+1)*pos - s); 
}; 
// SwingTo (adapted from "BackEaseOut") 
Effect.Transitions.SwingTo = function(pos) { 
    var s = 1.70158; 
    return (pos-=1)*pos*((s+1)*pos + s) + 1; 
};


// Bouncing Transitions 

// Bounce (adapted from "EaseOutBounce") 
Effect.Transitions.Bounce = function(pos) { 
    if (pos < (1/2.75)) { 
        return (7.5625*pos*pos); 
    } else if (pos < (2/2.75)) { 
        return (7.5625*(pos-=(1.5/2.75))*pos + .75); 
    } else if (pos < (2.5/2.75)) { 
        return (7.5625*(pos-=(2.25/2.75))*pos + .9375); 
    } else { 
        return (7.5625*(pos-=(2.625/2.75))*pos + .984375); 
    } 
}; 
// BouncePast (new creation based on "EaseOutBounce") 
Effect.Transitions.BouncePast = function(pos) { 
    if (pos < (1/2.75)) { 
        return (7.5625*pos*pos); 
    } else if (pos < (2/2.75)) { 
        return 2 - (7.5625*(pos-=(1.5/2.75))*pos + .75); 
    } else if (pos < (2.5/2.75)) { 
        return 2 - (7.5625*(pos-=(2.25/2.75))*pos + .9375); 
    } else { 
        return 2 - (7.5625*(pos-=(2.625/2.75))*pos + .984375); 
    } 
};
 
//Gradual Transitions 
 
// EaseFromTo (adapted from "Quart.EaseInOut") 
Effect.Transitions.EaseFromTo = function(pos) { 
    if ((pos/=0.5) < 1) return 0.5*Math.pow(pos,4); 
    return -0.5 * ((pos-=2)*Math.pow(pos,3) - 2);    
}; 
// EaseFrom (adapted from "Quart.EaseIn") 
Effect.Transitions.EaseFrom = function(pos) { 
    return Math.pow(pos,4); 
}; 
// EaseTo (adapted from "Quart.EaseOut") 
Effect.Transitions.EaseTo = function(pos) { 
    return Math.pow(pos,0.25); 
};

/*
* Effect.Morphpos - an extension to Script.aculo.us' Effect.Morph 
* Version 1
* Based on code lifted from Script.Aculo.Us version 1.8.1
* Amendments by Anthony Doherty 2008
* http://codeandeffect.co.uk/blog
*/
Effect.Morphbgpos = Class.create(Effect.Base, {
 
  initialize: function(element) {
    this.element = $(element);
    if (!this.element) throw(Effect._elementDoesNotExistError);
    var options = Object.extend({
      style: { }
    }, arguments[1] || { });
    this.style = options.style.parseStyle();
    this.start(options);
  },
  
  setup: function(){
 
    this.transforms = this.style.map(function(pair){
      var property = pair[0], value = pair[1], unit = null  ;
      var xpos, ypos
	  if (property != 'backgroundPosition') {
		return new Effect.Morph(this.element, { style: property+":"+value, duration: this.options.duration}  );
	}
     else if (Element.CSS_LENGTH.test(value)) {
          var components = value.match(/^([\+\-]?[0-9\.]+)(.*)$/);
		  var compo = value.match(/^([\+\-]?[0-9\.]+)(px)(.+)([\+\-]?[0-9\.]*)$/);
			 		 
			 	 	 xpos = parseFloat(compo[1]);
			  	     ypos = parseFloat(compo[3]);
			 
				  
		  
		  
          value = parseFloat(components[1]);
          unit = "px";
      }
	
		//get orginal x and y positions
		var originalValue = this.element.getStyle(property);
		
		var originalpositions = this.element.getStyle(property).match(/^([\+\-]?[0-9\.]+)(px)(.+)([\+\-]?[0-9\.]*)$/);
        var originalX = parseFloat(originalpositions[1]);
	    var originalY = parseFloat(originalpositions[3]);
      return { 
        style: property.camelize(), 
		originX: parseFloat(originalX || 0), 
		originY: parseFloat(originalY || 0), 
        originalValue: originalValue,
		targetX:  parseFloat(xpos || 0), 
		targetY:  parseFloat(ypos || 0), 
        targetValue:   value,
        unit: unit
		
      };
    }.bind(this)).reject(function(transform){
      return (
        (transform.originalValue == transform.targetValue) || (transform.unit  == (isNaN(transform.originalValue) || isNaN(transform.targetValue))
        )
      )
    });
  },
  update: function(position) {
    var style = { }, transform, i = this.transforms.length;
 
	while(i--)  {
	 
		 
      style[(transform = this.transforms[i]).style] =  
        (transform.originX +(transform.targetX - transform.originX) * position).toFixed(3) + "px" + " "+
		(transform.originY +(transform.targetY - transform.originY) * position).toFixed(3) + "px"  ;
        this.element.setStyle(style, true);
	    
		 }
  }
});