function $(element) {
	return document.getElementById(element);
}
var $xx = function(element) {
	return document.getElementById(element);
}
function addHandler(object, event, handler) {
  if (typeof object.addEventListener != 'undefined')
    object.addEventListener(event, handler, false);
  else if (typeof object.attachEvent != 'undefined')
    object.attachEvent('on' + event, handler);
  else
    throw "Incompatible browser";
}
function removeHandler(object, event, handler) {
  if (typeof object.removeEventListener != 'undefined')
    object.removeEventListener(event, handler, false);
  else if (typeof object.detachEvent != 'undefined')
    object.detachEvent('on' + event, handler);
  else
    throw "Incompatible browser";
}
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

var getClientWidth = function() {
	return width = top.document.body.clientWidth || 0;
}

var blocksSize = function() {
	var mainWidth = Math.floor( ( getClientWidth() * 90 ) / 100 ); // Таблица занимает 90% ширины экрана
	mainWidth = (mainWidth < 900) ? 900 : mainWidth;
//	var six = Math.floor(mainWidth / 6);
//	alert($('header').style.width);
	$('header').style.width = mainWidth + 'px';
	$('menu').style.width = mainWidth + 'px';
	$('main').style.width = mainWidth + 'px';
	
//	/* blocks */
//	for (var i = 0; i <= 5; i++) {
//		$('block-' + i).style.width = six + 'px';
//	}
//	
//	$('column').style.width = six + 'px';
//
//	if ($('rightcolumn')) {
//		$('rightcolumn').style.width = six + 'px';
//		$('content').style.width = (mainWidth - six * 2) + 'px';
//		$('contentimg').style.width = (mainWidth - six * 2) + 'px';
//		$('contentimg').style.height = 1 + 'px';
//	}
//	else {
//		$('content').style.width = ( mainWidth - six ) + 'px';
//	}
 //	$('content').style.padding = '0px';
}

var blocksBg = function() {
	if (document.location.href == 'http://inter-study.ru/' || document.location.href == 'http://www.inter-study.ru/') return;
	var active_block = -1;
	var count_normal = 0;
	for (var i = 0; i <= 5; i++) {
		if ($('block-' + i).className == 'normal') {
			active_block = i;
			count_normal++;
		}
	}
	if (count_normal > 1) {
		active_block = -1;
	}
	var mover = function(i) {
		for (j = 0; j <= 5; j++) {
			$('block-' + j).className = 'gray';
		}
		$('block-' + i).className = 'normal';
	}
	var mout = function(i) {
		if (active_block == -1) {
			for (j = 0; j <= 5; j++) {
				$('block-' + j).className = 'normal';
			}
		}
		else {
			for (j = 0; j <= 5; j++) {
				$('block-' + j).className = 'gray';
			}
			$('block-' + active_block).className = 'normal';
		}
	}
	for (var i = 0; i <= 5; i++) {
		addHandler(
			$('block-' + i),
			'mouseover',
			(function(i) { return function() { mover(i) } })(i)
		);
		addHandler(
			$('block-desc-' + i),
			'mouseover',
			(function(i) { return function() { mover(i) } })(i)
		);
		addHandler(
			$('block-' + i),
			'mouseout',
			(function(i) { return function() { mout(i) } })(i)
		);
		addHandler(
			$('block-desc-' + i),
			'mouseout',
			(function(i) { return function() { mout(i) } })(i)
		);
	}
}
var blocksBgLinks = function() {
	/*
	var mdown = function(i) {
		document.location.href = $('block-' + i).getAttribute('href');
	}
	for (var i = 0; i <= 5; i++) {
		addHandler(
			$('block-' + i),
			'mousedown',
			(function(i) { return function() { mdown(i) } })(i)
		);
	}
	*/
}

var tags = function() {
	try {
		if (getClientWidth() > 1100) {
			$('tags').style.display = 'block';
		}
		else {
			$('tags').style.display = 'none';
		}
	}
	catch(err){}
}

var init = function() {
	blocksBg();
	blocksBgLinks();
	blocksSize();
	tags();
}

// window.onload
addLoadEvent(init);

window.onresize = function() {
	blocksSize();
	tags();
}

