/*
	reflection.js for mootools v1.43
	(c) 2006-2009 Christophe Beyls <http://www.digitalia.be>
	MIT-style license.
*/
Element.implement({
	reflect:function(b,uo){ //unteres offset
		var a=this;
		var kd;
		var k;
		if(a.get("tag")=="img")
		{
			if(uo == null) uo = 0;
			else uo = (-1)*uo;
			b=$extend({height:1/3,opacity:0.5},b);
			a.unreflect();
			function c(){
				var f=a.width,
				d=a.height,h,l,g,j;
				h=Math.floor((b.height>1)?Math.min(d,b.height):d*b.height);
				if(Browser.Engine.trident){
					k=new Element("img",{
						src:a.src,
						styles:{
							width:f,
							height:d,
							marginTop:uo,
							marginBottom:h-d,
							filter:"flipv progid:DXImageTransform.Microsoft.Alpha(opacity="+(b.opacity*100)+", style=1, finishOpacity=0, startx=0, starty=0, finishx=0, finishy="+(h/d*100)+")"
						}
					})
				}else{
					k=new Element("canvas");
					if(!k.getContext){return}
					try{
						g=k.setProperties({width:f,height:h}).getContext("2d");
						g.save();
						g.translate(0,d-1);
						g.scale(1,-1);
						g.drawImage(a,0,0,f,d-uo);
						g.restore();
						g.globalCompositeOperation="destination-out";
						j=g.createLinearGradient(0,0,0,h);
						j.addColorStop(0,"rgba(255, 255, 255, "+(1-b.opacity)+")");
						j.addColorStop(1,"rgba(255, 255, 255, 1.0)");
						g.fillStyle=j;
						g.rect(0,0,f,h);
						g.fill()
					}catch(i){return}
				}
				k.setStyles({display:"block",border:0});
				l=new Element(($(a.parentNode).get("tag")=="a")?"span":"div")
					.injectAfter(a)
						.adopt(a,k);
				l.className=a.className;
				a.store("reflected",l.style.cssText=a.style.cssText);
				l.setStyles({width:f,height:d+h,overflow:"hidden"});
				new Element('div',{styles:{'overflow':'hidden','width':a.getStyle('width'),'height':a.getStyle('height'),'z-index':1}}).inject(l).adopt(a);
				kd = new Element('div',{styles:{'overflow':'hidden','z-index':0}}).inject(l).adopt(k);
				//a.style.cssText="display: block; border: 0px; margin-top: 20px";
				a.setStyles({'display':'block','border':'0px'});
				a.className="reflected"
			}
			if(a.complete){
				c()
			}else{
				a.onload=c
			}
		}
		return {img:a,ref:k}
	},
	unreflect:function(){
		var b=this,
		a=this.retrieve("reflected"),c;
		b.onload=$empty;
		if(a!==null){
			c=b.parentNode;
			b.className=c.className;
			b.style.cssText=a;
			b.store("reflected",null);
			c.parentNode.replaceChild(b,c)
		}
		return b
	}
});

// AUTOLOAD CODE BLOCK (MAY BE CHANGED OR REMOVED)
window.addEvent("domready", function() {
	$$("img").filter(function(img) { return img.hasClass("reflect"); }).reflect({/* Put custom options here */});
});
