/** Local Variable settings **/

var curLocation = location.host;

var arrType = new Array();
arrType['langpage'] = /^(en)$/i
//var LanguageList = new Array('en','de','fr');

var LanguageText = new Array();
LanguageText['en'] = 'English';
LanguageText['fr'] = 'Fran&#231;ais';
LanguageText['de'] = 'Deutsch';

/** creates an extra stylesheet **/
function addStyles(){

	//** Build js rendered stylesheet that css validators fail on **
	var jstyle = document.getElementsByTagName("head")[0];
	var lk = document.createElement("link");
	jstyle.appendChild(lk);
	lk.setAttribute("rel", "stylesheet");
	lk.setAttribute("type", "text/css");
	lk.setAttribute("href", "/js-vl.css");
}

function siteSearch(formObj){

	sQuery = formObj.search.value;

	if(sQuery.replace(/ /gi,"") != '')
	{
		top.location = "/search/"+sQuery.replace(/ /gi,"%20");
	}

	return false;
}


function countSearch(){

	if(document.getElementById("sCount"))
	{
		searchRes = document.getElementById("errpage").getElementsByTagName("p").length-1;
		document.getElementById("sCount").innerHTML = "<strong>"+searchRes+"</strong>";
	}
}

function setHeight(){
	
	if(document.getElementById("page")){
	bHeight = document.getElementsByTagName("body")[0].offsetHeight;
	pHeight = document.getElementById("page").offsetHeight;
	if(pHeight>bHeight){document.getElementsByTagName("body")[0].style.height = "auto";}
	}
}

function regExTest(arr, val){

if(val == '/')val = 'en';
val = val.replace("/","");

	if(arrType[arr])return arrType[arr].test(val);
}

function setContactForm(){

	$("a.popupcontact").attr("href","#contact");
	
	$("a.popupcontact").click(function(e){
		
		cType = "fibracon";
		if($(this).hasClass('popupcontactins'))cType = "insoll";
		
		e.preventDefault();
		loadContactForm(cType);
	});
	
}


function loadContactForm(cType){
	
	$("div#generalpopupbg").remove();
	$("div#generalpopup").remove();
	
	iframeLocation = "/js-contact.mfp";
	if(cType == "insoll")iframeLocation = "/ijs-contact.mfp";
	
	$('body').append('<div id="generalpopupbg"></div><div id="generalpopupcont"></div>');
	contactContent = '<iframe width="630" height="100%" frameborder="0" scrolling="auto" marginheight="0" marginwidth="0" src="'+iframeLocation+'"></iframe><a id="popclose" title="Close pop-up info box - click here" href="javascript:closeContactForm()"></a>';

	$("div#generalpopupcont").html(contactContent);
	$("div#generalpopupbg").fadeTo(200,0.7, function(){$("div#generalpopupcont").show();});
	
	generalPopupResize();
	
	$(window).resize(function() {

		generalPopupResize();
	});
	
	$("div#generalpopupbg").click(function(){closeContactForm();});
}

function generalPopupResize(){

	windowHeight = $(window).height();
	popupHeight = windowHeight-240;
	if(popupHeight<500)popupHeight = windowHeight-140;
	
	popupMargin = Math.floor((popupHeight/2)*-1);

	$('div#generalpopupcont').css({"width":"630px","height":popupHeight+"px","margin-top":popupMargin+"px"});
}

function closeContactForm(){

	$("div#generalpopupcont").hide(0,function(){
		$("div#generalpopupbg").fadeTo(200,0,function(){
			$("div#generalpopupbg").remove();$("div#generalpopup").remove();
		});
	});
}

function setAttachmentLinks(){
	
	fieldName = $("div.fiContainer").attr("rev");
	fieldLabel = $("div.fiContainer").attr("rel");
	
	$("div.fiContainer").html('<label for="im'+fieldName+'">'+fieldLabel+'</label><p class="fakelabel"><a href="#attachments" id="attachmentsLink">Need to send an attachment? Click here.</a></p>');

	$("a#attachmentsLink").click(function(e){
	
		e.preventDefault();
		setAttachments();
	});
}

function setAttachments(){
	
	fieldName = $("div.fiContainer").attr("rev");
	fieldLabel = $("div.fiContainer").attr("rel");
	totalAttachments = $("input[name='"+fieldName+"[]']").length;
	
	if(totalAttachments == 0){$("div.fiContainer").html('');}
	
	if(totalAttachments<5){
	$("a#attachmentsLink").remove();
	$("div.fiContainer").append('<label for="im'+fieldName+totalAttachments+'">'+fieldLabel+'</label><input type="file" id="im'+fieldName+totalAttachments+'" class="field" name="'+fieldName+'[]" style="width:245px;" /> <a href="#addattachments" id="attachmentsLink" style="float:left;">Add another</a>');
	}
	
	if(totalAttachments>=4)$("a#attachmentsLink").remove();
	
	$("a#attachmentsLink").click(function(e){
	
		e.preventDefault();
		setAttachments();
	});
}


function getMap(smap){

	if(smap == 'fibracon')
	{
		mapHtml = '<iframe width="447" height="344" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.co.uk/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=Fibracon+Twin+Ltd+6+Bowden+Hey+Road&amp;sll=53.328694,-1.908788&amp;sspn=0.073712,0.154324&amp;ie=UTF8&amp;hq=Fibracon+Twin+Ltd+6+Bowden+Hey+Road&amp;hnear=&amp;cid=8107026240902714980&amp;ll=53.342353,-1.902695&amp;spn=0.035871,0.072956&amp;z=13&amp;iwloc=A&amp;output=embed"></iframe>';
	}
	else if(smap == 'insoll')
	{
		mapHtml = '<iframe width="447" height="344" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.co.uk/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=Insoll+Components+Ltd&amp;sll=53.800651,-4.064941&amp;sspn=19.385722,39.506836&amp;ie=UTF8&amp;hq=Insoll+Components+Ltd&amp;hnear=&amp;cid=2240438683728669829&amp;ll=51.979488,-0.266933&amp;spn=0.037007,0.072956&amp;z=13&amp;iwloc=A&amp;output=embed"></iframe>';
	}
	
	if(!document.getElementById("popinfo"))
	{
		var parentBody = document.getElementsByTagName("body")[0];
		var popdiv = document.createElement("div");
		var popinner = document.createElement("div");
		var popclose = document.createElement("a");
		parentBody.appendChild(popdiv);
		popdiv.appendChild(popclose);
		popdiv.appendChild(popinner);
		popdiv.setAttribute("id", "popinfo");
		popinner.setAttribute("id", "popcontent");
		popclose.setAttribute("id", "popclose");
		popclose.setAttribute("title", "Close pop-up info box - click here");
		popclose.setAttribute("href", "javascript:closeMap()");
	}
	
	document.getElementById("popinfo").style.display = "block";
	document.getElementById("popcontent").innerHTML= mapHtml;
}

function closeMap(){

	document.getElementById('popinfo').style.display = 'none';
	document.getElementById('popcontent').innerHTML = '';
}

var sFadeA;
var sFadeB;

/** loop function for fading and moving objects - start **/
function valueCounter(id, opacStart, opacEnd, tFunction, millisec) { 

clearTimeout(sFadeA);
clearTimeout(sFadeB);

var speed = Math.round(millisec / 100); 
var timer = 10; 

if(opacStart > opacEnd) { 
 for(i = opacStart; i >= opacEnd; i--) { 
     sFadeA = setTimeout("changeValues(" + i + ",'" + id + "','" + tFunction + "')",(timer * speed)); 
     timer++; 
 } 
} else if(opacStart < opacEnd) { 
 for(i = opacStart; i <= opacEnd; i++) 
 { 
     sFadeB =setTimeout("changeValues(" + i + ",'" + id + "','" + tFunction + "')",(timer * speed)); 
     timer++; 
 } 
} 
} 

function changeValues(nValue, id, tFunction) { 
	
	if(tFunction == "opacity")
	{
		var object = document.getElementById(id).style; 
		object.filter = "alpha(opacity=" + nValue + ")"; 
		object.opacity = (nValue / 100); 
		object.MozOpacity = (nValue / 100); 
		object.KhtmlOpacity = (nValue / 100); 
	}
	else if(tFunction == "top")
	{
		document.getElementById(id).style.top = "-"+nValue+"px";
	}
}

var nxtTimer;

function flashHome(curLoop,curDiv){

	if(regExTest('langpage', location.pathname))
	{
		clearTimeout(nxtTimer);
		fDiv = document.getElementById("photostrip").getElementsByTagName("div");
		fImage = document.getElementById("photostrip").getElementsByTagName("img");
		fImages = fImage.length;

		if(curLoop>=fImages){curLoop=0;}
		if(curDiv>=fDiv.length){curDiv=0;}
		nxtDiv = curDiv+1;

		for(d=0;d<fDiv.length;d++)
		{
			curFDiv = fDiv[d];
			curFDiv.style.zIndex = "1";
		}

		fDiv[curDiv].style.zIndex = "2";

		strLoop = curLoop;
		curLoop=curLoop+1;

		for(g=0;g<fImage.length;g++)
		{
			curNImg = fImage[g];
			curNImg.style.opacity = "1";
			curNImg.style.filter = "alpha(opacity=100)";

			newImgId = "FlashImgId"+g;
			if(!document.getElementById(newImgId)){curNImg.setAttribute("id",newImgId);}
		}

		fimgidStr = "FlashImgId"+(curLoop+7);
		document.getElementById(fimgidStr).style.opacity = "1";
		document.getElementById(fimgidStr).style.filter = "alpha(opacity=100)";


		cid=strLoop;
		imgTimerA = setTimeout("$('#FlashImgId'+cid).fadeTo(1000,0, function() {})",1500);
		cida=strLoop+1;
		imgTimerB = setTimeout("$('#FlashImgId'+cida).fadeTo(1000,0, function() {})",2000);
		cidb=strLoop+2;
		imgTimerC = setTimeout("$('#FlashImgId'+cidb).fadeTo(1000,0, function() {})",2500);
		cidc=strLoop+3;
		imgTimerD = setTimeout("$('#FlashImgId'+cidc).fadeTo(1000,0, function() {})",3000);
		cidd=strLoop+4;
		imgTimerE = setTimeout("$('#FlashImgId'+cidd).fadeTo(1000,0, function() {})",3500);
		cide=strLoop+5;
		imgTimerF = setTimeout("$('#FlashImgId'+cide).fadeTo(1000,0, function() {})",4000);
		cidf=strLoop+6;
		imgTimerG = setTimeout("$('#FlashImgId'+cidf).fadeTo(1000,0, function() {})",4500);
		cidg=strLoop+7;
		imgTimerH = setTimeout("$('#FlashImgId'+cidg).fadeTo(1000,0, function() {})",5000);
		cidh=strLoop+8;
		imgTimerI = setTimeout("$('#FlashImgId'+cidh).fadeTo(1000,0, function() {})",5500);

		nxtLoop = curLoop+8;
		nxtTimer = setTimeout("flashHome("+nxtLoop+","+nxtDiv+")",6700);
	}
}


var newsTimer;

function rotateNews(newsNum){

	if(document.getElementById("newscontenth"))
	{
		clearTimeout(newsTimer);
		hpNews = document.getElementById("newscontenth").getElementsByTagName("p").length;

		if(newsNum >= hpNews){newsNum=0;}
		fadecontentviewer.init("newscontenth", "hnitem", "newschp", newsNum, 600);

		nxtNews = newsNum+1;
		newsTimer = setTimeout("rotateNews("+nxtNews+")",4000);
	}
}

var latestTimer;

function rotateLatest(newsNum){

	if(document.getElementById("latestevents"))
	{
		clearTimeout(latestTimer);
		hpNews = document.getElementById("latestevents").getElementsByTagName("div").length;

		if(hpNews>1)
		{
			if(newsNum >= hpNews){newsNum=0;}
			fadecontentviewer.init("latestevents", "latestc", "latesteventsm", newsNum, 600);

			nxtNews = newsNum+1;
			latestTimer = setTimeout("rotateLatest("+nxtNews+")",5000);
		}
	}
}

var rba;
var rbb;
var rbc;
var rbd;

function homeBullets(newsNumb){

	newsNum=1;
	if(regExTest('langpage', location.pathname))
	{
		clearTimeout(rba);
		clearTimeout(rbb);
		clearTimeout(rbc);
		clearTimeout(rbd);
		
		document.getElementById("homebulletscont").getElementsByTagName("div")[0].style.visibility = 'visible';
		document.getElementById("homebulletscont").getElementsByTagName("div")[0].style.zIndex = '100';
		document.getElementById("homebulletscontb").getElementsByTagName("div")[0].style.visibility = 'visible';
		document.getElementById("homebulletscontb").getElementsByTagName("div")[0].style.zIndex = '100';
		document.getElementById("homebulletscontc").getElementsByTagName("div")[0].style.visibility = 'visible';
		document.getElementById("homebulletscontc").getElementsByTagName("div")[0].style.zIndex = '100';
		document.getElementById("homebulletscontd").getElementsByTagName("div")[0].style.visibility = 'visible';
		document.getElementById("homebulletscontd").getElementsByTagName("div")[0].style.zIndex = '100';
		
		rba = setTimeout("homeBulletsA("+newsNum+")",2000);
		rbb = setTimeout("homeBulletsB("+newsNum+")",4000);
		rbc = setTimeout("homeBulletsC("+newsNum+")",6000);
		rbd = setTimeout("homeBulletsD("+newsNum+")",8000);
	}
}

var bulletAtimer;
var bulletBtimer;
var bulletCtimer;
var bulletDtimer;

function homeBulletsA(newsNum){

	if(document.getElementById("homebulletscont"))
	{
		clearTimeout(bulletAtimer);
		hpNews = document.getElementById("homebulletscont").getElementsByTagName("div").length;

		if(hpNews>1)
		{
			if(newsNum >= hpNews){newsNum=0;}
			fadecontentviewer.init("homebulletscont", "homebullets", "homebulletslink", newsNum, 600);

			if(regExTest('langpage', location.pathname))
			{
				nxtNews = newsNum+1;
				bulletAtimer = setTimeout("homeBulletsA("+nxtNews+")",8000);
			}
		}
	}
}

function homeBulletsB(newsNum){

	if(document.getElementById("homebulletscontb"))
	{
		clearTimeout(bulletBtimer);
		hpNews = document.getElementById("homebulletscontb").getElementsByTagName("div").length;

		if(hpNews>1)
		{
			if(newsNum >= hpNews){newsNum=0;}
			fadecontentviewer.init("homebulletscontb", "homebullets", "homebulletslinkb", newsNum, 600);

			if(regExTest('langpage', location.pathname))
			{
				nxtNews = newsNum+1;
				bulletBtimer = setTimeout("homeBulletsB("+nxtNews+")",8000);
			}
		}
	}
}

function homeBulletsC(newsNum){

	if(document.getElementById("homebulletscontc"))
	{
		clearTimeout(bulletCtimer);
		hpNews = document.getElementById("homebulletscontc").getElementsByTagName("div").length;

		if(hpNews>1)
		{
			if(newsNum >= hpNews){newsNum=0;}
			fadecontentviewer.init("homebulletscontc", "homebullets", "homebulletslinkc", newsNum, 600);

			if(regExTest('langpage', location.pathname))
			{
				nxtNews = newsNum+1;
				bulletCtimer = setTimeout("homeBulletsC("+nxtNews+")",8000);
			}
		}
	}
}

function homeBulletsD(newsNum){

	if(document.getElementById("homebulletscontd"))
	{
		clearTimeout(bulletDtimer);
		hpNews = document.getElementById("homebulletscontd").getElementsByTagName("div").length;

		if(hpNews>1)
		{
			if(newsNum >= hpNews){newsNum=0;}
			fadecontentviewer.init("homebulletscontd", "homebullets", "homebulletslinkd", newsNum, 600);

			if(regExTest('langpage', location.pathname))
			{
				nxtNews = newsNum+1;
				bulletDtimer = setTimeout("homeBulletsD("+nxtNews+")",8000);
			}
		}
	}
}



function startChildren()
{
	if(document.getElementById("startchildren"))
	{
		childDivs = document.getElementById("childrencontent").getElementsByTagName("div");
		tcDiv = childDivs.length-1;

		fstHeight = childDivs[0].offsetHeight;
		fstMargin = fstHeight-(fstHeight*2);
		
		pheight=fstMargin;
		for(i=0;i<childDivs.length;i++)
		{
			childDiv = childDivs[i];
			divClass = childDiv.getAttribute("class");

			if(divClass == "childpage")
			{
				thisHeight = childDiv.offsetHeight;
				childDivs.item(i).style.minHeight=thisHeight+"px";
				//childDivs.item(i).style.top="-"+pheight+"px";
				pheight=pheight+thisHeight;
			}
		}
		
		document.getElementById("childrencontent").style.minHeight = fstHeight+"px";
		//childDivs[0].style.marginBottom = fstMargin+"px";

		fadecontentviewer.init("childrencontent", "childpage", "childnav", 0, 300);
	}
}


function buildXt(){

	//expanding lists / highlight q&a
	ulTags = document.getElementsByTagName("ul");
	for(h=0;h<ulTags.length;h++)
	{
		ulTag = ulTags[h];
		ulClass = ulTag.getAttribute("class");
		if(ulClass == null){ulClass = ulTag.getAttribute("className");}
		
		if(ulClass == "expandlist" || ulClass == "expandlistred")
		{
			nTempId = "expandListTemp"+h;
			ulTag.setAttribute("id",nTempId);
			ulChild = ulTag.getElementsByTagName("li");

			ulChild[0].onclick = function(e)
			{
				target = e?e.target:window.event?window.event.srcElement:null;
				if(target) setExpandHide("objshow",target.parentNode.getAttribute("id"));
				target.setAttribute("class","openlist");
			}
			
			hTitle = ulChild[0].innerHTML;
			hTitle = 'View information on '+hTitle+' - click here';
			ulChild[0].setAttribute("title",hTitle);
		}
		
		if(ulClass == "qnahighlight")
		{
			qnahightID = "qnahightlightid";
			ulTag.setAttribute("id",qnahightID);

			setQNAhighlight();
		}
	}
	//end expand
	
	if(document.getElementById("hidechildcontent"))
	{
		childDivs = document.getElementById("rightcontent").getElementsByTagName("div");
		
		for(c=1;c<childDivs.length;c++)
		{
			childDiv = childDivs[c];
			
			childId = childDiv.getAttribute("id");
			childClass = childDiv.getAttribute("class");
			if(childClass==null){childClass = childDiv.getAttribute("className");}
			
			if(childClass == 'childcontent' && childId != "parentcontent")
			{
				hLink = childDiv.getElementsByTagName("h1")[0];
				chLink = childDiv.getElementsByTagName("div")[0].getElementsByTagName("h1")[0];
				
				getHeaderTxt = childDivs.item(c).getElementsByTagName("div")[0].getElementsByTagName("h1")[0].innerHTML;
				hLink.innerHTML = getHeaderTxt;
				
				hLink.onclick = function(e)
				{
					target = e?e.target:window.event?window.event.srcElement:null;
					if(target){
						siblDiv = target.parentNode.getElementsByTagName("div")[0];
						target.style.display= 'none';siblDiv.style.display = 'block';
					}
				}
				
				chLink.onclick = function(e)
				{
					target = e?e.target:window.event?window.event.srcElement:null;
					if(target){
						thisParent = target.parentNode;
						siblDiv = thisParent.parentNode.getElementsByTagName("h1")[0];
						siblDiv.style.display= 'block';target.parentNode.style.display= 'none';
					}
				}
			}
		}
	}
}

function setQNAhighlight(){

	qlists = document.getElementById("qnahightlightid").getElementsByTagName("li");
	
	for(i=0;i<qlists.length;i++)
	{
		qlist = qlists[i];
		
		qName = qlist.getElementsByTagName("a")[0].getAttribute("href");
		qName = qName.substr(1);
		
		qlist.getElementsByTagName("a")[0].setAttribute("href","javascript:qnaHighlight('"+qName+"')");
	}
}

function qnaHighlight(qTag){

	tQuestions = document.getElementsByTagName("h4");
	
	for(i=0;i<tQuestions.length;i++)
	{
		tQuestion = tQuestions[i];
		
		if(qName = tQuestion.getElementsByTagName("a")[0].getAttribute("name"))
		{
			tQuestion.style.color = '#000000';

			goQtag = "#"+qTag;

			if(qName == qTag)
			{
				tQuestions.item(i).style.color = '#DF3733';
			}

			top.location = goQtag;
		}
	}
}


function setExpandHide(objType,id){

	fObj = document.getElementById(id);
	fObjs = fObj.getElementsByTagName("li");
	
	if(objType == "objhide")
	{
		showHide = "none";
		
		fObjs[0].onclick = function(e)
		{
			target = e?e.target:window.event?window.event.srcElement:null;
			if(target) setExpandHide("objshow",id);
			fObjs[0].setAttribute("class","openlist");
		}
		
		hTitle = fObjs[0].innerHTML;
		hTitle = 'View information on '+hTitle+' - click here';

	}
	else if(objType == "objshow")
	{
		showHide = "list-item";
		
		fObjs[0].onclick = function(e)
		{
			target = e?e.target:window.event?window.event.srcElement:null;
			if(target) setExpandHide("objhide",id);
			fObjs[0].setAttribute("class","");
		}
		
		hTitle = fObjs[0].innerHTML;
		hTitle = 'Hide information on '+hTitle+' - click here';
	}
	
	for(t=0;t<fObjs.length;t++)
	{
		fObjs[t].style.display = showHide;
	}
	
	fObjs[0].style.display = "list-item";
	fObjs[0].setAttribute("title",hTitle);
}


function elementHide(cElement){

	elemArr = cElement.split(',');
	
	styleHTML='';
	for(i=0;i<elemArr.length;i++)
	{
		if(elemArr[i].substr(0,1)=="." || elemArr[i].substr(0,1)=="#")
		{
			styleHTML += elemArr[i]+"{display:none;}\n";
		}
	}
	
	var jxstyle = document.getElementsByTagName("head")[0];
	var xlk = document.createElement("style");
	var fstyles = document.createTextNode(styleHTML);
	xlk.setAttribute("type", "text/css");

	if(xlk.styleSheet){xlk.styleSheet.cssText = fstyles.nodeValue;}
	else{ xlk.appendChild(fstyles);}
	jxstyle.appendChild(xlk);
}


function printContent(){

myWindow = window.open('printPage.mfp','_blank');
myWindow.focus();

}


function checkWidePrint(){

	if(opener.document.getElementById("rightcontent"))
	{
		rDiv = opener.document.getElementById("rightcontent");
		rClass = rDiv.getAttribute("class");
		
		if(rClass == "wide")
		{
			document.getElementById("previewcontent").setAttribute("class","wide");
		}
	}
}


function removeLink(linkDet){

	links = document.getElementsByTagName("a");

	for(i=0;i<links.length;i++)
	{
		link = links[i];
		linkHref = link.getAttribute("href");

		if(linkHref == linkDet)
		{
			links.item(i).innerHTML = '';
			links.item(i).setAttribute("href","#");
		}
	}
}


function mail(){

	if(curLocation.search(/insoll/i) >= 0)
	{
		top.location = 'mailto:sales@insoll.com';
	}
	else
	{
		top.location = 'mailto:sales@fibracon.com';
	}
}

function imail(){

	if(curLocation.search(/insoll/i) >= 0)
	{
		top.location = 'mailto:sales@fibracon.com';
	}
	else
	{
		top.location = 'mailto:sales@insoll.com';
	}
}

function loginLinks(){
	
	if(document.getElementById("logoutlink"))
	{
		document.getElementById("logoutlink").href = 'javascript:loginJS()';
	}
}

/** creates an inline popup **/
function loginJS(){

	if(!document.getElementById("popinfo"))
	{
		var parentBody = document.getElementsByTagName("body")[0];
		var popdiv = document.createElement("div");
		var popinner = document.createElement("div");
		var popclose = document.createElement("a");
		parentBody.appendChild(popdiv);
		popdiv.appendChild(popclose);
		popdiv.appendChild(popinner);
		popdiv.setAttribute("id", "popinfo");
		popinner.setAttribute("id", "popcontent");
		popclose.setAttribute("id", "popclose");
		popclose.setAttribute("title", "Close pop-up info box - click here");
		popclose.setAttribute("href", "javascript:loginClose()");
	}
	
	if(bName == "Explorer")
	{
		//document.getElementById("popinfo").style.backgroundImage = "none";
	}
	
	document.getElementById("popinfo").style.display = "block";
	//valueCounter('popinfo',0,100,'opacity',200);
	
	document.getElementById("popcontent").innerHTML= '<iframe name="login" id="loginframe" src="/LoginJs.mfp" scrolling="yes" frameborder="0" width="100%" height="360"></iframe>';	

	if(bName == "Explorer")
	{
		//var RemFilTimer = setTimeout("document.getElementById('popinfo').style.filter = ''",300);
		//var AddBGTimer = setTimeout("document.getElementById('popinfo').style.background = 'transparent url(/gfx/info-pop.png) no-repeat center center'",400);
	}

}


function popInfoClose(){

	document.getElementById('rightcontent').style.display = 'none';
	//parent.document.getElementById('popcontent').innerHTML = '';
	parent.location.reload();
}

function loginClose(){

	document.getElementById('popinfo').style.display = 'none';
	parent.document.getElementById('popcontent').innerHTML = '';
}


function loadDrawings(){
	
var bgDrawingArr = new Array();		
bgDrawingArr[0] = '/gfx/drawing-1.png';
bgDrawingArr[1] = '/gfx/drawing-2.png';
bgDrawingArr[2] = '/gfx/drawing-3-1.png';
bgDrawingArr[3] = '/gfx/drawing-3-2.png';

	for(i=0;i<bgDrawingArr.length;i++)
	{
		$("div#bgDrawings").append('<img alt="Drawings" id="bgdrawing'+i+'" />');
	}
	
	$("div#bgDrawings").children('img').css('display','none');
	drawingsList = $("div#bgDrawings").children('img');

	$(drawingsList).each(function(index){

		$(this).attr("src",bgDrawingArr[index]);
		$(this).load(function(){
		
			$(this).css('display','');
		});
	});
}

function randomOrderArray(){return (Math.round(Math.random())-0.5); } 

function randomiseMarkets(){

	$("ul#strapblue").hide();
	markets = $("ul#strapblue").children("li");
	
	markets.sort(randomOrderArray);
	
	$(markets).each(function(index){
	
		$(this).clone().appendTo("ul#strapblueb");
	});
	
	$("ul#strapblueb").css('width','auto');
	$("ul#strapblueb").show();
	newMarkets = $("ul#strapblueb").children("li");
	
	marketWidth=0;
	marketWidthCheck=0;
	$(newMarkets).each(function(index){
	
		marketWidthCheck = marketWidthCheck+$(this).outerWidth(true);
		$(this).hide();

		if(marketWidthCheck<1000){
			$(this).show();
			marketWidth = marketWidth+$(this).outerWidth(true);
		}
	
	});
	
	marketWidthMargin = Math.floor((1000-marketWidth)/2);
	$("ul#strapblueb").css('margin-left',marketWidthMargin+'px');
	
}


function slideStrap()
{
	
	strapFadeI = setTimeout("$('#strapblue').fadeTo(500,0, function() {})",2000);
	//$("#strapblue").animate({"left": "-=490px"}, 100);
	strapSlide = setTimeout("$('#strapblue').animate({'left': '-=490px'}, 100)",2000);
	strapFadeO = setTimeout("$('#strapblue').fadeTo(500,100, function() {})",2500);
	
	strapFadeB = setTimeout("$('#strapblue').fadeTo(500,0, function() {})",6000);
	strapSlidC = setTimeout("$('#strapblue').animate({'left': '0px'}, 100)",6000);
	strapFadeD = setTimeout("$('#strapblue').fadeTo(500,100, function() {})",6500);
	
	newStrap = setTimeout("slideStrap()",10000);
}

function checkEmails(){

	if(location.hostname == 'insoll.peaknet.ltd.uk' || location.hostname == 'www.insoll.com'){
	
		if(location.pathname == '/contact-us'){
			
			aLinks = $('div#inlinechildren a');
			$(aLinks).each(function(index){
			
				thisHref = $(this).attr("href");
				if(thisHref.substr(0,7) == 'mailto:'){
					mailArr = thisHref.split("@");
					if(mailArr.length == 2 && mailArr[1] == 'fibracon.com'){
						newEmail = mailArr[0]+'@insoll.com';
						newEmailS = newEmail.replace(/mailto:/gi,"");
						$(this).attr("href",newEmail);
						$(this).html(newEmailS);
					}
				}
			});
		}	
	}
}


function setLanguageList(){

	//if(regExTest('langpage', location.pathname)){
	
		//curLanguage = location.pathname;
		//if(curLanguage == '/')curLanguage = 'en';
		//curLanguage = curLanguage.replace('/','');
	
		$("div#accesslinks").append(' . <div id="setLanguageDrop">Export Contacts<span></span></div>');
		//$("div#setLanguageDrop > span").append('<a href="#'+curLanguage+'" id="'+curLanguage+'Set"><img src="/gfx/lang/'+curLanguage+'.png" alt="'+curLanguage+'" /></a>');

		//$("a#"+curLanguage+"Set").click(function(e){e.preventDefault();});
		
		$(LanguageList).each(function(index){
		
			thisLang = LanguageList[index];
			if(thisLang != 'en'){
				xtMargin = '';
				//if(index == '1')xtMargin = ' style="margin-top:19px;"';
				thisLangLink = '/'+thisLang;
				$("div#setLanguageDrop > span").append('<a href="'+thisLangLink+'" id="'+thisLang+'LangSelect" title="Click for '+LanguageText[thisLang]+' help"'+xtMargin+'><img src="/gfx/lang/'+thisLang+'.png" alt="'+thisLang+'" /></a>');
			}
		});
		
		
		//$("div#setLanguageDrop").mouseenter(function(){
			
			langLinkList = $("div#setLanguageDrop").children('span').children('a');
			langListHeight = 17*langLinkList.length;
			//langListHeight = langListHeight+19;
			$("div#setLanguageDrop").children('span').css('height',parseInt(langListHeight)+'px');
		//});
		
		//$("div#setLanguageDrop").mouseleave(function(){
		
			//$(this).children('span').css('height','12px');
		//});
	//}
}

function loadPdfPreview(){

	previewLinks = $("a[rel=getpreview]");
	
	if(previewLinks.length>0){
	
		$(previewLinks).each(function(index){

			thisREV = $(this).attr("rev");
			if(thisREV != ''){

				var xmlhttp;
				if (window.XMLHttpRequest)
				{
					xmlhttp=new XMLHttpRequest();
				}
				else if (window.ActiveXObject)
				{
					xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				else
				{
					alert("Your browser does not support XMLHTTP!");
				}

				xmlhttp.onreadystatechange=function()
				{
					if(xmlhttp.readyState==4)
					{
						previewResponse = xmlhttp.responseText;

						if(previewResponse == 'GENERATE'){

							//alert("Generating preview jpg for: "+thisREV);
						}
					}
				}

				var whichPage = "/pdfpreview.php?img="+thisREV;
				xmlhttp.open("GET",whichPage,true);
				xmlhttp.send(null);
			}
		});
		
		checkPdfPreview();
	}
}

var pdfPreviewTimeout;
var pdfPreviewLeftPos = 0;
function checkPdfPreview(){

	$('body').append('<div id="pdfpreviewleftpos" style="display:none;"></div>');

	previewLinks = $("a[rel=getpreview]");
	
	$(previewLinks).each(function(index){

		linkPos = $(this).offset();

		linkWidth = $(this).outerWidth(true);

		if(linkWidth>pdfPreviewLeftPos)pdfPreviewLeftPos = linkWidth;

		$("div#pdfpreviewleftpos").attr("rel",pdfPreviewLeftPos);

		$(this).mouseover(function(){
			
			getPdfPreview($(this));
		});

		$(this).mouseout(function(){
			
			clearTimeout(pdfPreviewTimeout);
			$("div#pdfpreviewcont").remove();
		});
	});
}

function getPdfPreview(obj){

	thisREV = $(obj).attr("rev");
	
	if(thisREV != ''){

		$("div#page").append('<div id="pdfpreviewcont"><p id="pdfpreviewcontPara">Generating PDF Preview...</p></div>');
		linkPos = $(obj).offset();

		linkWidth = $("div#pdfpreviewleftpos").attr("rel");
		linkWidth = Math.floor(parseInt(linkWidth)+10);

		$("div#pdfpreviewcont").css({'top':(linkPos.top-50)+'px',
					     'left':linkWidth+'px'});

		var xmlhttp;
		if (window.XMLHttpRequest)
		{
			xmlhttp=new XMLHttpRequest();
		}
		else if (window.ActiveXObject)
		{
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		else
		{
			alert("Your browser does not support XMLHTTP!");
		}

		xmlhttp.onreadystatechange=function()
		{
			if(xmlhttp.readyState==4)
			{
				imgSrc = xmlhttp.responseText;
				if(imgSrc == 'ERROR'){

					$("p#pdfpreviewcontPara").html("No Preview Available.");

				}else if(imgSrc == 'GENERATE'){

					var pdfPreviewTimeout = setTimeout(function(){getPdfPreview($(obj))},20000);
					
					$(obj).mouseout(function(){

						clearTimeout(pdfPreviewTimeout);
						$("div#pdfpreviewcont").remove();
					});

				}else if(imgSrc != ''){

					showPdfPreview(imgSrc);
				}
			}
		}

		var whichPage = "/pdfpreview.php?img="+thisREV;
		xmlhttp.open("GET",whichPage,true);
		xmlhttp.send(null);
	}
}


function showPdfPreview(imgSrc){

	
	previewimg = new Image();
	previewimg.onload = function(){
		
		thisWidth = imgSrc.width;
		thisHeight = imgSrc.height;
		$("div#pdfpreviewcont").html('<div><img src="'+imgSrc+'" alt="'+imgSrc+'" /></div>');
		$("div#pdfpreviewcont").children('div').fadeTo("fast","1");
	}
	previewimg.src = imgSrc;
}

/** Provided by Google **/
function recordEventLinks(link, category, action) {
  try{
    var pageTracker = _gat._getTracker("UA-2043955-1");
    pageTracker._trackEvent(category, action);
    setTimeout('document.location = "' + link.href + '"', 100);
  } catch(err) {}
}


/** http://www.quirksmode.org/js/detect.html           **/
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

var bName = BrowserDetect.browser;
var bVer = BrowserDetect.version;


function startFunctions(){

	setHeight();
	randomiseMarkets();
	rotateNews(0);
	rotateLatest(0);
	homeBullets(0);
	flashHome(0,0);
	buildXt();
	elementHide('.expandlist li,.expandlistred li');
	startChildren();
	loadDrawings();
	//setContactForm();
	loginLinks();
	checkEmails();
	loadPdfPreview();
	//setLanguageList();
	
	if(location.pathname == '/')$("div#help").css('float','right');

	if(location.pathname == '/contact.mfp')setAttachmentLinks();	
}


