/*
reflection.js for mootools v1.2
by Christophe Beyls (http://www.digitalia.be) - MIT-style license
Hacked By Jesse Lee (www.zzvo.com), 2008.2.20
*/
var Reflection = {

	add: function(img, options){
		img = $(img);
		if (img.getTag() != 'img') return;
		options = {arguments: [img, options]};
		if (window.ie) options.delay = 50;
		img.preload = new Image();
		img.preload.onload = Reflection.reflect.create(options);
		img.preload.src = img.src;
	},

	remove: function(img){
		img = $(img);
		if (img.preload) img.preload.onload = null;
		if ((img.getTag() == 'img') && (img.className == 'reflected')){
			img.className = img.parentNode.className;
			img.style.cssText = img.backupStyle;
			img.parentNode.replaceWith(img);
		}
	},

	reflect: function(img, options){
		options = $extend({
			height: 0.20, // 20%
			opacity: 0.30  // 30%
		}, options || {});

		Reflection.remove(img);
		var canvas, canvasHeight = Math.floor(img.height*options.height);
// Hacked, Jesse, 2008.2.20		
if (window.ie){
canvas = new Element('img').setProperty('src', img.src).setStyles({
'width': img.width+'px',
'marginBottom': -img.height+canvasHeight+'px',
'border': '0px', // no border in case of parent
'filter': 'flipv progid:DXImageTransform.Microsoft.Alpha(opacity='+(options.opacity*100)+', style=1, finishOpacity=0, startx=0, starty=0, finishx=0, finishy='+(options.height*100)+')'
});
} else {
canvas = new Element('canvas').setStyles({'width': img.width+'px', 'height': canvasHeight+'px', 'border': '0px'});
if (!canvas.getContext) return;
}

var div = new Element('div');
var parent = img.getParent();
if (parent.getTag() == "a") {
div.injectAfter(parent).adopt(parent);
parent.adopt(canvas);
} else
div.injectAfter(img).adopt(img).adopt(canvas);
div.className = img.className;
div.style.cssText = img.backupStyle = img.style.cssText;
div.removeClass('reflect').setStyles({'width': img.width+'px', 'height': (canvasHeight+img.height)+'px', 'overflow': 'hidden'});
img.style.cssText = 'vertical-align: bottom';
img.className = 'reflected';
if (window.ie) return;
// End Hack.

		var context = canvas.setProperties({'width': img.width, 'height': canvasHeight}).getContext('2d');
		context.save();
		context.translate(0, img.height-1);
		context.scale(1, -1);
		context.drawImage(img, 0, 0, img.width, img.height);
		context.restore();
		context.globalCompositeOperation = 'destination-out';
		var gradient = context.createLinearGradient(0, 0, 0, canvasHeight);
		gradient.addColorStop(0, 'rgba(255, 255, 255, '+(1-options.opacity)+')');
		gradient.addColorStop(1, 'rgba(255, 255, 255, 1.0)');
		context.fillStyle = gradient;
		context.rect(0, 0, img.width, canvasHeight);
		context.fill();
	},

	addFromClass: function(){
		$each(document.getElementsByTagName('img'), function(img){
			if ($(img).hasClass('reflect')) Reflection.add(img);
		});
	}
};

Element.extend({
	addReflection: function(options) { Reflection.add(this, options); return this; },
	removeReflection: function(options) { Reflection.remove(this, options); return this; }
});

Window.addEvent("domready", Reflection.addFromClass);

/* Slidemenu, Removed some features, Jesse Lee (www.zzvo.com, http://gallery.zzvo.com)*/
var isExtended = 0;
// var height = 300;
var width = 187;
var slideDuration = 500;
//var opacityDuration = 1000;

function extendContract(){
	if(isExtended == 0){
		sideBarSlide(0, width);
		//sideBarOpacity(0, 1);
		isExtended = 1;
		// make expand tab arrow image face left (inwards)
		$('sideBarTab').childNodes[0].src = $('sideBarTab').childNodes[0].src.replace(/(\.[^.]+)$/, '-active$1');
	}
	else{
		sideBarSlide(width, 0);
		//sideBarOpacity(1, 0);
		isExtended = 0;
		// make expand tab arrow image face right (outwards)
		$('sideBarTab').childNodes[0].src = $('sideBarTab').childNodes[0].src.replace(/-active(\.[^.]+)$/, '$1');
	}
}
function sideBarSlide(fromWidth, toWidth){
		var myEffects = new Fx.Styles('sideBarContents', {duration: slideDuration, transition: Fx.Transitions.linear});
		myEffects.custom({
			 // 'height': [fromHeight, toHeight],
			 'width': [fromWidth, toWidth]
		});
}
function init(){
	$('sideBarTab').addEvent('click', function(){extendContract()});
	$('sideBarTab').addEvent('click', function(e){
    e = new Event(e);
    e.stop();
    });
}
window.addEvent('domready', function(){init()});
