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').fadeToggle();
		jQuery('#dialog').hide();
	});

	// CAPTURE AJAX BUTTONS
	jQuery('.buttonContact').click(function () {
		revealDialog('contact');
		return false;
	});
	jQuery('.buttonSubscribe').click(function () {
		revealDialog('subscribe');
		return false;
	});
	jQuery('.buttonUnsubscribe').click(function () {
		revealDialog('unsubscribe');
		return false;
	});
	jQuery('.buttonPrivacy').click(function () {
		revealDialog('privacy');
		return false;
	});


	// CUSTOM FADE TOGGLE
	jQuery.fn.fadeToggle = function(speed, easing, callback) {
		return this.animate({opacity: 'toggle'}, speed, easing, callback);
	};
});

// DIALOG BOX WITH AJAX
function revealDialog(element){
	jQuery('BODY').css('overflow','hidden');
	jQuery('#ajax').load(loadUrl + ' #' + element, null, function(){
		// VALIDATE FORM THEN AJAX SUBMIT
		var v = jQuery('#formContact').validate({
			submitHandler: function(form){
				jQuery(form).ajaxSubmit({
					target: "#ajax",
					success: function() { 
						$('#dialog').animate({borderWidth:'10px', width:'710px', height:'500px'},400);
						}  
				});
			}
		});
	});
	jQuery('#close').click(function () {
		jQuery('BODY').css('overflow','auto');
		jQuery('#dim').hide();
		jQuery('#dialog').css({'border':'0px solid #fff', 'width':'710px', 'height':'500px'});
		jQuery('#dialog').hide();

	});
	jQuery('#dialog').css('top', (jQuery(window).scrollTop() + 40) + 'px');
	jQuery('#dim').fadeToggle();
	jQuery('#dialog').toggle();
}

// RESIZE DIM ON WINDOW CHANGE
jQuery(window).bind('resize', function(){
   jQuery('#dim').css('height', jQuery(window).height());
});

