var zIndex = 1;

var baners = {
	
	get: function(id_zone) {
		var xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : false;
		xmlhttp.open('GET', '/JSBaners/baners.php?id='+id_zone);
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
		xmlhttp.send(null);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
				if (xmlhttp.status == 200) {
					var zone = document.getElementById('bzone'+id_zone);
					if (zone) {
						zone.innerHTML = '';
						zone.innerHTML = xmlhttp.responseText;
						if (id_zone == 2) { // Cambiar el fondo de la zona segun el baner:
							// 1- si se carga el fichero anamor2.swf, cargar la imagen de fondo de la zona
							if (xmlhttp.responseText.search(/anamor2.swf/i) != -1) {
								zone.style.background = 'url(/JSBaners/baners/sp240x120_anamor.png) no-repeat';
							// 2- si se carga el fichero banner_Karealde_240x120.swf, colorear de blanco de fondo de la zona
							} else if (xmlhttp.responseText.search(/banner_Karealde_240x120.swf/i) != -1) {
								zone.style.background = '#ffffff';
							// 3- en caso contrario, carga la imagen de fondo predeterminada
							} else {
								//zone.style.background = 'url(/JSBaners/baners/sp240x120_3.png) no-repeat';
							}
						}
						if (xmlhttp.responseText.search(/kukuiagainformatika80x60.png/i) != -1) {
							zone.style.background = '#3f351a';
						}
					}
				}
			}
		}
	},
	
	rotate: function(z, t) {
		this.get(z);
		if (t >0) setInterval("baners.get('"+z+"');", t*1000);
	},

	click: function(id) {
		var xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : false;
		xmlhttp.open('POST', '/JSBaners/click.php');
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
		xmlhttp.send('id=' + id);
	},
	
	init: function() {
		this.rotate(1, 0);
		this.rotate(2, 0);
		this.rotate(3, 0);
		this.rotate(4, 0);
		this.rotate(5, 0);
		this.rotate(6, 0);
		this.rotate(7, 0);
		this.rotate(8, 0);
		this.rotate(9, 0);
		this.rotate(10, 0);
		this.rotate(11, 0);
		this.rotate(12, 0);
		this.rotate(13, 0);
		this.rotate(14, 0);
		this.rotate(15, 0);
	}
	
};

