$(window).addEvent('load',function(){
	
	if($('canvas')){
		try{
			$('canvas').getContext('2d');
		}
		catch(e)
		{
			new Element('div',{
				id : 'no-canvas',
				text : 'Sorry, only canvas-enabled browsers :('
			}).replaces($('canvas'));
		}
	};

	var topNavi = window.location.pathname.split("/").getLast().split('.')[0];
	topNavi = topNavi || 'index';
	
	$$('#head a[href*='+topNavi+']')[0].addClass('active');
	
	var item = $$('#index a[href$='+window.location.pathname.split("/").getLast()+']');
	
	if(item.length == 1){
		
		new Element('ul').inject(item[0].getParent());
		$$('#content h2').each(function(item){
		
			var str = item.get('text').split(':').getLast().trim();
			
				var li = new Element('li').inject($$('#index ul')[0]);
				item.set('id','fn-'+str);
				new Element('a',{
					href : '#fn-'+str,
					text : str
				}).inject($$('#index ul li').getLast());
			
						new Element('a',{
				text : '\u2191 top',
				href : '#head'
			}).inject(item);
			
		});
	}
	
	if($('source'))
	{
		new Request({
			url : 'getSource.php',
			onComplete : function(content)
			{
				$('source').set('html',content);
			}
		}).get({
			file : $$('script[src*=examples]').getLast().get('src')
			});
	}
	
	
	
});


