
// Initialise the effects

window.onload = function(container) {
	var links = $$('.splash a');
	var details = $$('.splash .detail');
	
	links.addEvent('click', function(event) {
		tween = new Fx.Tween(details[0]);
		tween.set('display','block');
		tween.start('height','1px','auto');
	});
	
	drawFades();
}

function nospam(a) {
    m = "mai" + "lto:" + a + "@" + "montessori" + "-intl" + ".o" + "rg";
    window.location = m;
}

function drawFades() {
	var backgroundcolor = $('body').getStyle('background-color')
	var bg = colorComponents(backgroundcolor);

	var canvases = $$('.fade');
		
	Array.each(canvases, function(c) {
		w = parseInt(c.getStyle('width'));
		c_context = c.getContext("2d");
		c_context.fillStyle = c_context.createLinearGradient(0, 0, 0, 50);
		//c_context.fillStyle.addColorStop(0, 'transparent');
		c_context.fillStyle.addColorStop(0, 'rgba('+bg[0]+','+bg[1]+','+bg[2]+',0)');
		c_context.fillStyle.addColorStop(0.5, backgroundcolor);
		c_context.fillRect(0,0,w,50);
	});
}



// take css color string and return array of RGB components (0-255)
function colorComponents(color) {
	if (color.indexOf('rgb(') == 0)
	{
		var r = /\(.+\)/;
		var val = color.match(r).toString();
		val = val.substring(1, val.length - 1).replace(/ /g, '');
	
		var values = val.split(','), i = 0, result;
		for (i = 0; i < values.length; i++)
		{
			temp[i] = parseInt(values[i]);
		}
	
		return temp;
	}
	else {
		return HexToRGB(color);
	}
}
function HexToRGB(h) {return [HexToR(h),HexToG(h),HexToB(h)]}
function HexToR(h) {return parseInt((plumpHex(h)).substring(0,2),16)}
function HexToG(h) {return parseInt((plumpHex(h)).substring(2,4),16)}
function HexToB(h) {return parseInt((plumpHex(h)).substring(4,6),16)}
function cutHex(h) {return (h.charAt(0)=="#") ? h.substring(1,7):h}
function plumpHex(h) {
	h = cutHex(h);
	if (h.length == 3) {
		h[5] = h[2]; // f60##0
		h[4] = h[2]; // f60#00
		h[3] = h[1]; // f60600
		h[2] = h[1]; // f66600
		h[1] = h[0]; // ff6600
    }
    return h;
}
