//****************************Dynamic layer setup and scrolling function by Greg Sochanik(greg@zonegroup.com) for Orange June 2001 *************************************
//******************************************************************************************************************************************************************
	// This constant is the speed at which the nav slows down, before it reaches the edge of an image.The lower it is the longer it takes to slow down.
    decrement = 0.4
	scrollWidth = 353 // Must enter set width of main container parent layer in here for Netscapes benefit(for this site it's 353 )

//************ openPopup() Generic popup window function	*************************

	function openPopup(w,h,url,target) 
	{
		window.open(url,target,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width="+w+",height="+h)		
	}
	
	function openPopupScroll(w,h,url,target) 
	{
		window.open(url,target,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width="+w+",height="+h)		
	}
		
//************ openPopup() Generic popup window function with resizable turned on	********
	function openResizePopup(w,h,url,target) 
	{
		window.open(url,target,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1, width="+w+",height="+h)		
	}

//************ 	browserCheck() *********************************	
	// browserCheck is a function to check the browser that is being used. The function is then called as an object "is".
	function browserCheck() 
	{
		var b = navigator.appName
		if (b=="Netscape") this.b = "ns"
		else if (b=="Microsoft Internet Explorer") this.b = "ie"
		else this.b = b
		this.v = parseInt(navigator.appVersion)
		//this.ns = (this.b=="ns" && this.v>=4 && this.v<4.7 )
		this.nt = (navigator.appVersion.indexOf('NT')>0)
		this.ns4 = (this.b=="ns" && this.v>=4 && this.v < 5)
		this.ns5 = (navigator.appName == "Netscape" && navigator.appVersion.indexOf('5') == 0)? true:false
		this.ns6 = (document.getElementById)? true:false
		this.ie = (this.b=="ie" && this.v>=4)
		this.ie4 = (navigator.userAgent.indexOf('MSIE 4')>0)
		this.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0)||(navigator.userAgent.indexOf('MSIE 6')>0)
		this.ie55 = (navigator.userAgent.indexOf('MSIE 5.5')>0)
		if (this.ie5) this.v = 5
		this.min = (this.ns||this.ie)
		this.mac =(navigator.appVersion.indexOf("Mac")!=-1) 
	}
	//Sets up "is" as the browserCheck object
	is = new browserCheck()
	
	
	
//************ initLayers(objA, objB) ***************************	
	// This function initialises the two nav layers passed to it(objA and objB) as block and blockB in order to make them work across browsers
	function initLayers(objA,objB)
	{
		if(objA && objB)
		{
			
			//first child layer
   	  		if (is.ns4) block = eval('document.father.document.'+objA)
			if(is.ie4) block=layer2.style
			if (is.ie5) 	block = objA.style
			
			if (is.ns6) block = document.getElementById(objA).style
			// second child layer
			if (is.ns4) blockB = eval('document.father.document.'+objB)
			if (is.ie5) blockB = objB.style
			if(is.ie4) blockB = layer3.style
			if (is.ns6) blockB = document.getElementById(objB).style
			//parent layer
			if (is.ns4) mainLyr = document.father
			if (is.ie4|| is.ie5) mainLyr = father.style
			if (is.ns6) mainLyr = document.getElementById('father').style
			
		
			//sets a variable to equal the Xposition of a layer
			block.xpos = parseInt(block.left)
			blockB.xpos = parseInt(blockB.left)
			mainLyr.xpos = parseInt(mainLyr.left)
		
		
	/*	if(is.ie4||is.ie5)
		{
			imgAmnt = eval('document.'+parentlayer+'.document.'+layer+'.document.images['+imgName+'].src')
			//docAmnt = document.children.length
			alert(imgAmnt);
			for (i=0 ; i<imgAmnt;i++)
			{
				imgWidth=eval(objA+'.document.images['+i+'].width')
				imgLayer = eval(objA+'.document.images['+i+'].width')
				alert(imgLayer)
			}
		}		
		amtImages = eval('document.all.'+objA+'.document.images.length')		
		for (i=0; i<amtImages; i++)
		{
				img  = eval('document.'+objA+'.document.images['+i+'].src')
				alert(img)
		}*/
		
		//sets a variable to equal the width of the initialised layer
			if (is.ns4)
			{
				block.iWidth = parseInt(block.clip.width)
				blockB.iWidth = parseInt(blockB.clip.width)
				mainLyr.iWidth = parseInt(mainLyr.clip.width)
				
			}
			if (is.ie4||is.ie5||is.ns6)
			{
				
				block.iWidth = parseInt(block.width)
				blockB.iWidth = parseInt(blockB.width)
				mainLyr.iWidth = parseInt(mainLyr.width)
			}
			//sets a boolean variable to turn on and off the movement functions (false is off)
			block.loop = false
			//sets a boolean variable to turn on and off the inertia function (false is off)
			block.slowdown = false
			//sets block to false as default if whole page not yet loaded
			}
		else
		{
			block = false;
		}
	}
	
//**************** preload(imgObj, imgSrc) *************************
	//function to preload images and set them up as image objects for rollover calls. This must be done at the top of each html page as otherwise netscape doesn't like it.....
	function preload(imgObj, imgSrc)
	{
		if (document.images)
		{
			eval(imgObj+' = new Image()')
			eval(imgObj+'.src = "'+imgSrc+'"')
			
		}
	}

//*************** docfinderon() *************************************
	//function simply changes the search arrow to an on state once the text field
	//is on focus
	function docfinderimagestatus(type){
		if (type=='on'){
			if (is.ns4) document.layers['docsearch'].document.images['docsubmit'].src = 'http://www.safeandsounddev.cabinetuk.com/images/doc_finder_on.gif';
			else document.images['docsubmit'].src = 'http://www.safeandsounddev.cabinetuk.com/images/doc_finder_on.gif';
		}else{
			if (is.ns4) document.layers['docsearch'].document.images['docsubmit'].src = 'http://www.safeandsounddev.cabinetuk.com/images/doc_finder_off.gif';
			else document.images['docsubmit'].src = 'http://www.safeandsounddev.cabinetuk.com/images/doc_finder_off.gif';
		}
	}

//*************** submitLayerForm() **********************************
	//this function submits a form on a layer because of Netscape!
	function submitLayerForm(){
		if(is.ns4) document.layers['docsearch'].document.forms[0].submit();
		else document.forms[0].submit();
	}

//**************** changeImage(parentlayer,layer, imgName, imgObj) *********************
	// This is the function for image swaps. It works for  images on layers and nested layers, although it only works two layers deep in NS4. 
	// To use you put in a handler in the <a> tage wrapped around the graphic you want to swap or trigger the swap. The first argument
	//  is a string containing the name of the parent layer. If there is no parent layer you just enter null. The second argument is a string containing the name of the layer the image is on.
	// If it's not on a layer, simply enter null. The third argument is a string containing the name of the image you want to swap, declared ias an attribute of the <img> tag marking up the image.
	// The fourth argument is a string containing the name of the image (declared in the preload function above) you want to swap it with.
	// eg <a href="#" onmouseover="changeImage(null,null,'imageA','imageA_on')" onmouseover="changeImage(null,null,'imageA','imageA_off')"><img src="image.gif" name="imageA"></a>
	// The above code demostrates what the code should look like for a rollover on an image named 'imageA' that isn't on a layer.
	function changeImage(parentlayer,layer, imgName, imgObj)
	{
		if (!is.ns4)
		{
			document.images[imgName].src = eval(imgObj+".src");
			if(!is.ns5) document.images[imgName].blur();
		}
		else
		{
			if(document.layers && parentlayer != null && layer != null) 
			{
				eval('document.'+parentlayer+'.document.'+layer+'.document.images['+"imgName"+'].src= '+imgObj+'.src');
				
			}
			if(document.layers && parentlayer == null && layer != null) 
			{
				eval('document.'+layer+'.document.images['+"imgName"+'].src= '+imgObj+'.src');
			}
			else if (parentlayer==null && layer==null)
			{
				eval ('document.images['+imgName+'].src = '+imgObj+'.src');
			}
		}		
	}
	
//********************	 scrLeft(spd) ***********************************
	// This is the function to scroll a layer to the right. It is declared in a <a> tag as an onmouseover, using the boolean value block.loop as a switch.
	// the argument spd is an integer value representing the speed at which the layer moves, this can be adjusted in the function call.
	function scrLeft(spd)
	{
	    decrement = 0.1//speed at which layer slows before hitting the end of an ima
		if(screen.availWidth <= 1024 || is.nt) 
		{
		speed = spd-1
		time = 30

		}
		else
		{
			speed = spd 
			time=10
		}
		
		if(block.loop)// the swicth. Set to true on mouseover...false onmouseout. Defaults to false
		{
					
			block.xpos += speed //increments movement by spd*px/loop
			blockB.xpos += speed
			if (block.xpos >= mainLyr.iWidth)// if the first layer moves out of the visible area (ie width of the parent frame)
			{
					
					block.xpos = parseInt(blockB.xpos-block.iWidth)// Pop the layer on the left of the second layer
										
			}
			if(blockB.xpos >= (mainLyr.iWidth))// if the second layer moves out of the visible area
			{
					
					blockB.xpos = parseInt(block.xpos-blockB.iWidth)// Pop the layer on the end of the first layer
					
				
			}
			
			//status=('block.xpos = '+block.xpos)
			block.left = block.xpos;	//moves the layer
			blockB.left = blockB.xpos
			
			eval('setTimeout("scrLeft('+spd+')", '+time+')')//sets the speed of the loop
		}
		else
		{
			block.slowdown=true;// this occurs when the switch is set to false, only after it has been set to true
			slowdownLeft(speed,time);// calls the inertia function and passes the original variable spd to it.
			return false;
		}		
	}
		
//**************************scrRight(spd) ********************************************
	function scrRight(spd)// works exactly the same as scrLeft(spd) only scrolling the other way
	{
		decrement = 0.1
		if(screen.availWidth <=1024 || is.nt){
		 speed = spd-1
		 time=30
		 
		}
		else
		{
			speed = spd
			time=10
		}
		
		if(block.loop)
		{
			block.xpos -= speed
			blockB.xpos -= speed
			if (block.xpos <= (-block.iWidth))// If the first layer position is less than it's width (ie none of the layer is showing in the parent layer)
			{
				
				block.xpos = parseInt(blockB.iWidth+blockB.xpos)// Pop the layer on the right of the second layer (it's width plus it's position)
				
			}
			if (blockB.xpos <= (-blockB.iWidth))// If the second layer position is less than it's width (ie none of the layer is showing in the parent layer)
			{
				blockB.xpos = parseInt(block.iWidth+block.xpos)// Pop the layer on the right of the first layer (it's width plus it's position)
			}
			block.left = block.xpos;
			blockB.left = blockB.xpos;			
			eval('setTimeout("scrRight('+spd+')", '+time+')')
		}
		else
		{
			block.loop=false
			block.slowdown=true;
			slowdownRight(speed,time);
			return false;
		}
	}

//******************* 	slowdownLeft(speed) *************************
// Slowdown inertia functions	
	function slowdownLeft(speed,time)
	{
		
		if (block.slowdown && speed > 0 && !block.loop) //Only runs the function if all these things are true (ie the slowdown sitch is set to true, the loop switch is set to false)
		{
			
			speed -= decrement;// this reduces the speed of the movement by the decrement variable declared earlier				
			iPos = Math.floor(block.xpos)// Converts the decimal value of the first layers position to an integer to makle it easier to track
			iPosB = Math.floor(blockB.xpos)// Converts the decimal value of the second layers position to an integer to makle it easier to track
			
			// The following if statement tracks the positions of all the images on the layer. Each image position has four possible points as the same pixel is not always reached (movmenet increments by 3)
			// If four are chosen, one of them will always be reached.
			// When placing a new image on the nave bar, not only must you increase the width of the layer it's placed on by the width of the new image. You must also
			// declare the new layer position of the image by adding it's width to the last/ largest four numbers in this if statement. This must be done both for the first layer and the second loop layer.
			// ie if we place a new image on the layer that was width '50' and the original width of the layers were 350 then the new layer widths would be 400 and if the last four numbers 
			// in the if statement were
	/*	if(iPos == 2  || iPos==3 || iPos == 4|| iPos==5 || iPos == 71 || iPos == 72 || iPos == 73 || iPos == 74 || iPos == 150 || iPos == 151 || iPos == 152 || iPos == 153 || iPos == 245 ||iPos == 246 || iPos == 247 || iPos == 248 || iPos == 357 || iPos == 358 || iPos == 359 || iPos == 360 || iPos == 458 || iPos == 459 || iPos == 460 || iPos == 461 || iPos == 544 || iPos == 545 || iPos == 546 || iPos == 547 || iPosB == 71 || iPosB == 72 || iPosB == 73 || iPosB == 74 || iPosB == 150 || iPosB == 151 || iPosB == 152 || iPosB == 153 || iPosB == 245 ||iPosB == 246 || iPosB == 247 || iPosB == 248 || iPosB == 357 || iPosB == 358 || iPosB == 359 || iPosB == 360 || iPosB == 458 || iPosB == 459 || iPosB == 460 || iPosB == 461 ||  iPosB == 544 || iPosB == 545 || iPosB == 546 || iPosB == 547 || iPosB == -484 || iPosB == -485 || iPosB == -486 || iPosB == -487)
			{
			
			decrement = 0.4
			
			}*/
			block.xpos += speed
			blockB.xpos += speed
			block.left = block.xpos
			blockB.left = blockB.xpos
		
			eval('setTimeout("slowdownLeft('+speed+','+time+')", '+time+')')
		}				
		
		else
		{
			block.slowdown = false;
		}
	}

//************************ slowdownRight(speed) ***************************
	function slowdownRight(speed,time)
	{
		
		if (block.slowdown && speed > 0 && !block.loop)
		{	
			
			speed -= decrement;
			iPos = Math.floor(block.xpos)
			iPosB = Math.floor(blockB.xpos)
			
			block.xpos -= speed
			blockB.xpos -= speed
			block.left = block.xpos
			blockB.left = blockB.xpos
						
			eval('setTimeout("slowdownRight('+speed+','+time+')", '+time+')')
		}
		
		else
		{
			block.slowdown = false;
		}
		
	}
	

function initSize()
	{
		this.pgWidth = window.innerWidth;
		this.pgHeight= window.innerHeight;		
	}
	
	size = new initSize;
	
	
	function patentResizer()
	{
		if ((navigator.appName=="Netscape")&&(parseInt(navigator.appVersion)==4)) 
		{
				
			pgWidth=window.innerWidth; 
			pgHeight=window.innerHeight; 
			if(pgWidth!=size.pgWidth || pgHeight!=size.pgHeight)
			{
				location.reload();
				size.pgWidth = pgWidth;
				size.pgHeight = pgHeight;
			}			
		}
	}
		
	if (is.ns4 && !is.mac) document.captureEvents(Event.MOUSEMOVE)
	if (is.ns4 && !is.mac) document.onmousemove = patentResizer
	if (is.ns4 && is.mac) onresize = function() {location.reload();}
	   
	function layerPosition()
	{		
		if(is.ns4)
		{

		//	if(!is.mac){
				document.father.top = 91;
				document.team.top = 93;
		//	}

			iWidth = parseInt(window.outerWidth)
			if(screen.availWidth > 800)
			{			
				if(document.scrollertr != "Untitled Document" && iWidth > document.scrollertr.left)
				{					
					document.scrollertr.clip.width = iWidth - document.scrollertr.left - 16				
				}
				
			}
			if(document.scrollertr != "Untitled Document" && document.scrollertl != "Untitled Document" && document.father != "Untitled Document")
			{
			
			//	document.father.overflow="auto"
			//	document.father.clip.width = scrollWidth
			//	document.scrollertl.top = 92
			//	document.scrollertl.left = 323
			//	document.scrollertr.top =  92
			//	document.scrollertr.left = 699
			//	document.father.top = 91
			//	document.father.document.layer2.top = -2
			//	document.father.document.layer3.top = -2
			}
			if(document.title != "Orange Safe and Sound")
			{
				document.title.left = window.outerWidth - document.title.clip.width - 36
			}
			for(i=0; i< document.layers.length; i++)
			{
				document.layers[i].visibility="visible"
			}					
		}
		if(is.ns4)
		{
			if(document.scrollertr != "Untitled Document" && document.scrollertl != "Untitled Document" && document.father != "Untitled Document")
			{
			//	totalWidth=0
			//	imgAmnt = document.father.document.layer2.document.images.length
			//	for (i=0 ; i<imgAmnt;i++)
			//	{
			//		imgWidth=eval('document.father.document.layer2.document.images['+i+'].width')
			//		totalWidth += imgWidth
			//	}
			
			//	document.father.document.layer2.clip.width = totalWidth;
			//	document.father.document.layer3.clip.width = totalWidth;		
				
			}
		}
	
		if(is.ie4 || is.ie5)
		{
			if(document.all['scrollertl']&&document.all['scrollertr']&&document.all['father'])
			{
				
			//	scrollertl.style.top = 96
			//	scrollertr.style.top =  96
				
				if(!is.mac){
					father.style.top = 91;
					team.style.top = 93;
				}

				if(is.mac){
					if(document.title == 'Orange Insurance - Search'){
						father.style.top = 99;
						if(document.all['team']){team.style.top = 99;}
					}else{
						document.all['father'].style.top = 99;
						if(document.all['team']){document.all['team'].style.top = 99;}
					}
				}
				
				if(screen.availWidth > 800)
				{
					iWidth = parseInt(document.body.clientWidth)					
					if (iWidth > parseInt(scrollertr.style.left))
					{
						scrollertr.style.width = iWidth - parseInt(scrollertr.style.left);
						if(is.ie4 && !is.mac)
						{							
							father.style.clip = "rect(0 353px 16px 0)";
						}						
					}
				}
			}
			if(document.all['title'])
			{
				
				iWidth =parseInt(document.body.clientWidth);
				titleWidth = parseInt(title.style.width);
				if (document.body.scroll == 'no') title.style.left = iWidth - titleWidth - 25;
				else title.style.left = iWidth - titleWidth - 12;
			}
			if(!is.mac)
			{
				
				for(i=0; i<document.all.length; i++)
				{
						
						document.all[i].style.visibility = "visible"
							
				}
				
			}
			else // This inefficient peice of code is a result of a bug in IE where a flash embed is included among the elements in document.all as having .style.visibility but then returning an error!
					// It takes into account all the layers your ever likely to meet so all new layer must be included here or they will not appear on a IE5Mac
			{
				if(document.all['father']) document.all['father'].style.visibility = "visible";
				if(document.all['mother'])	document.all['mother'].style.visibility = "visible";
				if(document.all['sidenav']) document.all['sidenav'].style.visibility = "visible";
				if(document.all['mapnav']) document.all['mapnav'].style.visibility = "visible";
				if(document.all['picLyr']) document.all['picLyr'].style.visibility = "visible";
				if(document.all['copy']) document.all['copy'].style.visibility = "visible";
				if(document.all['title']) document.all['title'].style.visibility = "visible";				
				if(document.all['team']) document.all['team'].style.visibility = "visible";
				if(document.all['scrollertr']) document.all['scrollertr'].style.visibility = "visible";
				if(document.all['scrollertl']) document.all['scrollertl'].style.visibility = "visible";
				if(document.all['scrollerup']) document.all['scrollerup'].style.visibility = "visible";
				if(document.all['scrollerdown']) document.all['scrollerdown'].style.visibility = "visible";
				if(document.all['box']) document.all['box'].style.visibility = "visible";
				if(document.all['hidelayer']) document.all['hidelayer'].style.visibility = "visible";
				if(document.all['tophide']) document.all['tophide'].style.visibility = "visible";
				if(document.all['image']) document.all['image'].style.visibility = "visible";			 
			}
		}
		if(is.ns5)
		{		
				dom = document.getElementsByTagName('div')
				
				if(!is.mac){
					dom.father.style.top = 91;
					dom.team.style.top = 93;
				}

				//	arrImages = document.getElementsByTagName('img')
				if(dom.scrollertl&&dom.scrollertr&&dom.father)
				{
					dom.father.style.overflow = "auto"
				//	dom.scrollertl.style.top = 96
				//	dom.scrollertr.style.top =  96
				//	dom.father.style.top = 93
					
					if(screen.availWidth > 800)
					{
						iWidth = parseInt(window.innerWidth)
						if (iWidth > parseInt(dom.scrollertr.style.left))
						{												
							dom.scrollertr.style.width = iWidth - parseInt(dom.scrollertr.style.left) - 16
						}
					}
				}
				if(dom.title)
				{
					iWidth =parseInt(window.innerWidth)					
					titleWidth = parseInt(dom.title.style.width) 
					dom.title.style.left = iWidth - titleWidth - 22
				}				
				for (k=0; k<dom.length; k++)
				{
					
					if(dom[k].id != 'scrollerdown' || dom[k].id != 'scrollerup')
					{
						dom[k].style.visibility = "visible"						
					}
					
				}

			//	if(dom.scrollertl&&dom.scrollertr&&dom.father)
			//	{
			//		totalWidth=0
			//		imgAmnt = dom.layer2.getElementsByTagName('img').length				
			//		for (i=0 ; i<imgAmnt;i++)
			//		{
			//			imgWidth=eval('dom.layer2.getElementsByTagName("img")['+i+'].width')
			//			totalWidth += imgWidth
			//		}				
			//		dom.layer2.style.width = totalWidth;
			//		dom.layer3.style.width = totalWidth;			
			//	}
			}	
	}
	if(is.ie4 || is.ie5 || is.ns6) onresize = layerPosition
	
	