var originalMap;
var searchURL = "./index.php?option=com_propertysearch&Itemid=33&view=gallery3col&p_department=RS&national=true";


function showBalloon(propertyID, left, top, html) {
	var b = document.getElementById("balloon");
	
	b.innerHTML = html;
	
	var newHeight = parseInt(top) - parseInt(b.style.height);
	b.style.top = newHeight + "px";
	b.style.left = left + "px";

	b.style.visibility = "visible";
}

function hideBalloon() {
	//Don't hide it here otherwise you can't mouse off the pin!

	//var b = document.getElementById("balloon");
	//b.style.visibility = "hidden";
}


function showArea(area) {
	m = document.getElementById("mapimg");
	originalSource = m.src;
	originalMap = originalSource.substr(0, originalSource.length - 4);
	m.src = originalMap + "_" + area + ".png";
}

function hideArea(area) {
	m = document.getElementById("mapimg");
	m.src = originalMap + ".png";
}

function showHover() {
	m = document.getElementById("mapimg");
	m.style.backgroundColor = "white";
}

function hideHover() {
	m = document.getElementById("mapimg");
	m.style.backgroundColor = "transparent";
}

function showAreas(parentArea, link) {
	//First of all, reset all of the area divs to hidden...
	var e = document.getElementsByClassName('areaList');
	for(var a = 0; a < e.length; a++) {
		e[a].style.visibility = "hidden";
	}

	//Now show the div passed to the function...
	var x = document.getElementById(parentArea);
	if(x != undefined)
		x.style.visibility = "visible";
	else
		window.location = link;
}


function setURLs() {
	//Get a list of areaLists...
	var area = document.getElementsByClassName('areaList');
	for(var a = 0; a < area.length; a++) {
		var anchor = area[a].getElementsByTagName('a') //get all the anchors for that areaList...
		for(var ai = 0; ai < anchor.length; ai++) {
			var myURL = anchor[ai].href;
			myURL = myURL.substring(myURL.indexOf('?') + 1, myURL.length); //even though the href values are just the querystring Javascript returns a full implicit url from the current page so get rid of everything up to the ?
			anchor[ai].href = searchURL + "&" + myURL; //Now prepend the final url to the querystring...
		}
	}
}


onload = function() {
	if (document.getElementsByClassName == undefined) {
		document.getElementsByClassName = function(className)
		{
			var hasClassName = new RegExp("(?:^|\\s)" + className + "(?:$|\\s)");
			var allElements = document.getElementsByTagName("*");
			var results = [];

			var element;
			for (var i = 0; (element = allElements[i]) != null; i++) {
				var elementClass = element.className;
				if (elementClass && elementClass.indexOf(className) != -1 && hasClassName.test(elementClass))
					results.push(element);
			}

			return results;
		}
	}
	setURLs(); //call setURLs here...
}


