new function(){
	$(document).ready(function(){
		makeBigTargets();
		ajaxSubmits();
		popUpSendmail();
		ieHover('.locations li, .navigation li, .sidebar li, .left1 li');
		clearSeach();
		initTabs('.tabset .tab');
		$('.locations').hover(function(){
			var _box = $(this).find('.lightbox');
			_box.show();
			hideSelectBoxes(_box);
		
		}, function(){
			var _box = $(this).find('.lightbox');
			_box.hide();
			showSelectBoxes(_box);
		});
	
	
	
	});

	/*
	Increase target area for clicks.
	*/
	function makeBigTargets(){
		apply("*:has(>a.button,>a.more)");
		apply("div.related-box");
		apply("div.case");
		function apply(grp){
			$(grp).each(function(){
			    this.onclick = function(){
		        	document.location.href = $("a",this).get(0).href;
		    	};
		    	this.style.cursor = "pointer";
			});
		};
	};


	/*--- function clear seach field ---*/
	function clearSeach() {
		var _field = $('#header div.text :text');
		var _text = $('#header div.text :text').val();
		_field.focus(function() {
			if($(this).val() == _text) { $(this).val('');}
		});
		_field.blur(function() {
			if($(this).val() == '') { $(this).val(_text);}
		});
	};

	/*--- function hover fo IE6 or later ---*/
	function ieHover(_list) {
		if ($.browser.msie && $.browser.version < 7) {
			$(_list).each(function() {
				this.onmouseover = function() {
					$(this).addClass('hover');
				}
				this.onmouseout = function() {
					$(this).removeClass('hover');
				}
			});
		}
	};

	/*--- function tabs ---*/
	function initTabs(btn_list){
		btn_list = $(btn_list);
		var _a = 0;
		btn_list.each(function(_ind, _el) {
			_el.box = $('#' + _el.href.substr(_el.href.indexOf("#") + 1));
			if($(_el).hasClass('active')) {
				if(_el.box) _el.box.show();
				_a = _ind;
			}
			else {
				if(_el.box) _el.box.hide();
			}
			_el.onclick = function() {
				if(_ind != _a) {
					if(btn_list.get(_a).box) btn_list.get(_a).box.hide();
					btn_list.eq(_a).removeClass('active');
					if(_el.box) _el.box.show();
					$(_el).addClass('active');
					_a = _ind;
				}
				return false;
			};
		});
	};

	/*--- function hide/show selects for IE ---*/
	function hideSelectBoxes(object) {
		if ($.browser.msie && $.browser.version < 7) {
			var selects_list = $('select');
			object.each(function() {
				var _el = $(this);
				var t = _el.offset().top;
				var l = _el.offset().left;
				var w = _el.outerWidth();
				var h = _el.outerHeight();
				var el_selects = [];
				selects_list.each(function(){
					var _select = $(this);
					var s_t = _select.offset().top;
					var s_l = _select.offset().left;
					var s_w = _select.outerWidth();
					var s_h = _select.outerHeight();
					var _ver = false, _hor = false;
					if((t - s_t > 0) ? (t - s_t < s_h) : (t - s_t + h > 0)) _ver = true;
					if((l - s_l > 0) ? (l - s_l < s_w) : (l - s_l + w > 0)) _hor = true;
					if(_ver && _hor) {
						_select.css('visibility', 'hidden');
						el_selects.push(this);
					}
				});
				this.sboxes = el_selects;
			});
		}
	};
	function showSelectBoxes(object) {
		if ($.browser.msie && $.browser.version < 7) {
			object.each(function() {
				if(this.sboxes.length > 0) {
					$(this.sboxes).css('visibility','visible');
				}
			});
		}	
	};

	/*
	Submit to sendmail form using ajax
	*/
	function ajaxSubmits(){
		$("form[action$='/sendmail/']").unbind("submit");
		$("form[action$='/sendmail/']").bind("submit",function(){
			var theform = this;
			if($(".submit-result",theform).length<1){
				$(":visible:first",theform).after("<p class='submit-result' />");
			}
			function updateResult(txt,cls,success){
				$(".submit-result:first",theform)
				.fadeOut("slow",function(){
					$(this)
					.text(txt)
					.fadeIn("slow");
					if(success){
						$(":not(.submit-result)",theform).fadeOut("slow");
						theform.reset();
						
						setTimeout(function(){
						$("p.send_another",theform).remove();
						$(theform).append("<p class='send_another' style='display:none'><a href='#'>Click here to send another message.</a></p>");
						$("p.send_another",theform).fadeIn("slow")
						.bind("click",function(){
							$(this).remove();
							$(".submit-result",theform).text("");
							$(":not(.submit-result)",theform).fadeIn("slow");
							return false;

						});
						},1000);
						
					}
				})
			};
			if(!String(theform.elements["from"].value).match(/^[^@]+@[^@]+\.[^@]+$/)){
				updateResult("Please enter your full email address, so we can respond to your inquiry.");
				return false;
			}
			//$(".submit-result:first",theform).hide();
			var qstring = $(theform).serialize();
			$("*",theform).each(function(){
				this.disabled = true;
			});
			$(document.createElement("div")).load(theform.action +"?"+qstring,function(){
				$("*",theform).each(function(){
					this.disabled = false;
				});
				theform.disabled = false;
				var thediv = this;
				updateResult(String($(".submit-result",thediv).text()).replace(/^\w*(.*)\w$/,"$1"),"",true);
				
			});
			return false;
		});
	};
	function popUpSendmail(){
		$("a[href^='/sendmail/']").bind("click",function(){
			var a = this;
			var thehref= this.href;
			a.disabled = true;
			var mailform = $("div[_mailform='"+this.href+"']",this.parentNode);
			if(mailform.length<1){
				$(this).after("<div _mailform='"+this.href+"' style='display:none'></div>");
				mailform = $("div[_mailform='"+this.href+"']",this.parentNode);
			}
			function hideMe(){
				$(mailform).slideUp("slow");
			};
			
			mailform.load(thehref+" form.sendmail",function(){
				a.disabled = false;
				ajaxSubmits();
				$(mailform).slideDown("slow")
				.append("<p><a href='#' class='form-close' title='hide form'>Click here to close the form.</a></p>")
				.each(function(){
					$("a:last",this).bind("click",function(){
						hideMe();
						return false;
					});
				});
			});
			return false;
		});
	};
};

