function Ajax() {
	this.xmlhttp = null;
	this.send = function(url, statechange) {
		if(window.XMLHttpRequest) this.xmlhttp = new XMLHttpRequest();
		else if(window.ActiveXObject) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		if(this.xmlhttp != null) {
			this.xmlhttp.onreadystatechange = statechange;
			this.xmlhttp.open("GET", url, true);
			this.xmlhttp.send(null);
		}
		else alert("Your browser doesn't support AJAX.");
	}
	this.post = function(url, data, statechange) {
		if(window.XMLHttpRequest) this.xmlhttp = new XMLHttpRequest();
		else if(window.ActiveXObject) this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		if(this.xmlhttp != null) {
			this.xmlhttp.onreadystatechange = statechange;
			this.xmlhttp.open("POST", url, true);
			this.xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			this.xmlhttp.setRequestHeader("Content-length", data.length);
			this.xmlhttp.setRequestHeader("Connection", "close");
			this.xmlhttp.send(data);
		}
		else alert("Your browser doesn't support AJAX.");
	}
}

var site = {
	ajax: null,
	stopLight: false,
	
	init: function() {
		site.initBackground();
		window.onresize = site.onResize;
	},
	
	hang: function(millis) {
		window.setTimeout("site.stopLight = false", millis);
	},
	
	onResize: function() {
		if(site.stopLight == true) return;
		site.stopLight == true;
		window.setTimeout("site.initBackground()", 500);
	},
	
	initBackground: function() {
		var myWidth = 0, myHeight = 0;
		if( typeof( window.innerWidth ) == 'number' ) { //Non-IE
			myWidth = window.innerWidth;
			myHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
		}
		
		var wheight = document.getElementById('wrapper').clientHeight;
		var pageHeight = wheight > myHeight ? wheight : myHeight;
		var footerMarginTop = wheight > myHeight ? wheight - 47 : myHeight - 47;
		
		if(myWidth < 1073) myWidth = 1073;
		
		var d = document.getElementById('background');
		d.style.width = myWidth + 'px';
		d.style.height = pageHeight + 'px';
		
		var e = document.getElementById('wrapper');
		var f = document.getElementById('footer');
		var l = document.getElementById('lang');
		
		e.style.width = myWidth + 'px';
		f.style.width = myWidth + 'px';
		f.style.marginTop = footerMarginTop + 'px';
		l.style.marginLeft = (myWidth - 60) + 'px';
		
		var h = document.getElementById('barasus');
		h.style.width = myWidth + 'px';
		var h = document.getElementById('barast');
		h.style.height = myHeight + 'px';
		
		var g = document.getElementById('galerie');
		var h = document.getElementById('gal-content');
		if(h) {
			var www = myWidth;
			if(www < 1073) www = 1073;
			
			if(g) g.style.width = www + 'px';
			if(g) g.style.marginTop = (footerMarginTop - 84 + 28) + 'px';
			
			www = www - 90;
			var h1 = document.getElementById('gal-content-bg');
			var h2 = document.getElementById('gal-content-c');
			h.style.width = www + 'px';
			h1.style.width = www + 'px';
			h2.style.width = www + 'px';
		}
		
		var flashWidth = 2000;
		var flashHeight =1500;
		var fd = document.getElementById('bg_center');
		fd.style.marginLeft = ((myWidth / 2) - (flashWidth / 2)) + "px";
		
		var textarea = document.getElementById('textarea');
		var viewimagine = document.getElementById('viewimagine');
		if(viewimagine != null)
			textarea = viewimagine;
		if(textarea != null) {
			var w = textarea.clientWidth;
			var h = textarea.clientHeight;
			var mt = (myHeight / 2) - (h / 2);
			var ml = (myWidth / 2) - (w / 2);
			if(mt < 90) mt = 90;
			if(ml < 300) ml = 300;
			textarea.style.paddingTop = mt + 'px';
			textarea.style.marginLeft = ml + 'px';
		}
		
		site.adjustMenu();
		
		site.hang(500);
	},
	
	adjustMenu: function() {
		var d = document.getElementById('menu');
		var e = document.getElementById('menu-bg');
		var f = document.getElementById('menu-content');
		d.style.height = (f.clientHeight + 47) + 'px';
		e.style.height = (f.clientHeight + 47) + 'px';
	},
	
	openCateg1: function() {
		site.closeCateg2();
		document.getElementById('categ1').style.display = 'block';
		site.adjustMenu();
	},
	closeCateg1: function() {
		document.getElementById('categ1').style.display = 'none';
		site.adjustMenu();
	},
	openCateg2: function() {
		site.closeCateg1();
		document.getElementById('categ2').style.display = 'block';
		site.adjustMenu();
	},
	closeCateg2: function() {
		document.getElementById('categ2').style.display = 'none';
		site.adjustMenu();
	},
};

