$(document).ready( function()
	{
		$(".mainmenu ul li ul").hide();
		$(".mainmenu ul li ul li ul").hide();
		var myAgent = navigator.userAgent.toLowerCase();
		if(myAgent.indexOf('blackberry') < 0 && myAgent.indexOf('iphone') < 0 && myAgent.indexOf('mobile') < 0){
			$(".mainmenu").find("li").hover( function()
			{
				$(this).find("ul").stop(true,true).animate({ height: 'show', opacity: 'show' }, 'slow');
				$(this).find("ul li ul").stop(true,true).hide();
			}, function()
			{
				$(this).find("ul").stop(true,true).animate({ height: 'hide', opacity: 'hide' }, 'slow');
				$(this).find("ul li ul").stop(true,true).hide();
			}).find("ul li").hover( function()
			{
				$(this).find("ul").stop(true,true).hide().animate({ width: 'show', opacity: 'show' }, 'slow');
				$(this).find("ul li ul").stop(true,true).hide();
			}, function()
			{
				$(this).find("ul").stop(true,true).show().animate({ width: 'hide', opacity: 'hide' }, 'slow');
				$(this).find("ul li ul").stop(true,true).hide();
			});
		}
		
		var locat = location.href
		
		
		
		var locat = location.href;

		
		
		$(".mainmenu ul li a").each(function(){
			if(locat.indexOf(this.href) >= 0)
			{
				this.className += " active"
			}
		});
		
		/*if($(".scroll").children().length > 0 && $(".EditableTextEdit").length <= 0)
		{
			var scrolled = $(".scroll").html();
			$(".scroll").html('<div class="scroll_main"><div class="scroll_container"></div><div class="clear"></div></div><div class="slider_container"><div id="slider"><div class="ui-slider-handle"></div></div></div>').css('overflow','hidden');
			$(".scroll_container").html(scrolled);
			$(".scroll").find(".scroll_main").css('margin-right','-1000%','width','1000%'); 

			$("#slider").slider({
				change: function(event, ui) { getPosition($(this)); },
				stop: function(event, ui) { getPosition($(this)); },
				slide: function(event, ui) { getPosition($(this)); }
			);
    		}*/
    		var contactSmt = $('.EditingFormTable').find('.FormButton');
    		contactSmt.parent().append('<input type="reset" value="Reset Form" />');
    		contactSmt.click(function(){document.getElementById('form1').onsubmit = function() { return validate()}});
    		
    		$('.footer ul').append('<li><span>Change Text Size: <a href="javascript:changetoDefault()" class="a_s" title="Change the text to the default size.">A</a> <a href="javascript:changetoMedium()" class="a_m" title="Change the text to a larger size.">A</a> <a href="javascript:changetoLarge()" class="a_l" title="Change the text to the largest size.">A</a></span></li>');
	}
);

function getPosition(mySlider)
{
	myHandle = mySlider.find('.ui-slider-handle');
	sliderOffset = mySlider.offset().left;
	sliderHandOffset = myHandle.offset().left;
	sliderWidth = mySlider.width();
	sliderHandWidth = myHandle.width();
	offset = sliderHandOffset - sliderOffset;
	
	newLeft = -($('.scroll_container').width() * (offset/(sliderWidth-sliderHandWidth)))+(($('.slider_container').width()+8)*(offset/(sliderWidth-sliderHandWidth)));
	
	$('.scroll_main').stop(true,false).animate({marginLeft:newLeft}, 'slow');
	
}

var clearText = new Array('username', 'password', 'Search Site');

function clearCheck(myInput)
{
	for(i=0;i<clearText.length;i++)
	{
		if(myInput.value == clearText[i])
		{
			myInput.value = "";
		}
	}
}

if(navigator.appVersion.indexOf('Safari') > 0)
{
	document.write('<style type="text/css">.mainmenu ul li ul li ul, .mainmenu ul li:hover ul li ul { margin-top:-25px!important; }</style>');
}

function validate(thisBtn)
{
	var missinginfo = "";
	var emailfilter = new RegExp(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+)+(\.[a-zA-Z0-9]{2,4})+$/);
	//var phonefilter = new RegExp(/^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/);
	
	if ($('#plcRoot_Layout_zonePagePlaceholder_pageplaceholder_pageplaceholder_Layout_zoneContent_editabletext_BizFormControl1_Bizform1_ctl00_YourForename').attr('value') <= 0) {
		missinginfo += "\n     -  First Name";
	}
	if ($('#plcRoot_Layout_zonePagePlaceholder_pageplaceholder_pageplaceholder_Layout_zoneContent_editabletext_BizFormControl1_Bizform1_ctl00_YourSurname').attr('value') <= 0) {
		missinginfo += "\n     -  Surname";
	}
	if ($('#plcRoot_Layout_zonePagePlaceholder_pageplaceholder_pageplaceholder_Layout_zoneContent_editabletext_BizFormControl1_Bizform1_ctl00_Youraddress').attr('value') <= 0) {
		missinginfo += "\n     -  Address";
	}
	
	if ($('#plcRoot_Layout_zonePagePlaceholder_pageplaceholder_pageplaceholder_Layout_zoneContent_editabletext_BizFormControl1_Bizform1_ctl00_YourEmail_txtEmailInput').attr('value') <= 0) {
		missinginfo += "\n     -  Email Address";
	}
	else if (!emailfilter.test($('#plcRoot_Layout_zonePagePlaceholder_pageplaceholder_pageplaceholder_Layout_zoneContent_editabletext_BizFormControl1_Bizform1_ctl00_YourEmail_txtEmailInput').attr('value')) && $('#plcRoot_Layout_zonePagePlaceholder_pageplaceholder_pageplaceholder_Layout_zoneContent_editabletext_BizFormControl1_Bizform1_ctl00_YourEmail_txtEmailInput').length > 0) {
		missinginfo += "\n     -  A valid Email Address";
	}
	if($('#plcRoot_Layout_zonePagePlaceholder_pageplaceholder_pageplaceholder_Layout_zoneContent_editabletext_BizFormControl1_Bizform1_ctl00_YourEmail_txtEmailInput').attr('value') != $('#plcRoot_Layout_zonePagePlaceholder_pageplaceholder_pageplaceholder_Layout_zoneContent_editabletext_BizFormControl1_Bizform1_ctl00_ConfirmEmail_txtEmailInput').attr('value')) {
		missinginfo += "\n     -  Please make sure your email addresses match";
	}
	if($('#plcRoot_Layout_zonePagePlaceholder_pageplaceholder_pageplaceholder_Layout_zoneContent_editabletext_BizFormControl1_Bizform1_ctl00_Comments').attr('value') <= 0) {
			missinginfo += "\n     -  Your Message";
	}
	
	
	document.getElementById('form1').onsubmit = function() { javascript:return WebForm_OnSubmit();}
	
	if (missinginfo != "") {
	missinginfo ="_____________________________\n" +
	"You failed to correctly fill in your:\n" +
	missinginfo + "\n_____________________________" +
	"\nPlease re-enter and submit again!";
	alert(missinginfo);
	return false;
	}
	else return true;
}


function iotbs() {
	switcher = new switchManager();
};

var switcher;

//setup initialisation function
//.. gecko, safari, konqueror and generic
if(typeof window.addEventListener != 'undefined') {
	window.addEventListener('load', iotbs, false);
}
//.. opera 7
else if(typeof document.addEventListener != 'undefined') {
	document.addEventListener('load', iotbs, false);
}
//.. win/ie
else if(typeof window.attachEvent != 'undefined') {
	window.attachEvent('onload', iotbs);
}


//preferences manager
function switchManager() {
	//string for storing the overall custom classname
	//I was originally storing it in the body class name directly
	//but 1.7+ mozilla builds were not honouring the trailing whitespace we need
	this.string  = '';

	//store reference to body element
	this.body = document.getElementsByTagName('body')[0];

	//store the initial classname
	this.initial = this.body.className;

	//if the default classname is empty, add "iotbs"
	//because we need there to be at least one classname already -
	//the leading and trailing space in each custom classname is required,
	//but you can't set the body classname as " something" (beginning with a leading space)
	//because that may not work in Opera 7
	if(this.initial == '') {
		this.initial = 'itobs';
	}

	//look for a stored cookie
	this.cookie = this.read();

	//if it exists
	if(this.cookie != null) {
		//store cookie value to string
		this.string = this.cookie;

		//set new body class name
		this.body.className = this.initial + ' ' + this.string;
	}

	//*** dev
	//document.title = '<' + this.body.className.replace(/ /g,'+') + '>   [' + this.string.replace(/ /g,'+') + ']';
};

//set a cookie method
switchManager.prototype.set = function(days) {
	//format expiry date
	this.date = new Date();
	this.date.setTime(this.date.getTime() + ( days *24*60*60*1000));

	//store the string, replacing spaces with '#' so that leading spaces are preserved
	this.info = this.string.replace(/ /g,'#');

	//if the value is empty, set its expiry in the past to delete the cookie
	if(this.info == '') { this.date.setTime(0); }

	//create the cookie
	document.cookie = 'bodySwitcher=' + this.info
		+ '; expires=' + this.date.toGMTString()
		+ '; path=/';
};


//read a cookie method
switchManager.prototype.read = function() {
	//set null reference so we always have something to return
	this.cookie = null;

	//if a cookie exists
	if(document.cookie) {
		//if it's our cookie
		if(document.cookie.indexOf('bodySwitcher')!=-1) {
			//extract and store relevant information (turning '#' back into spaces)
			this.cookie = document.cookie.split('bodySwitcher=');
			this.cookie = this.cookie[1].split(';');
			this.cookie = this.cookie[0].replace(/#/g,' ');
		}
	}
	return this.cookie;
};


function changetoDefault() {
	switcher.string = 'default'
	switcher.body.className = " iotbs  ";
	switcher.set(365);
}

function changetoMedium() {
	switcher.string = 'medium';
	switcher.body.className = " iotbs  " + switcher.string +' ';
	switcher.set(365);
}

function changetoLarge() {
	switcher.string = 'large';
	switcher.body.className = " iotbs  " + switcher.string +' ';
	switcher.set(365);
}