var x=0;
var y=0;
function changeClass(Layer,from, to) {
	var Obj=document.getElementById(Layer);
	Obj.className = Obj.className.replace(from, to);
	return false;
}
function position(event){
	var obj=document.getElementById('ContainerMap');
	x = event.clientX-obj.offsetLeft;
	y = event.clientY-obj.offsetTop;
}
function initializeSortTab(category) {
	var listItem = document.createElement('li');
	var listItemLink = listItem.appendChild(document.createElement('a'));
	listItemLink.href = "#";
	for(Id in Categories) {
		if ( Categories[Id].code == category) {
			listItemLink.innerHTML = '<img src="'+Categories[Id].icon+'" border="0" align="absmiddle" /> '+Categories[Id].name;
			break;
		} else {
			listItemLink.innerHTML = '<img src="images/spacer.gif" border="0" align="absmiddle" height="24" /> '+category;
		}
	}
	
	listItemLink.onclick = function() {
		changeClass('ContainerMap', 'standby', 'loading');
		for(id in markers) {
			if (markers[id].category == category || 'Todas' == category) {
				markers[id].show();
			} else {
				markers[id].hide();
			}
		}
		changeClass('ContainerMap', 'loading', 'standby');
		changeClass('toolbar','Show', 'Hidden');
		return false;
	}
	document.getElementById('filters').appendChild(listItem);
}
function VerItem(codi) {
		changeClass('ContainerMap', 'standby', 'loading');
		for(id in markers) {
			if (markers[id].code == codi) {
				markers[id].show();
			} else {
				markers[id].hide();
			}
		}
		changeClass('ContainerMap', 'loading', 'standby');
		changeClass('toolbar','Show', 'Hidden');
		return false;
}
function initializePoint(pointData) {
	var visible = false;
	var point = new GPoint(pointData.longitude, pointData.latitude);
	var iconImage='';
	
	for(Id in Categories) {
		if ( Categories[Id].code == pointData.category) {
			iconImage = Categories[Id].icon;
			iconWidth = Categories[Id].width;
			iconHeight = Categories[Id].height;
			break;
		} 
	}
	
	if (pointData.icon!='') {
		iconImage = pointData.icon;
		iconWidth = pointData.width;
		iconHeight = pointData.weight;
	}
	
	if(iconImage!='') {
		var icon = new GIcon();
		icon.image = iconImage;
		icon.iconSize = new GSize(iconWidth, iconHeight);
		icon.iconAnchor = new GPoint(Math.ceil(iconWidth/2), iconHeight);
		icon.infoWindowAnchor = new GPoint(Math.ceil(iconWidth/2), Math.ceil(iconHeight/2));
		var marker = new GMarker(point,icon);
	} else {
		var marker = new GMarker(point);
	}

	GEvent.addListener(marker, 'click',
			function() {
				aj('propiedad_detalle.php?pro_codi='+pointData.code+'&pagina='+pagina,'propiedad')
			}
		);
	pointData.show = function() {
		if (!visible) {
			map.addOverlay(marker);
			visible = true;
		}
	}
	pointData.hide = function() {
		if (visible) {
			map.removeOverlay(marker);
			visible = false;
		}
	}
	pointData.show();
}

