// IWD Rotater JS


var currentID=1;
var maxID=12;
var rotate=true;
var secondsDelay=5;
var centreContentId="centreContent";
var timer = null;
var thisbefore=maxID;
var thisafter=2;
var highlighted=1;


function startRotate(){
	if(rotate){
		buildCentreCont(currentID);
		countCurrentID(1);
		timer = setTimeout("startRotate()",(secondsDelay*1000));
	}
}

function countCurrentID(x){
	currentID=currentID+x;	
	if(currentID>maxID){currentID=1;}
	thisbefore=currentID-1;
	thisafter=currentID+1;
	if(thisbefore<1){thisbefore=maxID;}
	if(thisafter>maxID){thisafter=1;}	
}

function restart(){
	rotate=true;
	for (i = 1; i <= maxID; i++){  
		thisbefore=i-1;
		thisafter=i+1;
		if(thisbefore<1){thisbefore=maxID;}
		if(thisafter>maxID){thisafter=1;}
		document.getElementById("buttonControl" + i).innerHTML="<img src=\"/images/playButtons/playInactive.gif\" alt=\"currently playing\"> <a href=\"#\" onclick=\"stopRotate(); return false;\" style=\"text-decoration:none\"><img src=\"/images/playButtons/pause.gif\" alt=\"pause\"></a> <a href=\"#\" onclick=\"swapCentreCont(" + thisbefore + "); return false;\" style=\"text-decoration:none\"><img src=\"/images/playButtons/back.gif\" alt=\"back\"></a> <a href=\"#\" onclick=\"swapCentreCont(" + thisafter + "); return false;\" style=\"text-decoration:none\"><img src=\"/images/playButtons/forward.gif\" alt=\"forward\"></a>";
	}
	countCurrentID(0)
	buildCentreCont(currentID);
	startRotate();
}

function stopRotate(){
	rotate=false;
	for (i = 1; i <= maxID; i++){  
		thisbefore=i-1;
		thisafter=i+1;
		if(thisbefore<1){thisbefore=maxID;}
		if(thisafter>maxID){thisafter=1;}
		document.getElementById("buttonControl" + i).innerHTML="<a href=\"#\" onclick=\"restart(); return false;\" style=\"text-decoration:none\"> <img src=\"/images/playButtons/play.gif\" alt=\"play\"></a> <img src=\"/images/playButtons/pauseInactive.gif\" alt=\"currently paused\"> <a href=\"#\" onclick=\"swapCentreCont(" + thisbefore + "); return false;\" style=\"text-decoration:none\"><img src=\"/images/playButtons/back.gif\" alt=\"back\"></a> <a href=\"#\" onclick=\"swapCentreCont(" + thisafter + "); return false;\" style=\"text-decoration:none\"><img src=\"/images/playButtons/forward.gif\" alt=\"forward\"></a>";
	}
	countCurrentID(-1);
	buildCentreCont(currentID);
	clearTimeout(timer);
}

function swapCentreCont(targID){
	currentID=targID;
	countCurrentID(1);
	buildCentreCont(targID);
	stopRotate();
}

function buildCentreCont(x){
	theCont=document.getElementById("cont" + x);
	if(theCont != null){
		theContHTML=theCont.innerHTML;
		thetargetDiv=document.getElementById(centreContentId);
		thetargetDiv.innerHTML=theContHTML; 
		swapInactive(highlighted); 
		swapActive(x); 
		highlighted=x;
	}

}

function setStyleById(i, p, v) {
	if(i != null && i != ""){
		var n = document.getElementById(i);
		if(n != null){	
			n.style[p] = v;
		}
	}
}

function init(){
	setWidth();
	for (i = 1; i <= maxID; i++){
		a="cont" + i;
		setStyleById(a, 'display', 'none');
	}
	startRotate();
	setWidth();
}


function pageSetup(){ // draw the page
	for (i = 1; i <= maxID; i++){
		a="cont" + i;
		setStyleById(a, 'display', 'none');
	}
	buildCentreCont(1);
	setWidth();
}

function buttonControl(before,after){ // write out the play/pause/back/forward buttons
	if(after>1){
	document.write("<div id=\"buttonControl"+(after-1)+"\" style=\"float:right; padding:30px 25px 0px 0px;\">")
	} else {
	document.write("<div id=\"buttonControl"+(before+1)+"\" style=\"float:right; padding:30px 25px 0px 0px;\">")	
	}
	document.write("<img src=\"/images/playButtons/playInactive.gif\" alt=\"currently playing\"> <a href=\"#\" onclick=\"stopRotate(); return false;\" style=\"text-decoration:none\"><img src=\"/images/playButtons/pause.gif\" alt=\"pause\"></a> ");
	document.write("<a href=\"#\" onclick=\"swapCentreCont(" + before + "); return false;\" style=\"text-decoration:none\"><img src=\"/images/playButtons/back.gif\" alt=\"back\"></a> ")
	document.write("<a href=\"#\" onclick=\"swapCentreCont(" + after + "); return false;\" style=\"text-decoration:none\"><img src=\"/images/playButtons/forward.gif\" alt=\"forward\"></a></div>");
	
}

function shopWinOpen(){
	document.write("<tab");
	document.write("le style='align: center; text-align: center; margin: 0px 0px 0px 0px;'><t");
	document.write("r>");
}
function shopWinClose(){
	document.write("</t");
	document.write("r></tab");
	document.write("le>");
}
function writeShopWindowButton(x,text){
	document.write("<td id=\"imgLnk" + x + "\" class=\"imgLinkHP\" style=\"width:86px; background-image:url(images/buttonBackgrounds/" + inactiveImg + "); height:50px; background-repeat:no-repeat;\"><a style=\"display:block; width:86px;\" onMouseOver=\"swapMouseOver(" + x + ");\" onMouseOut=\"swapMouseOut(" + x + ");\" href=\"#\" onclick=\"swapCentreCont(" + x + "); return false;\">" + text + "</a></td>");
}

function swapMouseOver(x){
	setStyleById(("imgLnk"+x), "backgroundImage", "url(images/buttonBackgrounds/" + mouseOverImg + ")")
}
function swapMouseOut(x){
	if(x==highlighted){
		setStyleById(("imgLnk"+x), "backgroundImage", "url(images/buttonBackgrounds/" + activeImg + ")")
	}else{
		setStyleById(("imgLnk"+x), "backgroundImage", "url(images/buttonBackgrounds/" + inactiveImg + ")")
	}
}
function swapActive(x){
	setStyleById(("imgLnk"+x), "backgroundImage", "url(images/buttonBackgrounds/" + activeImg + ")")
}
function swapInactive(x){
	setStyleById(("imgLnk"+x), "backgroundImage", "url(images/buttonBackgrounds/" + inactiveImg + ")")
}

function setWidth(){
	brsW=document.body.offsetWidth;
	setStyleById("wrapperIWD","visibility","hidden");
	setStyleById("wrapperIWD","visibility","visible");
	
	if(document.getElementById('content')){
		setStyleById("content","visibility","hidden");
		setStyleById("content","visibility","visible");
	}
	if(document.getElementById('containerpr')){
		setStyleById("containerpr","visibility","hidden");
		setStyleById("containerpr","visibility","visible");
	}
	if(document.getElementById('centWrapper')){
		setStyleById("centWrapper","visibility","hidden");
		setStyleById("centWrapper","visibility","visible");
	}
	if(document.getElementById('bottomlineswitch')){
		setStyleById("bottomlineswitch","visibility","hidden");
		setStyleById("bottomlineswitch","visibility","visible");
	}
	if(document.getElementById('toplineswitch')){
		setStyleById("toplineswitch","visibility","hidden");
		setStyleById("toplineswitch","visibility","visible");
	}
}

function setHeight(){
	if(document.getElementById('productimages')){
			var imageheight = document.getElementById('productimages').offsetHeight;
			//alert(imageheight);
			setStyleById('destext',"height",imageheight + "px");
			setStyleById('destext',"min-height",imageheight + "px");
		}	
}

function getStyle(el,styleProp)
{
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

function jumpto(x){

if (document.form1.jumpmenu.value != "null") {
	document.location.href = x
	}
}

function resizeScrollDiv(){
	var scrollDiv = document.getElementById('scroller');
	if(scrollDiv != null){
		if(document.body.offsetWidth > 800){
			scrollDiv.style.width = document.body.offsetWidth - 190;
		}
		else{
			
		}
	}
}

 function setrollovercolour(colortouse){
 	document.getElementById('clrcell').style.backgroundColor = '#' + colortouse;
	document.getElementById('fontcolor').value = '#' + colortouse;
 }

function phoneMsg(x){
	d=document.getElementById('phoneorderid');
	if(x>0){
	d.innerHTML="<div style=\"font-size:11px; padding:6px 12px 6px 12px; border:1px solid #999999; background-color:#ffffcc;\"><p>We can accept orders by phone between 10am and 5pm, Monday to Friday inclusive.</p><p>Call us on <strong>01592 561017</strong> and we will be happy to complete your order.</p><p><a href='javascript:phoneMsg(0);'>Close This [x]</a></p></div>";	
	} else {
	d.innerHTML="";
	}
	d.blur();
	
}

function addonresize(){
 	window.onresize=function(){ setWidth();} 
}
