var currentID=1;
var maxID=7;
var rotate=true;
var secondsDelay=7;
var centreContentId="centreContent";
var timer = null;

var fpc = 0;
var fpca = Array();

function startRotate(){
	if(rotate){
		buildCentreCont(currentID);
		currentID++;
		if(currentID>maxID){currentID=1;}
		opacdir="grow";
		timer = setTimeout("startRotate()",(secondsDelay*1000));
	}
}

function restart(){
	rotate=true;
	startRotate();
	document.getElementById("pausebutton").innerHTML="<a href=\"#\" onclick=\"stopRotate(); return false;\">PAUSE</a>";
}

function stopRotate(){
	rotate=false;
	clearTimeout(timer);
	document.getElementById("pausebutton").innerHTML="<a href=\"#\" onclick=\"restart(); return false;\">PLAY</a>";
}

function swapCentreCont(targID){
	currentID=targID;
	buildCentreCont(targID);
	stopRotate();
}
function swapImageCont(targID){
	currentID=targID;
	buildCentreCont(targID);
}


function buildCentreCont(x){
	theCont=document.getElementById("cont" + x);
	if(theCont != null){
		theContHTML=theCont.innerHTML;
		thetargetDiv=document.getElementById(centreContentId);
		thetargetDiv.innerHTML=theContHTML + "</p><p>Displaying page <strong>" + currentID + "</strong> of <strong>" + maxID + "</strong></p>";
	}
}

function buildImageCont(x){
	theCont=document.getElementById("cont" + x);
	if(theCont != null){
		theContHTML=theCont.innerHTML;
		thetargetDiv=document.getElementById(centreContentId);
		thetargetDiv.innerHTML=theContHTML + "<p>Displaying image <strong>" + currentID + "</strong> of <strong>" + maxID + "</strong></p>";
	}
}

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(){
	// Rearrange h2 and h3 tags
	for (i = 1; i <= maxID; i++){
		a="cont" + i;
		// Get the background image
		if(b=document.getElementById(a)){
			var backgroundimage = b.style.backgroundImage;
			var titletag = '';
			var linktag = '';
			var boomcount = 0;
			oldinnerhtml = b.innerHTML;
			
			backgroundimage = backgroundimage.replace('url(','');
			backgroundimage = backgroundimage.replace(')','');
			
			// Split By <h2>
			var split1 = oldinnerhtml.split("<H2>");
			if(split1.length == 1){
				split1 = oldinnerhtml.split("<h2>");
			}
			if(split1.length > 1){
				// Then </h2>
				var split2 = split1[1].split("</H2>");
				if(split2.length == 1){
					split2 = split1[1].split("</h2>");
				}
				titletag = split2[0];
				boomcount++;
			}
			
			// Split By href="
			var split1 = oldinnerhtml.split("href=\"");
			if(split1.length > 1){
				// Then "
				var split2 = split1[1].split("\"");
				linktag = split2[0];
				boomcount++;
			}
			
			oldinnerhtml2 = oldinnerhtml.replace("</H3>","contentbreak");
			if(oldinnerhtml == oldinnerhtml2){
					oldinnerhtml2 = oldinnerhtml.replace("</h3>","contentbreak");
			}
			//alert(boomcount + ' : ' + oldinnerhtml2);
			if(boomcount == 2){
					var split3 = oldinnerhtml2.split("contentbreak");
					if(split3.length == 2){
							oldinnerhtml2 = '<a href=\'' + linktag + '\'><h2 style="cursor: pointer; cursor: hand;"><img src=\'' + backgroundimage + '\' alt=\'' + titletag + '\'>' + titletag + '</h2><h3 id="pulse' + i + '" style="cursor: pointer; cursor: hand;">' + titletag + '</h3></a>' + split3[1];
							
					}
			}
			
			b.innerHTML = oldinnerhtml2;
		}
	}
	
	
	for (i = 1; i <= maxID; i++){
		a="cont" + i;
		setStyleById(a, 'display', 'none');
	}
	buildCentreCont(1);
	setWidth();
	
	// Now Iterate through ids for images to create links
	for (i = 1; i <= maxID; i++){
		var subvalue = document.getElementById('imgLnk' + i);
		if(subvalue != null){
			subvalue.innerHTML = '<a href="#" onclick="swapCentreCont(' + i + '); return false;">' + subvalue.innerHTML + '</a>';
		}
	}
	
	// Div id swaplinks
	var subvalue = document.getElementById('swaplinks');
	var texttoset = '';
	for (i = 1; i <= maxID; i++){
		texttoset = texttoset + '<a href="#" onclick="swapCentreCont(' + i + '); return false;">' + i + '</a> | ';
	}
	
	texttoset = texttoset + '<span id="pausebutton"><a href="#" onclick="stopRotate(); return false;">PAUSE</a></span> |';
	subvalue.innerHTML = texttoset;

}

function setWidth(){
	brsW=document.body.offsetWidth;
	
	//alert(document.body.clientWidth);
	
	//return;
	/*
	if(brsW == null){
		brsW = document.body.clientWidth;
	}

	//brsW = brsW.replace(/px/,'');
	if(parseInt(brsW)<=980){
		//alert("resize")
		setStyleById("banner","width","984px");
		setStyleById("wrapperSS","width","984px");
		setStyleById("footer","width","984px");
		setStyleById("container","width","984px");
	}
	else{
		setStyleById("banner","width","AUTO");
		setStyleById("wrapperSS","width","AUTO");
		setStyleById("footer","width","AUTO");
		setStyleById("container","width","984px");
	}
	/**/
	setStyleById("wrapperSS","visibility","hidden");
	setStyleById("wrapperSS","visibility","visible");
	
	if(document.getElementById('indexDefaultMainContent')){
		setStyleById("indexDefaultMainContent","visibility","hidden");
		setStyleById("indexDefaultMainContent","visibility","visible");
		//alert("a");
	}
	if(document.getElementById('containerpr')){
		setStyleById("containerpr","visibility","hidden");
		setStyleById("containerpr","visibility","visible");
		//alert("a");
	}
	if(document.getElementById('centWrapper')){
		setStyleById("centWrapper","visibility","hidden");
		setStyleById("centWrapper","visibility","visible");
		//alert("a");
	}
	if(document.getElementById('bottomlineswitch')){
		setStyleById("bottomlineswitch","visibility","hidden");
		setStyleById("bottomlineswitch","visibility","visible");
		//alert("a");
	}
	if(document.getElementById('toplineswitch')){
		setStyleById("toplineswitch","visibility","hidden");
		setStyleById("toplineswitch","visibility","visible");
		//alert("a");
	}
	
	

}

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();} 
}

