// Vignette Generated Content Marker - DO NOT REMOVE
// stores reference to XMLHttpRequest object
var xmlHttp = createXmlHttpRequestObjectKFC();
	
//Retrieves XMLHttpRequest object
function createXmlHttpRequestObjectKFC() {
	//will store the reference to the XMLHttpRequest object
	var xmlHttp;
	//if running Internet Explorer
	if(window.ActiveXObject) {
       try {
           xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
       }
		catch (e) {
		xmlHttp = false;
		}
	} else {
		// if running Mozilla or other
		try {
			xmlHttp = new XMLHttpRequest();
		}
		catch (e) {
			xmlHttp = false;
		}
	}
	//return the created object or display an error message
	if (!xmlHttp) {
		alert("Error here");
	} else {
		return xmlHttp;
	}
}

//Make asynchronous HTTP request using the XMLHttpRequest object
function enLargeImg(image, rollover) {
//alert(name +", "+ type);
	//proceed only if xmlHttp object isn't busy
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0) {
		xmlHttp.open("GET", "http://www.ivillage.co.uk/kfc/enlarge.xml?image=" + image + "&rollover=" + rollover, true);
		//define the method to handle server responses
		xmlHttp.onreadystatechange = handleServerResponseKFC;
		//make the server request
		xmlHttp.send(null);
	} else {
		//if the connection is busy try again after 1 second
		setTimeout('enLargeImg("'+ image +'");', 100);
	}
}
	
//executed automatically when a message is received from the server
function handleServerResponseKFC() {
	//move forward only if transaction has completed
	if (xmlHttp.readyState == 4) {
		//status of 200 indicates the transaction completed successfully
		if (xmlHttp.status == 200) {
			//extract the XML received from the server
			xmlResponse = xmlHttp.responseXML;
			//obtain the document element (the root element) of the XML structure
			xmlDocumentElement = xmlResponse.documentElement;
			imageArray = xmlDocumentElement.getElementsByTagName("image");
		    rolloverArray = xmlDocumentElement.getElementsByTagName("rollover");
			var html = "";
			//iterate through arrays to create html structure
			for (var i=0; i<imageArray.length; i++) {
				if (rolloverArray.item(i).firstChild.data == "none") {
					html += "<img src=\"http://i.ivillage.co.uk/uk_en/microsite/kfc/"+ imageArray.item(i).firstChild.data+"\" onmouseover=\"javascript:rollOver('"+ rolloverArray.item(i).firstChild.data+"')\" onmouseout=\"javascript:rollOut('"+ rolloverArray.item(i).firstChild.data+"')\" alt=\"\" />";
				} else {
					html += "<div id=\""+ rolloverArray.item(i).firstChild.data+"\"><img src=\"http://i.ivillage.co.uk/uk_en/microsite/kfc/"+ rolloverArray.item(i).firstChild.data+".jpg\"></div><img src=\"http://i.ivillage.co.uk/uk_en/microsite/kfc/"+ imageArray.item(i).firstChild.data+"\" onmouseover=\"javascript:rollOver('"+ rolloverArray.item(i).firstChild.data+"')\" onmouseout=\"javascript:rollOut('"+ rolloverArray.item(i).firstChild.data+"')\" alt=\"\" />";
				}
			}
			//update the client display with data received from the server
			var divMessage = document.getElementById("facts_enlargedImg");
		   	divMessage.innerHTML = html;
		   
			
		} else {
			//a http status different that 200 signals an error
			alert("problem: " + xmlHttp.statusText);
		}
	}
}

function rollOver(rollover) {
	if (rollover == "none") {
	} else {
 		document.getElementById(rollover).style.display = "block";
	}
}

function rollOut(rollover) {
	if (rollover == "none") {
	} else {
		 document.getElementById(rollover).style.display = "none";
	}
}