var BrowserFixes = function() {
	// Internet Explorer
	if (Browser.Engine.trident) {
		// Fix clears
		$each($(document.body).getElements('br'), function(item) {
			if ($chk(item.get("style"))) {
				new Element('div', {'html': '<!-- Internet Explorer Fix -->', 'styles': {'clear': 'both'}}).inject(item, 'after');
				item.destroy();
			}
		});
		// Fix white space under images
		$each($(document.body).getElements('img'), function(item){ item.addEvent('load', function(item) { this.set('alt', ''); }).setStyle('display', 'block').set('GALLERYIMG', 'no'); });
		// Fix HR
		$each($(document.body).getElements('hr'), function(item){
			new Element('div', {'html': '<!-- Internet Explorer Fix -->', 'class': 'hr'}).inject(item, 'after');
			item.destroy();
		});
		// Fix Legends
		$each($(document.body).getElements('legend'), function(item){ item.setStyles({'position': 'absolute', 'left': '-7px'}); });
		// Fix last and first childs in tables for styling and lists for IE6 only (implemented in IE7 and IE8)
		var rowgroups = $(document.body).getElements('thead, tbody, tfoot, ul, ol');
		// Do rows
		rowgroups.each(function(group){
			var rows = group.getElements('td, th, li');
			// Add style to columns for first row
			if (Browser.Engine.version==4&&(rows[0].get('tag')=='td'||rows[0].get('tag')=='th'||rows[0].get('tag')=='li')) {
				rows[0].addClass('first-child');
			}
			// Add style to columns for last row
			if ($chk(rows[(rows.length-1)])&&(rows[(rows.length-1)].get('tag')=='td'||rows[(rows.length-1)].get('tag')=='th'||rows[(rows.length-1)].get('tag')=='li')) {
				rows[(rows.length-1)].addClass('last-child');
			}
		});
	}
	// Firefox
	else if (Browser.Engine.gecko) {
		// Fix Legends
		$each($(document.body).getElements('legend'), function(item){
			new Element('div', {'class': 'legend', 'html': item.get('html'), 'styles': {'top': '-40px', 'left': '-10px'}}).inject(item, 'after');
			item.destroy();
		}); 
	}
}

window.addEvent('domready', function() {	
	// Fix Browser spesific bugs
	BrowserFixes.run();
	
	// Home navigation
	if ($chk($(document.body).getElement('div.nav-home ul'))) {
		var width = 0;
		$(document.body).getElements('div.nav-home ul li').each(function(li) {
			width += li.getSize().x.toInt();
		});
		$(document.body).getElement('div.nav-home ul').setStyle('margin-left', (960-width)/2-24);
	}
});
