$(function () {
	if( jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 ) {
		$('body').addClass('msie6');
		$('#header h1, #popup, #content img, body.who-we-are, .supersleight').supersleight();
		
		$('form .submit').hover(function() {
				$(this).addClass('hover');
			},
			function() {
				$(this).removeClass('hover');
		});
	}
	
	$("form .button").click(function() {
		$(this).closest("form").submit();
	});
	
	var disableTooltip = false;
	$('#sidebar .checkbox').hover(function() {
			if (!disableTooltip) {
				$(this).find('.tooltip').fadeIn();
			}
		},
		function(){
			$(this).find('.tooltip').fadeOut();
	});
	$(".tooltip, div.checkbox").click(function() {
		$(".tooltip").fadeOut();
		disableTooltip = true;
	});
	
	$("form input.watermarked").focus(function() {
		if (!$(this).data("value-changed")) {
			$(this).val("");
		}
		return true;
	}).blur(function() {
		if ($(this).val() == "") {
			$(this).val($(this).attr("title"));
		} else {
			$(this).data("value-changed", true);
		}
		return true;
	}).each(function() {
		// Tricky one... If you come back to the page using the Back button,
		// the watermark values will already be filled in, so we need to treat
		// this as equivalent to the field being blank on first load. However,
		// we can't distinguish this from the case where someone happened to
		// type the same thing as the watermark value. We'll just have to live
		// with that limitation, I think.
		//
		// Note that this is the only difference from the code in the blur event
		// handler.
		if ($(this).val() == "" || $(this).val() == $(this).attr("title")) {
			$(this).val($(this).attr("title"));
		} else {
			$(this).data("value-changed", true);
		}
	});
	
	$('#sidebar form .checkbox .replacement').click(function(){
		var wrapper = $(this).parent();
		
		if ( wrapper.find('input').attr('checked') ){
			wrapper.removeClass('checked').find('input').attr('checked', '');
		} else {
			wrapper.addClass('checked').find('input').attr('checked', 'true');
		}
	});
	
	$('#sidebar form').submit(function() {
		var ret = true;
		$(this).find("input[type=text]").each(function(i, e) {
			if ($(e).attr("value").toLowerCase() == $(e).attr('name')) {
				ret = false;
			}
			if ($(e).attr("value") == "") {
				ret = false;
			}
		});
		return ret;
	});
});

function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'block':(v=='hide')?'none':v; }
    obj.display=v; }
}

