/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *
 *		(c) 2010 Die Agentur GmbH
 *		http://die-agentur-gmbh.de
 *		Web Development by Bernd Lutz (berndlutz.com)
 *
 **/


/*
 *		The Layout class aims to help making
 *		all parts responsive and adjust shapes
 *		to the window size. Images would't scale
 *		nice.
 */


var Layout = {

	init: function()
	{
		this.setDimensions();
		
		// element creation does't work by string on canvas in IE
		this.canvasElement = document.createElement('canvas');
		
		$('#bg').after(this.canvasElement);
		
		this.canvasElement = $('canvas').attr({
			id: 'bg-shapes',
			width: this.windowWidth,
			height:  this.windowHeight
		}).get(0);
		
		// explorercanvas initiation for dynamically created canvas elements
		if ( !document.createElement('canvas').getContext )
			G_vmlCanvasManager.initElement(this.canvasElement);
		
		this.canvas = this.canvasElement.getContext('2d');
		this.drawShapes();
	},
	
	
	setDimensions: function()
	{
		this.windowWidth = Number($(window).width());
		this.windowHeight = Number($(window).height());
	},
	
	
	drawShape: function(points, opacity)
	{
		this.canvas.beginPath();
		this.canvas.moveTo(this.windowWidth*points[0][0], this.windowHeight*points[0][1]);
		for ( var i = 1; i < points.length; i++ )
		{
			this.canvas.lineTo(this.windowWidth*points[i][0], this.windowHeight*points[i][1]);
		}
		this.canvas.fillStyle = 'rgba(0, 0, 0, ' + opacity + ')';
		this.canvas.fill();
	},
	
	
	drawShapes: function()
	{
		this.canvas.clearRect(0, 0, 10000, 10000);
		this.setDimensions();
		
		this.canvasElement.width = this.windowWidth;
		this.canvasElement.height = this.windowHeight;
		
		this.drawShape([[0.684, 0.736], [1, 0.664], [1, 1], [0.824, 1]], 0.5);
		this.drawShape([[0, 0], [0.791, 0], [0.84, 0.632], [0, 0.82]], 0.25);
		this.drawShape([[0, 0.41], [0.698, 0.41], [0.8, 0.547], [0, 0.72]], 0.6);
	}
};


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */


$(document).ready(function()
{
	Layout.init();
	
	$(window).bind('resize', $.proxy(Layout, 'drawShapes'));
});
