var DivBoxes = new Array();
DivBoxes[0] = "sf_store";
DivBoxes[1] = "sf_petrol";
DivBoxes[2] = "sf_pharmacy";
DivBoxes[3] = "sf_cafe";
DivBoxes[4] = "sf_dry";
//Default box is the one that becomes selected when javascript is enabled
var DefaultBox = "sf_store";
var morrisonsHost = 'http://' + window.location.host;
function updateDivs(showWelsh) {

	for (var i = 0, as = document.getElementById("sf_details").getElementsByTagName("a"), a; a = as[i]; i++) {
		if (a.rel == "storefinder") {
			var img = a.getElementsByTagName("img")[0];
			if (a.id == DefaultBox) {
				img.src = morrisonsHost+"/graphics/storelocator/" + showWelsh + "sf_store_on.jpg";
				addMouseOut(a, a.id, morrisonsHost+'/graphics/storelocator/' + showWelsh + 'sf_store_on.jpg');
			} else {
				img.src = morrisonsHost+'/graphics/storelocator/' + showWelsh + a.id + '_off.jpg';
				document.getElementById(a.id+'_div').style.display = 'none';				
				addMouseOut(a, a.id, morrisonsHost+'/graphics/storelocator/' + showWelsh + a.id + '_off.jpg');
			}
			addOnclick(a, a.id, showWelsh);	
			addMouseOver(a, a.id, showWelsh);
			
		}
	}
}
function addOnclick(obj, divID, showWelsh)
{
	obj.onclick = function() {
		DivBox = document.getElementById(divID);
		for (var i = 0, as = document.getElementsByTagName("a"), a; a = as[i]; i++) {
			var img = a.getElementsByTagName("img")[0];
			if (a.rel == "storefinder") {
				img.src = morrisonsHost+'/graphics/storelocator/'+ showWelsh + a.id + '_off.jpg';
				HideDiv = a.id+'_div';
				document.getElementById(HideDiv).style.display = 'none';
			}
		}
		var img = DivBox.getElementsByTagName("img")[0];
		img.src = morrisonsHost+'/graphics/storelocator/' + showWelsh + DivBox.id+'_on_hover.jpg';
		addMouseOut(DivBox, DivBox.id, morrisonsHost+'/graphics/storelocator/'+ showWelsh + DivBox.id+'_on.jpg');
		document.getElementById(DivBox.id+'_div').style.display = 'block';
		return false;
	}
}
function addMouseOver(obj, divID, showWelsh)
{
	obj.onmouseover = function() {
		DivBox = document.getElementById(divID);
		var img = DivBox.getElementsByTagName("img")[0];
		if (img.src == morrisonsHost+'/graphics/storelocator/'+ showWelsh + DivBox.id+'_on.jpg') {
			addMouseOut(DivBox, divID, morrisonsHost+'/graphics/storelocator/'+ showWelsh + DivBox.id+'_on.jpg');
			img.src = morrisonsHost+'/graphics/storelocator/'+ showWelsh + DivBox.id+'_on_hover.jpg';
		} else {
			addMouseOut(DivBox, divID, morrisonsHost+'/graphics/storelocator/'+ showWelsh + DivBox.id+'_off.jpg');
			img.src = morrisonsHost+'/graphics/storelocator/'+ showWelsh + DivBox.id+'_hover.jpg';
		}
		return false;
	}
}
function addMouseOut(obj, divID, imagePath)
{
	obj.onmouseout = function() {
		DivBox = document.getElementById(divID);
		var img = DivBox.getElementsByTagName("img")[0];
		img.src = imagePath;
	}
}
