// true if IE
var IE = /*@cc_on!@*/false;

//Firefox version
moz = navigator.userAgent.substring(0, 7);
		mozVersion = navigator.userAgent.substr(navigator.userAgent.length-5, 5);
		mozVersion = mozVersion.substr(0,3);
		var u=navigator.userAgent.toLowerCase();
		var ff3=u.indexOf("firefox/3")>-1;
		var firefox31=u.indexOf("firefox/3.0.1")>-1;
		
		if (ff3) {
			if (firefox31){
				oldMoz = 1;
			} else {
				oldMoz = 0;
			}
		} else {
			oldMoz = 1;
		}
		//if (moz == 'Mozilla' && (mozVersion == '3.0' || mozVersion.substring(0,1) == '1' || mozVersion.substring(0,1) == '2')){oldMoz = 1}else{oldMoz=0}
		
//detect flash
var flashversion = 0;
if (navigator.plugins && navigator.mimeTypes.length) {
	var x = navigator.plugins["Shockwave Flash"];
	if(x && x.description) {
		var y = x.description;
		flashversion = parseInt(y.substr(y.indexOf(".") - 2, 2), 10);
	}
} else {
	result = false;
	for(var i = 30; i >= 3 && result != true; i--){
		execScript('on error resume next: result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript');
		flashversion = i;
	}
}

if (flashversion >= 8) {
	    document.getElementsByTagName('html')[0].className = 'flashInstalled';
}
		document.getElementsByTagName('html')[0].className += ' json';


var t; //thumbnails
var h=0; 
var n=1; //gallery
var m = 0;  //header images

var citrusCMS = {
		
	load : function() {
		citrusCMS.openWindow();
		citrusCMS.printWindow();
		citrusCMS.formStyle();
		citrusCMS.addCompanyType();
		citrusCMS.addSector();
		citrusCMS.sizeChanger();
		citrusCMS.HeaderGallery();
		citrusCMS.flashRewrite('header>a','/_img/layup/navi.swf', '', '1');
		citrusCMS.flashRewrite('footer>h3','/_img/layup/title3.swf', '', '1');
		if ($('homenews')) {
			citrusCMS.flashRewrite('homenews>h2','/_img/layup/title2.swf', '', '1');
			citrusCMS.flashRewrite('homenews>a','/_img/layup/title4.swf', '', '1');	
		}
		if($('middle')) {citrusCMS.flashRewrite('middle>h1','/_img/layup/title.swf', '', '1')};
		if($('leftside')) {citrusCMS.flashRewrite('leftside>a','/_img/layup/navi2.swf', '', '1')};
		if($('categories')) {citrusCMS.flashRewrite('categories>h2','/_img/layup/title2.swf', '', '1')};
		if ($('imgcaption').innerHTML != '') {citrusCMS.flashRewrite('mainimg>h2','/_img/layup/caption.swf', '', '1');}
		if ($('categories')) {citrusCMS.categoryLinks();}
		//if($('categories')) {citrusCMS.flashRewrite('prod1','/_img/layup/prodimage.swf', 'img=jpg_1276252344.jpg&link=http://www.google.com', '0')};
		//if($('categories')) {citrusCMS.flashRewrite('prod2','/_img/layup/prodimage.swf', 'img=jpg_1276252344.jpg&link=http://www.google.com', '0')};
		//if($('categories')) {citrusCMS.flashRewrite('prod3','/_img/layup/prodimage.swf', 'img=jpg_1276252344.jpg&link=http://www.google.com', '0')};
		if ($('controls')) {citrusCMS.galleryControls();}		

	},
	
		openWindow : function(){
		
		allNodes = $A(document.getElementsByClassName("openWindow")); 
		allNodes.each(function(node, i) {
		allNodes[i].onclick = function() {window.open(this.href); pageTracker._trackPageview('/outbound/'+this.href.replace('http://',''));  return false};
		});
	},
	
	
	
	addCompanyType : function() {
		if ($('company_type')) {
				$('company_type').onchange = function() { 
						if ($('company_type').value=='99') {
							$('showNewCompany').style.display='block';
							
						} else {
							$('showNewCompany').style.display='none';
							
						}
				}
		}
	},
	
	
	addSector : function() {
		if ($('sector')) {
				$('sector').onchange = function() { 
						if ($('sector').value=='99') {
							$('showNewSector').style.display='block';
							
						} else {
							$('showNewSector').style.display='none';
							
						}
				}
		}
	},	
	
	
	printWindow : function(){
		
		allNodes = $A(document.getElementsByClassName("printWindow")); 
		allNodes.each(function(node, i) {
		allNodes[i].onclick = function() {window.print()};
		});

	},
	
	formStyle : function(){
		
		allNodes = $A(document.getElementsByClassName("textform")); 
		allNodes.each(function(node, i) {
			
			Event.observe(allNodes[i], 'focus', 
				function(e){ 
					if(Event.element(e).nodeName != 'SELECT'){
						Event.element(e).className="textformfocus";
						if (Event.element(e).value.charAt(0) == ' ' || (Event.element(e).value.charAt(0) == '-' && Event.element(e).value.charAt(Event.element(e).value.length-1) == '-')) { Event.element(e).value='' }
					}
					}
				);

			Event.observe(allNodes[i], 'blur', 
				function(e){ 
					Event.element(e).className="textform";
					}
				);
		});
	},
	

	
	flashRewrite : function (x, movie, query, type, width, height) {
	
		if (flashversion >= 8){
				
			if (type == '1'){ //tag name
				xArea = x.split('>'); //if TagName in a id
	
				if (xArea[1]){var x = $(xArea[0]).getElementsByTagName(xArea[1]);} else {var x = document.getElementsByTagName(x);}
					
				for (var i=0;i<x.length;i++){
								
					width = Element.getDimensions($(x[i])).width;
					height = Element.getDimensions($(x[i])).height;
                    color = $(x[i]).getStyle('color')
					title = x[i].innerHTML;
					
					if (title) {title = title.replace("&", "%26")}
					if (!query){q= "title="+ title + "&color="+ color;} else {q= query +"&title="+ title + "&color="+ color;}	
										
						// check for flash in 'a' tag
						if(x[i].nodeName == 'A') {
							
							q+= "&link="+ x[i].href.replace("&", "%26");
							if (x[i].className == "flash" || x[i].className == "flash on" || x[i].className == "flash openWindow on" || x[i].className == "flash openWindow") {
																
								if (x[i].className == "flash on" ){ q+= "&s=1" }
								if (x[i].className == "flash openWindow on" ){ q+= "&s=1&o=1" }
								if (x[i].className == "flash openWindow" ){ q+= "&o=1" }
								citrusCMS.getFlash(x[i], movie, q, width, height)
							
							}
							
						// not a	
						}else{
							citrusCMS.getFlash(x[i], movie, q, width, height)
						}
						q = '';
					
				}
				
			} else { //id
					
				if (!width){width = Element.getDimensions($(x)).width;}
				if (!height){height = Element.getDimensions($(x)).height;}
				
				citrusCMS.getFlash($(x), movie, query, width, height)

			}
			
		}
		
	},
	
	
	getFlash : function(what, movie, query, width, height) {

		new_txt = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+width+'" height="'+height+'">\n';
		new_txt += '<param name="movie" value="'+movie+'">\n';
		new_txt += '<param name="quality" value="high" />\n';
		new_txt += '<param name="menu" value="false">\n';
		new_txt += '<param name="wmode" value="transparent">\n';
		new_txt += '<param name="flashvars" value="'+query+'">\n';
		new_txt += '<param name="scale" value="noscale" />\n';
		new_txt += '<param name="salign" value="lt" />\n';
		new_txt += '<embed src="'+movie+'" flashvars="'+query+'" width="'+width+'" height="'+height+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" menu="false" scale="noscale" salign="lt" wmode="transparent"></embed>\n';
		new_txt += '</object>';
		what.innerHTML = new_txt;
		what.style.visibility= 'visible';
	
	},
	
	
	linksShow : function() { //product image rotator
			allNodes = $A($("thumbnails").getElementsByTagName('img'));	
			allthumbs.each(function(node, j){if (allthumbs[j].parentNode.className=='on'){currentNode = j;}});
				if (typeof currentNode!='undefined'){if (h != currentNode) {h=currentNode + 1;}}
				if (h==allNodes.length){h=0;}
				if (allNodes.length > 1){
					getimage  = allNodes[h].parentNode.href.split('/');
					citrusCMS.flashRewrite('mainimg','/_img/layup/head.swf', 'images=' +getimage[getimage.length-1].replace('t_','') + '&title=' + allNodes[h].parentNode.title, '0'); 
					allthumbs.each(function(node, j){Element.removeClassName(allthumbs[j].parentNode, 'on');});
					allNodes[h].parentNode.className='on';
					h=h+1;
					t=setTimeout("citrusCMS.linksShow('0,"+h+"')",6000)
				}
		
	},
	
	
	greyscale : function(imgObj){
		
		if (!IE && oldMoz!=1){
			
		var canvas = document.createElement('canvas');
		var canvasContext = canvas.getContext('2d');
		
		var imgW = imgObj.width;
		var imgH = imgObj.height;
		canvas.width = imgW;
		canvas.height = imgH;
		canvasContext.drawImage(imgObj, 0, 0);

		
		var imgPixels = canvasContext.getImageData(0, 0, imgW, imgH);
		
		for(var y = 0; y < imgPixels.height; y++){
			 for(var x = 0; x < imgPixels.width; x++){
				  var i = (y * 4) * imgPixels.width + x * 4;
				  var avg = (imgPixels.data[i] + imgPixels.data[i + 1] + imgPixels.data[i + 2]) / 3;
				  imgPixels.data[i] = avg;
				  imgPixels.data[i + 1] = avg;
				  imgPixels.data[i + 2] = avg;
			 }
		}

		canvasContext.putImageData(imgPixels, 0, 0, 0, 0, imgPixels.width, imgPixels.height);
		
		return canvas.toDataURL();
		}

	},
	
	sizeChanger : function() {
		//load cookie for css switcher
	var cookie = readCookie("style");
	var title = cookie ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);
		
		//show correct size on navi
		if (cookie){
		cookiestr = cookie.toString();
			if ($(cookiestr)){
			if ($(cookiestr).childNodes[0].nodeName == 'A') {$(cookiestr).childNodes[0].className="on";}
			}else{
			$('Default').childNodes[0].className="on";
			}
		}else{
			$('Default').childNodes[0].className="on";
		}
		
		//textchange navi
		topnaviRoot = $("textchange");
			
			for (i=0; i<topnaviRoot.childNodes.length; i++) {
				node = topnaviRoot.childNodes[i];
				
					if (node.nodeName=="LI") {
					node.onclick=function() {
						
						if (this.id !='') {
							for (j=0; j<topnaviRoot.childNodes.length; j++) {
							if (topnaviRoot.childNodes[j].childNodes[0]) {
								if (topnaviRoot.childNodes[j].childNodes[0].nodeName == 'A') {topnaviRoot.childNodes[j].childNodes[0].className="";}
							}
							}
							this.childNodes[0].className="on";
								setActiveStyleSheet(this.id); return false;
						}
					}
				}
			}

	},
	
	
	galleryControls : function() {
		if (('controls')) {
			allNodes = $A($('showcarousel').childNodes); 
			allNodes.each(function(node, i) {
			allNodes[i].onclick = function() {					
					
					$('gallerymainimg').src = this.childNodes[0].href.replace('s_','d_');
					$('gallerylightbox').href = this.childNodes[0].href.replace('s_','z_');
					$('gallerylightbox').title = this.childNodes[0].childNodes[0].alt;
	
			if (this.childNodes[0].rel == 'exist'){					// set up the hi res link
					hires1 = this.childNodes[0].href.split('/');							
					$('hiresspan').innerHTML = '<a href="/content/download.asp?file=h_'+hires1[6].replace('d_','')+'&force=true&folderName=_img\\pics\\gallery\\" id="hires" class="openWindow">Download hi-res image</a>'					
					} else {
					$('hiresspan').innerHTML = ''					
					}
				return false;
				}
			});
			
				currentLocation = window.location.href.split('/');
				var gallery = '';
				if (currentLocation.length>=6) {gallery = currentLocation[5].replace('#text','');}
			
			if ($('carouselright')){
			$('carouselright').onclick = function() {
					citrusAjax.carouselRequest('/content/gallerycontrols.asp?ajax=1&g='+gallery+'&s='+n,'controls','r'); 
				
				}
			}
			
			if ($('carouselleft')){
			$('carouselleft').onclick = function() {
					citrusAjax.carouselRequest('/content/gallerycontrols.asp?ajax=1&g='+gallery+'&s='+n,'controls','l'); 
				}
			}
		}
	},
	
	categoryLinks : function() {
		allNodes = $A(document.getElementsByClassName('cat')); 
		allNodes.each(function(node, i) {
		allNodes[i].onclick = function() {
			window.location = this.getElementsByTagName('a')[0].href;
			}
		});
		
		
	},
	
	HeaderGallery : function() {
		
	images = $A(document.getElementsByClassName('fadeimg')); 
	if ($('thumbnails')){
		allthumbs = $A($('thumbnails').getElementsByTagName('img'));	
		allNodes = $A($('thumbnails').getElementsByTagName('img'));	
		}

	if (images.length > 1){
		
		if ($('thumbnails')){
			saveImage = new Array();
							
			allNodes.each(function(node, i) {
				if (allNodes[i].nodeName=='span'){getnode = allNodes[i].nextSibling} else {getnode = allNodes[i];}
				saveImage[i] = getnode.src;
				if (!IE && oldMoz!=1) {if (i != 0) {getnode.src = citrusCMS.greyscale(getnode);}}
								   
			getnode.onmouseover = function() {
				this.src = saveImage[i];
				}
				
			getnode.onmouseout = function() {
				if (!IE && this.parentNode.className=='' && oldMoz!=1) { this.src = citrusCMS.greyscale(this);}
				}	
								
			allNodes[i].onclick = function() {
				x = m;
				m = i;
			
				allthumbs.each(function(node, j){
				if (!IE && oldMoz!=1) {allthumbs[j].src = citrusCMS.greyscale(allthumbs[j]); }
					Element.removeClassName(allthumbs[j].parentNode, 'on');
				});
				this.parentNode.className='on';
				
					$(images[i]).appear({ duration: 1.0 }); 
					if ($(images[i]).childNodes.length==2){
						new Effect.Fade(('imgcaption'), {from: 1, to: 0, duration: 0.75, afterFinish: (function(){$('imgcaption').innerHTML = $(images[i]).childNodes[1].innerHTML; $('imgcaption').appear({ duration:1.0 }); citrusCMS.flashRewrite('mainimg>h2','/_img/layup/caption.swf', '', '1');}) });
					} else {
							$('imgcaption').fade({duration: 2.0});
							$('imgcaption').innerHTML = '';
					}
					
					$(images[x]).fade({duration: 1.0}); 
		
				clearInterval(play);
				citrusCMS.HeaderGallery();
				return false;
				
					}
			});	
		}
								
	play = setInterval(	 
		
				function() {
					y = m + 1;
					if (y==images.length){y=0;}
					
					$(images[y]).appear({ duration: 1.0 }); 
					
					if ($(images[y]).childNodes.length==2){
						
						new Effect.Fade(('imgcaption'), {from: 1, to: 0, duration: 0.75, afterFinish: (function(){$('imgcaption').innerHTML = $(images[y]).childNodes[1].innerHTML; $('imgcaption').appear({ duration:1.0 }); citrusCMS.flashRewrite('mainimg>h2','/_img/layup/caption.swf', '', '1');}) });
						
					} else {
							$('imgcaption').fade({duration: 2.0});
							$('imgcaption').innerHTML = '';
					}
					
					if ($('thumbnails')){ 
						allthumbs.each(function(node, j){
							if (!IE && oldMoz!=1) {allthumbs[j].src = citrusCMS.greyscale(allthumbs[j]); }
								Element.removeClassName(allthumbs[j].parentNode, 'on');
							});
						allthumbs[y].parentNode.className = 'on'; 
					}
					
					$(images[m]).fade({duration: 1.0}); 
				
					m++;
					if (m==images.length){m=0;}
					
				
				},4400);

			}	
	}
}


var f; //feature products
var p; //featured projects
var c=1; //featured products
var d=1; //featured projects

var citrusWeb = {
	
	showFAQ : function() {
		
		allNodes = $A(document.getElementsByClassName("faqQuestion"));
		allNodes.each(function(node, i) {

			allNodes[i].onclick = function() {
				
				allAnswers = $A(document.getElementsByClassName("faqAnswer"))
				allAnswers.each(function(node, i) {node.hide(); node.parentNode.className = ''});

				iID = this.href.split('#'); $(iID[1]).style.display = 'block';
				
				this.parentNode.className = 'on'
			
				};

		});
	},
	
	showTabs : function() {
		if ($('tabs')) { 
		allNodes = $A($("tabs").childNodes)
			
			allNodes.each(function(node, i) {
				if (node.nodeName=="LI") {
					node.onclick = function() {
						
						onNodes = $('middle').select('.tabon'); 
						onNodes.each(function(node, j) {
							node.className='taboff';
						});
						
						onNodes = $('tabs').select('.on'); 
						onNodes.each(function(node, j) {
							node.className='';
						});
					
					Element.addClassName(this.childNodes[0], "on"); 
					$(this.childNodes[0].id.replace('tab','pinfo')).className = 'tabon'; 	
					return false;
					};
				}
			
			});	
		}
	},
	
	colourBars : function() {
	if ($('dataGrid')) {
		var even = false;
		var thearea = $('dataGrid');
		allA = $A(document.getElementsByClassName("folderLink"));
		allNodes = $A(thearea.getElementsByTagName('tr'));
		
		
		allA.each(function(node, i) {

			allA[i].onclick = function() {
				
				allAnswers = $A(document.getElementsByClassName("folderlist"))
				allAnswers.each(function(node, i) {node.className ='folderlist'; node.parentNode.childNodes[0].childNodes[0].className = '';});
				iID = this.href.split('#'); $(iID[1]).className += ' table';
				this.className = 'on'
			
				};

		});
		
		
		allNodes.each(function(node, i) {
			if (!even) {node.className += 'highlight';}	
			allNodes[i].onmouseover = function() {node.addClassName('over');};
			allNodes[i].onmouseout = function() {node.removeClassName('over');};
			
			
			if (node.childNodes[0].nodeName == 'TD'){ 
				allNodes[i].onclick = function() {window.open(node.childNodes[0].childNodes[0]); return false;};
			}
			
			
			even =  ! even;
		});
	}
	},
	
	showFeaturedProducts : function() {
		if ($('fpcontrols')) {	
			allNodesi = $A($('fpcontrols').childNodes);
				allNodesi.each(function(node, j){if (allNodesi[j].childNodes.className=='on'){currentNode = j;}});
				if (typeof currentNode!='undefined'){if (c != currentNode) {c=currentNode + 1;}}
				if (c==allNodesi.length){c=1;}
				if (c==4){c=1;}
			
				citrusAjax.featureRequest('/content/featurecontrols.asp?ajax=1&fp='+c,'featuredproducts'); 
				
			c=c+1;
			f=setTimeout("citrusWeb.showFeaturedProducts('0,"+c+"')",6000)
		}	
	},
		
		showFeaturedProjects : function() {
		if ($('fjcontrols')) {	
			allNodesi = $A($('fjcontrols').childNodes);
				allNodesi.each(function(node, j){if (allNodesi[j].childNodes.className=='on'){currentNode = j;}});
				if (typeof currentNode!='undefined'){if (d != currentNode) {d=currentNode + 1;}}
				if (d==allNodesi.length){d=1;}
				if (d==4){d=1;}
			
				citrusAjax.featureRequest2('/content/featurecontrols.asp?ajax=1&fj='+d,'featuredprojects'); 
				
			d=d+1;
			p=setTimeout("citrusWeb.showFeaturedProjects('0,"+d+"')",6000)
		}	
		
		
	},
	
		showSingleProductFeatured : function() {
		if ($('featuredproducts')) {	
			if (!IE) {
				var fpimage = citrusCMS.greyscale($('fpimage'));
				if (fpimage!=='' && typeof fpimage != 'undefined') {$('fpimage').src = fpimage;}
				}
				
				citrusCMS.flashRewrite('featuredproducts>h2','/_img/layup/title2.swf', '', '1');
				citrusCMS.flashRewrite('featuredproducts>a','/_img/layup/title4.swf', '', '1');
		}
	},
	
		showSingleProjectFeatured : function() {
		if ($('featuredprojects')) {	
			if (!IE) {
				var fjimage = citrusCMS.greyscale($('fjimage'));
				if (fjimage!=='' && typeof fjimage != 'undefined') {$('fjimage').src = fjimage;}
				}
				
				citrusCMS.flashRewrite('featuredprojects>h2','/_img/layup/title2.swf', '', '1');
				citrusCMS.flashRewrite('featuredprojects>a','/_img/layup/title4.swf', '', '1');
		}
	},
	
	featureControls : function() {
		if ($('fpcontrols')) {	
		allNodes = $A($('fpcontrols').childNodes); 
		allNodes.each(function(node, i) {
		allNodes[i].onclick = function() {
		if (this.childNodes[0].nodeName=='A'){
			//	thislink = this.childNodes[0].href.split('=');
			//		c = thislink[1];
			//		citrusAjax.featureRequest('/content/featurecontrols.asp?ajax=1&fp='+c,'featuredproducts'); 
				}
				return false;
				};
		 });
	 } 
	 
	 if ($('fjcontrols')) {	
		allNodes = $A($('fjcontrols').childNodes); 
		allNodes.each(function(node, i) {
		allNodes[i].onclick = function() {
		if (this.childNodes[0].nodeName=='A'){
				//thislink = this.childNodes[0].href.split('=');
				//	c = thislink[1];
				//	citrusAjax.featureRequest('/content/featurecontrols.asp?ajax=1&fj='+d,'featuredprojects'); 
				}
				return false;
				};
		 });
	 }
	 
	}
	

	
}

var citrusAjax = {
	
	makeRequest : function(url,getID) { 
	
		var myAjax = new Ajax.Request(
		url,
		{
			method: 'get', 
			onComplete: function(originalRequest){$(getID).innerHTML = originalRequest.responseText;}
		});
			
	},
	
	featureRequest : function(url,getID) { 
	
		var myAjax = new Ajax.Request(
		url,
		{
			method: 'get', 
			onComplete: function(originalRequest){$(getID).innerHTML = originalRequest.responseText;
				if($('featuredproducts')) {citrusCMS.flashRewrite('featuredproducts>h2','/_img/layup/title2.swf', '', '1')};
				if($("featuredproducts")) {citrusCMS.flashRewrite('featuredproducts>a','/_img/layup/title4.swf', '', '1')};
				if (!IE) {
					var fpimage = citrusCMS.greyscale($('fpimage').getElementsByTagName('img'));
					if (fpimage!=='' && typeof fpimage != 'undefined') {$('fpimage').src = fpimage;}
					}			
				citrusWeb.featureControls();
			}
		});
			
	},
	
	featureRequest2 : function(url,getID) { 
	
		var myAjax = new Ajax.Request(
		url,
		{
			method: 'get', 
			onComplete: function(originalRequest){$(getID).innerHTML = originalRequest.responseText;
				if($('featuredprojects')) {citrusCMS.flashRewrite('featuredprojects>h2','/_img/layup/title2.swf', '', '1')};
				if($("featuredprojects")) {citrusCMS.flashRewrite('featuredprojects>a','/_img/layup/title4.swf', '', '1')};
				if (!IE) {
					var fjimage = citrusCMS.greyscale($('fjimage').getElementsByTagName('img'));
					if (fjimage!=='' && typeof fjimage != 'undefined') {$('fjimage').src = fjimage;}
					}				
				citrusWeb.featureControls();
			}
		});
			
	},
	
	carouselRequest : function(url,getID,dir) { 
	
		var myAjax = new Ajax.Request(
		url,
		{
			method: 'get', 
			onComplete: function(originalRequest){
					
				//new Effect.Move($('showcarousel'), { x: -675, y: 0, mode: 'relative', afterFinish: (function() {
				new Effect.Opacity($('showcarousel'), { from: 1.0,to: 0,duration: 1});																
									
				$(getID).innerHTML = originalRequest.responseText;
				new Effect.Opacity($('showcarousel'), {
									from: 0,
									to: 1.0,
									duration: 1,
									afterFinish: (function () {
											
										if (dir=='r'){
												n=n+1;
												
												if ($('gallerysets')){
													if (parseInt(n,10) >= parseInt($('gallerysets').innerHTML, 10)){
														setTimeout(function(){n=0;},0)}
												}
												
										} else {
											n=n-1;
											if (n < 0){
												setTimeout(function(){
														if ($('gallerysets')){
															n = parseInt($('gallerysets').innerHTML, 10) -1;
														} else {
															n=0;
														}
													},0)
											}
									}
							
								
						 })
				});
								//	})
								//});
				
				citrusCMS.galleryControls();
				
					
				
			}
		});
			
	},
	
	submitForm : function(pageUrl) {
		
		
		$('waiting').innerHTML = '<img src="/_img/layup/loading.gif" />'
		$('submitButton').type == 'button'; //if js then remove the submit function of the button
		$('submitButton').disabled = 'disabled'; //when submited disable button
		
		waitPadd = (Element.getDimensions($('cmsForm')).height - 45) /2
		$('waiting').style.paddingTop =  waitPadd + "px"
		$('waiting').style.paddingBottom =  waitPadd + "px"
		Element.show('waiting'); //show waiting div
		
		//stops whole site appearing when ajax is called
		if(pageUrl) {pageLocation = pageUrl} else {pageLocation = window.location}
		
		var myAjax = new Ajax.Request(
		pageLocation,
		{
			method: 'post', 
			parameters: 'ajax=1&' + Form.serialize("cmsForm"),
			onComplete: citrusAjax.showResponse
		});
			
	},

	showResponse : function(originalRequest) {
			
			if(originalRequest.responseText.substring(0,4) == 'http') {
				window.location = originalRequest.responseText; //redirect
			  } else {
				new Effect.Fade('waiting') ; //hide waiting div
				$('cmsForm').innerHTML = originalRequest.responseText; //show response
				new Effect.Shake('submitButton')
				citrusCMS.formStyle(); //load js functions again for new content
				citrusCMS.addCompanyType();
				citrusCMS.addSector();
  			}

	}
	
}


Event.observe(window, 'load', citrusCMS.load, false);
