var ajaxRequest = false;
try {
	ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	try {
		 ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
	 } catch (E) {
		 ajaxRequestajaxRequest = false;
   }  
}
if(!ajaxRequest &&typeof XMLHttpRequest != 'undefined'){
	ajaxRequest = new XMLHttpRequest();
}
if (!ajaxRequest){alert("Your browser does not support AJAX");}
//-------------------------------------end Ajax setup --------------------------
var i=2;
var stopSetInterval=0;
var interval;
//--------------------------------------Select Interval-------------------------
function getSecs(data){
	ajaxRequest.open("GET", "wip.php");
	ajaxRequest.onreadystatechange  = function(){
		if(ajaxRequest.readyState == 4 &&  ajaxRequest.status == 200){
			interval=data;
			i=2;
			document.getElementById("int").innerHTML="Interval set to <br /><strong>" +interval+ "</strong> seconds";
			document.getElementById("defaultInterval").innerHTML="You may reset this:";
		}
	}
	ajaxRequest.send(null);
}
//--------------------------------------Display Badges-------------------------
function ajaxDisplayBadge(button,srvrPage){
	var obj =document.getElementById("start");
	ajaxRequest.open("GET", srvrPage);
	ajaxRequest.onreadystatechange  = function(){
		if(ajaxRequest.readyState == 4 &&  ajaxRequest.status == 200){
			switch(button){
			case 'pauseTheDisplay':
				obj.innerHTML=ajaxRequest.responseText;
				var pauseDisplay=parseInt(readCookie('pauseDisplay'));
				clearInterval(stopSetInterval);
				//displayImage(pauseDisplay);
				break;
			case 'resumeTheDisplay':
				obj.innerHTML=ajaxRequest.responseText;
				var pauseDisplay=parseInt(readCookie('pauseDisplay'));
					if (pauseDisplay==8){
						i =2;
						displayImage(1);	
						run();
					}else{
						i=pauseDisplay+2;
						displayImage(pauseDisplay+1);	
						run();
					}	
				break;
			default:		
				clearInterval(stopSetInterval);
				displayImage(1);	
				i=2;
				obj.innerHTML=ajaxRequest.responseText;
				run();
			}
		}
	}
		ajaxRequest.send(null);
}
function run(){
	stopSetInterval=setInterval("display_badge()", interval*1000);
}
function display_badge(){	
	if (i == 9){i = 1;}
	displayImage(i);	
		i++;
}
function displayImage(i){
			switch (i){
			case 1:
				document.wip.src ='images/herald badge/1_design.jpg';
				document.getElementById("imageText").innerHTML="1. As with all our work, before a graver is touched the design and method of construction is fully thought through and working drawings produced.  These are in front of Ian throughout the engraving stage.<br /><br />This project required every item to be engraved twice as we will explain with the next image.<br /> ";
				createCookie('pauseDisplay',1,0);	
			break;
			case 2:
				document.wip.src ='images/herald badge/2_arms_cutting_out.jpg';
				document.getElementById("imageText").innerHTML="2. The shield has been engraved, twice, in silver. &nbsp; The insignia which appear in each quarter of the shield are pierced out by Fraser from the first engraving: illustrated top left.  Fraser will now hard-solder them  precisely over their twins in the second engraving, bottom left.";
				createCookie('pauseDisplay',2,0);	
			break;
			case 3:
				document.wip.src ='images/herald badge/3_crown_standrew_cutting_out.jpg';
				document.getElementById("imageText").innerHTML="3. The same procedure is followed for the crown and the figure of St Andrew.";
				createCookie('pauseDisplay',3,0);	
			break;
			case 4:
				document.wip.src ='images/herald badge/4_rim_cut_out_one.jpg';
				document.getElementById("imageText").innerHTML="4. The rim comprises three elements: this image shows, on the left, the centre plate on which the dome will eventually be mounted. Top right is the rim which will be soldered over the centre plate, before it is fully pierced out.<br />When both rims have been fixed in place and the excess metal has been removed, the rim is filed to give it the shape you see in the finished item.";	
				createCookie('pauseDisplay',4,0);	
			break;
			case 5:
				document.wip.src ='images/herald badge/5_rim_cut_out_two.jpg';
				document.getElementById("imageText").innerHTML="5. Before the rim is soldered in position the other side of the centre plate is protected so that the silver solder does not encroach on the part to which the rear rim will be fixed.";
				createCookie('pauseDisplay',5,0);	
			break;
			case 6:
				document.wip.src ='images/herald badge/6_dome_beating.jpg';
				document.getElementById("imageText").innerHTML="6. Each dome is beaten out by Alan.";
				createCookie('pauseDisplay',6,0);	
			break;
			case 7:
				document.wip.src ='images/herald badge/7_parts_for_assembly.jpg';
				document.getElementById("imageText").innerHTML="7. The rear dome has been fixed in position and will now be polished by Alan.  The crown, St Andrew and shield will be gilded and fixed to the domes.";
				createCookie('pauseDisplay',7,0);	
			break;
			case 8:
				document.wip.src ='images/herald badge/8_gilded_assembled.jpg';
				document.getElementById("imageText").innerHTML="8. The completed badge.";
				createCookie('pauseDisplay',8,0);	
			break;
			default:
		}
}
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}