/* Brehaut.net V3 - Wendigo 
 *  Copyright Andrew Brehaut (c) 2010-2011 
 */

(function () {
    function drawCurve () {
    	if (!document.createElement('canvas').getContext) return;
	
        var c = document.createElement('canvas');
    
        c.id = "wave";

        c.style.position = "absolute";
        c.style.top = "0px";
        c.style.left = "0px";
        c.style.zIndex = -1;
    
        var ctx = c.getContext("2d");
        document.body.appendChild(c);
        c.height = 330;
    
        var Color = net.brehaut.Color;
        var backgroundColor = Color("#FFE69C");
        var gradEdge = backgroundColor.desaturateByAmount(0.1);
        var gradCenter = backgroundColor.desaturateByAmount(0.235);
    
        function rgba(c, a) {
        	var rgb = c.toRGB();
        	return 'rgba(' + Math.floor(rgb.getRed() * 255) + "," + Math.floor(rgb.getGreen() * 255) + "," + Math.floor(rgb.getBlue() * 255) + "," + a + ")";
        }
    
        function createGradient(width) {
        	var grad = ctx.createLinearGradient(0, 0, width, 0);
        	grad.addColorStop(0, rgba(gradEdge, 1));
        	grad.addColorStop(0.04, rgba(gradEdge, 1));
        	grad.addColorStop(0.35, rgba(gradCenter, 1));
        	grad.addColorStop(0.65, rgba(gradCenter, 1));
        	grad.addColorStop(0.96, rgba(gradEdge, 1));
        	grad.addColorStop(1, rgba(gradEdge, 1));
        	return grad;
        }
    
        //background: -webkit-gradient(linear, 0% 0%, 100% 0%, from(#FFCD38), color-stop(0.04, #FFCD38), color-stop(0.5, #FFD863), color-stop(0.96, #FFCD38), to(#FFCD38));
        function curve () {
            c.width = document.body.clientWidth || window.innerWidth;

            ctx.fillStyle = createGradient(c.width);
            ctx.beginPath();
            ctx.moveTo(0,0);
            ctx.lineTo(0,230);
            ctx.bezierCurveTo(c.width * 0.25, 105, c.width * 0.75, 335, c.width, 230);
            ctx.lineTo(c.width, 230);
            ctx.lineTo(c.width, 0);
            ctx.lineTo(0,0);
            ctx.fill();
        }

        curve();

        window.onresize = curve;
    }

    drawCurve();
} ())

