
window.addEvent('domready', function()
{

	// Stylize tables
	$$('table').each(function(item, index)
	{
		item.addClass('table');

		var i = 0;
		var tbody = item.getElement('tbody');
		var trs = item.getElements('tr');
		var ths = item.getElements('th');
		var createHeader = false;
		
		if (ths.length > 0)
		{
			ths.each(function(th, id_th)
			{
				if (id_th % 2 == 0) {th.addClass('odd'); } else {th.addClass('even');}
			});
		}
		else
		{
			createHeader = true;
		}

		trs.each(function(tr, id_tr)
		{
			if (id_tr % 2 == 0) {tr.addClass('dark'); } else {tr.addClass('light');}
			
			
			var tds = tr.getElements('td');
			tds.each(function(td, id_td)
			{
				var cl = 'even';
				if (id_td % 2 == 0) {cl = 'odd'; }
				
				if (createHeader == true)
				{
					tr.adopt(new Element('th', {'class':cl}).set('text', td.get('text')));
					td.dispose();
				}
				else
				{
					td.addClass(cl);
				}
				
				if ((td.get('text')).toInt() > 0)
				{
					td.addClass('small');
				}
			});

			createHeader = false;
		});
	});
	








	if (Browser.Engine.name=='trident' && Browser.Engine.version==4)
	{
		mtop = $('header').getSize().y;
		$w = $$('div.wrap')[0].addClass('nobg');
		ht = $w.getSize().y;
		mleft = $w.getCoordinates().left;
		$(document.body).adopt(new Element('div', {'id':"wrapbg"}));
		$('wrapbg').setStyles({
			height : ht,
			marginTop : mtop,
			marginLeft : mleft
		});
	
		window.addEvent('resize', function()
		{
			mleft = $w.attr('offsetLeft');
			$('wrapbg').setStyle('margin-left', mleft);
		});

		// Navigation
		$$('#nav ul > li').addEvent('mouseover', function(event){
			this.getChildren('ul').addClass('show');
		});
		$$('#nav ul > li').addEvent('mouseout', function(event){
			this.getChildren('ul').removeClass('show');
		});
		// Subnavigation
		$$('#nav li li a').addEvent('mouseover', function(event){
			this.addClass('on');
		});
		$$('#nav li li a').addEvent('mouseout', function(event){
			this.removeClass('on');
		});

		// Header
		$('header').adopt(new Element('span', {'class':'bg'}));

		// Gallery boxes
		$$('#gallery div.int p a').addEvent('mouseover', function(event){
			this.addClass('on');
		});
		$$('#gallery div.int p a').addEvent('mouseout', function(event){
			this.removeClass('on');
		});
	}

	// Columns height
	ht = 0;
	$div = $$('#content > div');
	for(i=0; i<$div.length; i++)
	{
		$obj = $div[i];
		cs = $obj.getComputedSize();
		if (ht < cs.totalHeight)
		{
			ht = cs.totalHeight;
		}
		$obj.store('pad', (cs['padding-top'] + cs['padding-bottom']));
	}
	for (i=0; i<$div.length; i++)
	{
		$obj = $div[i];
		newht = ht - $obj.retrieve('pad');
		$obj.setStyle('height', newht);
	}
	
	// Menu width
	menu_width = 141;
	$ul = $$('#nav ul ul').setStyle('width', 'auto');
	for (i=0; i<$ul.length; i++)
	{
		$menu = $ul[i];
		$links = $menu.getElements('a');	
		padding = $links[0].getComputedSize()['padding-left'];
		$links.setStyles({
			'white-space' : 'nowrap',
			'display' : 'inline-block'
		});
		for (j=0; j<$links.length; j++)
		{
			width = $links[j].getSize().x;
			if (menu_width < width) {
				menu_width = width;
			}
		}
		$links.removeProperty('style');
	//	$menu.setStyle('width', (menu_width + 2 * padding) + 'px');
		$links.setStyle('width', (menu_width + 2 * padding) + 'px');
		menu_width = 141;
	}
});

