jQuery.ajaxSetup ({  
	cache: false  
});
var ajax_load = '<img src="images/loading.gif" alt="Loading..." />';  
var loadUrl = '/ajax.asp';  

jQuery(document).ready(function() {
	// SETUP DIALOG DIVS
	jQuery('#dialog').hide();
	jQuery('#dim').hide();
	jQuery('#dim').css('height', jQuery(document).height());
	jQuery('#dim').click(function() {
		jQuery('BODY').css('overflow','auto');
		jQuery('#dim').toggle();
		jQuery('#dialog').hide();
	});
	jQuery('.zebra TR:visible TD:first-child P').addClass('bold');
	jQuery('.zebra TR:odd TD').addClass('odd');
	jQuery('.zebra TR:even TD').addClass('even');

	// CAPTURE AJAX BUTTONS
//	jQuery('.buttonMainDoorway').click(function () {
//		revealDialog('mainDoorway');
//		return false;
//	});
	jQuery('.buttonContact').click(function () {
		revealDialog('contact');
		return false;
	});
	jQuery('.buttonPrivacy').click(function () {
		revealDialog('privacy');
		return false;
	});
	
	jQuery('.buttonThamesvilleMap').click(function () {
		revealDialog('ThamesvilleMap');
		return false;
	});
	
	jQuery('.buttonWardsvilleMap').click(function () {
		revealDialog('WardsvilleMap');
		return false;
	});
	
	jQuery('.buttonDuttonMap').click(function () {
		revealDialog('DuttonMap');
		return false;
	});
	// NAV DESCRIPTION
	jQuery('#topNav').find('.links').hide();
	jQuery('#topNav UL LI').hover(function() {
	//alert(jQuery(this).position().left);
		jQuery(this).find('.links').css({'left':jQuery(this).position().left + 'px', 'z-index':'10000'}).show();
	}, function() {
		jQuery(this).find('.links').hide();
	});

	// GLOBAL NAV
	jQuery('#globalNav').find('.links').hide();
	jQuery('#globalNav P').hover(function() {
		jQuery(this).addClass('hover');
	}, function() {
		jQuery(this).removeClass('hover');
	});
	jQuery('#globalNav UL LI').hover(function() {
	//alert(jQuery(this).position().left);
		jQuery(this).find('.links').css('left', jQuery(this).position().left + 'px');
		jQuery(this).find('.links').show();
	}, function() {
		jQuery(this).find('.links').hide();
	});
});




// DIALOG BOX WITH AJAX
function revealDialog(element){
	jQuery('BODY').css('overflow','hidden');
	jQuery('#ajax').load(loadUrl + ' #' + element, null, function(){
		if (element == 'contact') {
			jQuery('#ajax TABLE.zebra tr:even').addClass('zebraEven');
			jQuery('#ajax TABLE.zebra tr:odd').addClass('zebraOdd');
		}
		jQuery('#ajax TABLE.zebra tr').mouseover(function() {
			jQuery(this).addClass('zebraHover');
		});
		jQuery('#ajax TABLE.zebra tr').mouseout(function() {
			jQuery(this).removeClass('zebraHover');
		});

		if (element == 'mainDoorway'){
			revealer();
		}
		// VALIDATE FORM THEN AJAX SUBMIT
		var v = jQuery('#formContact').validate({
			rules: {
				form_CaptchaVal: {
					required: true,
					remote: {
						url: '/includes/testcaptcha.asp',
						type: 'post',
						data: {
							form_CaptchaVal: function() {return jQuery('form_CaptchaVal').val();}
						},
						success: function(data){
							alert(data);
						}
					}
				},
				messages: {
						form_CaptchaVal: 'Correct captcha is required'
				}
			},
			submitHandler: function(form){
				jQuery(form).ajaxSubmit({
					target: "#ajax",
					success: function() { 
						//jQuery('#dialog').animate({borderWidth:'10px', width:'740px', height:'430px'},400);
						jQuery('#dialogWrapper').toggle();
						}  
				});
			},
			onkeyup: false
		});
	});
	jQuery('#close').click(function () {
		jQuery('BODY').css('overflow','auto');
		jQuery('#dim').hide();
		jQuery('#dialog').css({'border':'0px solid #fff', 'width':'760px', 'height':'500px'});
		jQuery('#dialog').hide();

	});
	jQuery('#dialog').css('top', (jQuery(window).scrollTop() + 50) + 'px');
	jQuery('#dim').toggle();
	jQuery('#dialog').toggle();
}

// RESIZE DIM ON WINDOW CHANGE
jQuery(window).bind('resize', function(){
   jQuery('#dim').css('height', jQuery(window).height());
});

function revealer() {
	//jQuery('#revealerItemsBox').hide();
	jQuery('#revealerItemsAll').hide();
	jQuery('#revealerItemsBoxClose').click(function() {
			jQuery('#revealerItemsBox').animate({'left':'1000px'},200);
	});
	jQuery('#revealerItemsList LI').hover(function() {
			jQuery(this).addClass('hover');
		}, function() {
			jQuery(this).removeClass('hover');
		})
		.click(function() {
			var tempIndex = $('#revealerItemsList LI').index(this);
			var tempLI = $('#revealerItemsAll LI:eq('+tempIndex+')');
			jQuery('#revealerItemsBox DIV').html(tempLI.html());
			jQuery('#revealerItemsBox').animate({'left':'0px'},200);
			return false;
	});
}

