function initUI () {
	dbox = new DarkBox();

	// get all div elements that need over
	divs_to_edit = document.getElementsByClassName('showcase_item_caption_thumb_border');
	
	if(!divs_to_edit[0]) {
		divs_to_edit = document.getElementsByClassName('items');
	}


	// apply the mouseover / mouseout things
	if(divs_to_edit[0]) {
		for(var i=0; i < divs_to_edit.length; i++) {
			divs_to_edit[i].onmouseover = doFadeIn;
			divs_to_edit[i].onmouseout = doFadeOut;
			divs_to_edit[i].onclick = doFadeOut;
		}
	}

	$('content_main').style.display = 'none';
	$('content_main').style.display = '';


}






function formValue(cValue, dom) {
	
	if (dom.value == cValue) {
		dom.value = "";
	} else if (dom.value == "") {
		dom.value = cValue;
	}
	
}

function swfWindow(url, width, height) {
	var newWindow = window.open(url, "swfWindow", "width="+width+", height="+height+", resizable=no");
}


function doFadeIn() {	
	var fader = new bgFade();
	fader.fade(this, 'in');
}

function doFadeOut() {
	var fader = new bgFade();
	fader.fade(this, 'out');
	
}

/* Showcase FADER!!!!!!! */
function bgFade() {
	
	this.colorsIn = new Array("#532a45", "#703d3e", "#8d5037", "#aa6230", "#c77529", "#e48822", "#F7941D");
	
	this.colorsOut = new Array("#F7941D", "#e48822", "#c77529", "#aa6230", "#8d5037", "#703d3e", "#532a45");
	this.colorsOut2 = new Array("247, 148, 29", "228, 136, 34", "247, 148, 29", "199, 117, 41", "170, 98, 45", "141, 80, 55", "112, 61, 62");
	
	this.colorCount = 0;
	this.currentlyExecuting = true;
	this.dom = null;
	this.state = null;
	
	this.fade = function(dom, state) {
		
		this.dom = dom;
		this.state = state;

		setInterval(this.actionTimer.bind(this), 30);

	}
	
	this.actionTimer = function() {
		if (this.currentlyExecuting) 
		{

			if (this.state == "in") {
	        	$(this.dom).style.backgroundColor = this.colorsIn[this.colorCount];
			} else {
				$(this.dom).style.backgroundColor = this.colorsOut[this.colorCount];
			}

	    }
		
		this.colorCount++;
		
		if (this.colorCount == this.colorsIn.length) 
		{
			this.currentlyExecuting = false;
		
			if (this.state == "in") 
			{
				$(this.dom).style.backgroundImage = "none";
				
				if (!document.documentElement && typeof document.documentElement.style.maxHeight=="undefined") {
					//means ie6
					if($(this.dom).filters)
					{
						$(this.dom).filters.item(0).enabled = 0;
					}
				}
				
			
			} else {
				$(this.dom).style.backgroundImage = "url(/images/background_showcase_thumb.png)";
				$(this.dom).style.backgroundColor = "transparent";		    
				$(this.dom).removeAttribute("style");
				
				if (!document.documentElement && typeof document.documentElement.style.maxHeight=="undefined") {
					if($(this.dom).filters)
					{
						$(this.dom).filters.item(0).enabled = 1;
					}
				}
					
				
				
			}
		}
	}
	
}


/* Form Processing */
function subscribe() {
	
	var form = $('sfrm');
	var email = form.email.value;
	
	//Validate Email
	if (email == "" || email == "subscribe" || email.indexOf("@") == -1 || email.indexOf(".") == -1) {
		setTimeout(function() { $('stay_in_touch').id  = "stay_in_touch2"; }, 300);
		Effect.Fade('sfrm', {duration: 0.4, afterFinish:
			 function(e) { 
				$('sfrm').innerHTML = "<span class='orange_heading'>Please enter a valid email address</span>"; 
				Effect.Appear('sfrm', {duration: 0.4})
				setTimeout(function() {
					setTimeout(function() { $('stay_in_touch2').id  = "stay_in_touch"; }, 500);
					
					Effect.Fade('sfrm', {duration: 0.4, afterFinish: function(e) {
						$('sfrm').innerHTML = "<input onfocus=\"formValue('your email address', this)\" onblur=\"formValue('your email address', this)\" type='text' class='subscribe_tf1' name='email' value='"+email+"' /><a class='subscribe' onclick='subscribe();' href='#'><span class='access'>Subscribe</span></a>"; 
						Effect.Appear('sfrm', {duration: 0.4, to: 1.0});
						
					}})
				}, 1500);
			}
		});
	} else {
	
		data = Form.serialize(form);
		
		var url = '/subscribe.php';
	    var myAjax = new Ajax.Updater("tt", url, {method: 'post', parameters: data});
		
		setTimeout(function() { $('stay_in_touch').id  = "stay_in_touch2"; }, 300);
		Effect.Fade('sfrm', {duration: 0.4, afterFinish:
			 function(e) {
				$('sfrm').innerHTML = "<span class='orange_heading'>Thank-you for subscribing.</span>"; 
				Effect.Appear('sfrm', {duration: 0.4})
				Element.setStyle('sfrm', { opacity: 0.999999 });
			}
		});	
	}
	
}

function sendContact() {
	
	var form = $('cfrm');

	//Validate Feidls
	fieldsRequired = new Array("first_name", "last_name", "email", "phone");
	var error = new Array();
	for (i=0;i<form.elements.length;i++) {
		for(i2=0;i2<fieldsRequired.length;i2++) {
			if (form.elements[i].name == "enq["+fieldsRequired[i2]+"]") {
				//YAY, start validating
				
				cError = false;
				if (form.elements[i].name == "enq[email]") {
					if (form.elements[i].value.indexOf("@") == -1 || form.elements[i].value.indexOf(".") == -1) {
						if (form.elements[i].value == "") {
							cError = "Email not entered correctly";
						} else {
							cError = "Email not valid";
						}
					}
					
				}

				if (form.elements[i].value == "" || cError != false) {
					var Name = fieldsRequired[i2].replace("_", " ");
					Name = Name.substr(0, 1).toUpperCase()+Name.substr(1);
					if (cError == false) {
						error[error.length++] = Name+" not entered correctly";
					} else {
						error[error.length++] = cError;
					}
					$(fieldsRequired[i2]+"s").style.color = "#F7941D";
				} else {
					$(fieldsRequired[i2]+"s").style.color = "#FFF";
				}
			}
		}
	}

  if ($('source').value == "blank") {
    error[error.length++] = "Sales channel not selected";
    $('sources').style.color = "#F7941D";
  }
  else {
    $('sources').style.color = "#FFF";    
    if($('source').value == "Other" && $('sourceother').value.length == 0) {
      error[error.length++] = "Sales Channel not entered";				     
      $('sourceothers').style.color = "#F7941D";      
    }
    else {
      $('sourceothers').style.color = "#FFF";            
    }
  }
  	
	var errStr = "";
	for(i=0;i<error.length;i++) {
		if (i == 1) {
			errStr += "<div style='margin-left: 7px'>";
		}
		errStr += error[i]+"<br />";
		if (i == error.length-1) {
			errStr += "</div>";
		}
	}
	
	if (errStr != "") {
		Effect.Fade('rmes', {duration: 0.4, to: 0.001, afterFinish: 
			function(e) {
				$('rmes').innerHTML = "* "+errStr;
				Effect.Appear('rmes', {duration: 0.4});
			}
		});
		return false;
	} else {
		//Send email
		data = Form.serialize(form);
		
	     var url = '/process.php';
	     var myAjax = new Ajax.Updater("tt", url, {method: 'get', parameters: data});
	
		Effect.Fade('rmes', {duration: 0.4});
		Effect.Fade('cfrm', {duration: 0.4, to: 0.0001, afterFinish: function(e) {
			$('cfrm').innerHTML = "<span class='orange_heading'>Your message has been sent. Thank-you.</span>";
			Effect.Appear('cfrm', {duration: 0.4});
		}});
	}
}


/* Crossfade */
function doCrossFade() {
	if (document.getElementById('cislideshow')) {
		so_init();
	}
}

var d=document, imgs = new Array(), zInterval = null, current=0, pause=false;

function so_init() {
	if(!d.getElementById || !d.createElement)return;
	
	imgs = d.getElementById("cislideshow").getElementsByTagName("img");
	for(i=1;i<imgs.length;i++) imgs[i].xOpacity = 0;
	imgs[0].style.display = "block";
	imgs[0].xOpacity = .99;
	
	setTimeout(so_xfade,2000);
}

function so_xfade() {
	cOpacity = imgs[current].xOpacity;
	nIndex = imgs[current+1]?current+1:0;
	nOpacity = imgs[nIndex].xOpacity;
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	imgs[nIndex].style.display = "block";
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;
	
	setOpacity(imgs[current]); 
	setOpacity(imgs[nIndex]);
	
	if(cOpacity<=0) {
		imgs[current].style.display = "none";
		current = nIndex;
		setTimeout(so_xfade,2000);
	} else {
		setTimeout(so_xfade,80);
	}
	
	function setOpacity(obj) {
		if(obj.xOpacity>.99) {
			obj.xOpacity = .99;
			return;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
	}
	
}

function checkvalue(value) {
  if(value == "Other") {
    $('other-source').show();
  }
  else {
    $('other-source').hide();
  }
}