
var http = false;

if(navigator.appName == "Microsoft Internet Explorer") {
	http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
	http = new XMLHttpRequest();
}

function load(url) {
	http.open("GET", url, true);
	http.onreadystatechange = function() {
		if ( http.readyState == 4 ) {
			document.getElementById('gallery').innerHTML = http.responseText;
		}
	}
	http.send(null);
}

var pages = ['elgastroi', 'equipment', 'niski_constr', 'visoki_constr', 'reconstruc', 'trubni_inst', 'putno_stroit', 'plochki', 'suhi_smesi'];
document.observe('dom:loaded', function () {
	var page = $get('#');
	if ( pages.indexOf(page) != -1 ) {
		$$('.menuText a').each(function(element) {
			element.removeClassName('current');
		});
		var element = $('nav_' + page);
		new Ajax.Updater('gallery', element.href, { method: 'get' });
		element.addClassName('current');
	}

// 	alert(page);
// 	if ( pages.contains(page) ) {
// 		$('current').id = null;
// 		$('nav_' + page).getElements('a')[0].id = 'current';
// 	}

	$$('.menuText a').each(function(element) {
		element.observe('click', function(event) {
			event.stop();
			var element = event.element();
			$$('.menuText a').each(function(element) {
				element.removeClassName('current');
			});
// 			load(element.href);
			new Effect.Opacity('gallery', { from: 1.0, to: 0, duration: 0.5 });
			setTimeout("$('gallery').addClassName('height400')", 600);
			var update = "new Ajax.Updater('gallery', '" + element.href + "', {method: 'get', onComplete: function() { $('gallery').removeClassName('height400'); new Effect.Opacity('gallery', { from: 0, to: 1.0, duration: 1 }) }})";
			setTimeout(update, 600);

// 			$('gallery').removeClassName('height400');
// 			setTimeout("new Effect.Opacity('gallery', { from: 0, to: 1.0, duration: 0.6 })", 700);

			element.addClassName('current');
		});
	});
});

