jQuery.ajaxSetup ({  
	cache: false,
	error:function(xhr,err){
		alert("readyState: "+xhr.readyState+"\nstatus: "+xhr.status);
		alert("responseText: "+xhr.responseText);
	}
});
var ajax_load = '<img src="/images/loading.gif" alt="Loading..." />';  
var loadUrl = '/ajax.asp';  

jQuery(document).ready(function() {
// CLUNKY MOBILE SOLUTION
	jQuery('#mobile').hide();
	var ua = navigator.userAgent;
	var checker = {
	  iphone: ua.match(/(iPhone|iPod)/),
	  blackberry: ua.match(/BlackBerry/),
	  android: ua.match(/Android/)
	};
	if (checker.android) {
		jQuery('#mobile').show();
	} else if (checker.iphone) {
		jQuery('#mobile').show();
	} else if (checker.blackberry) {
		jQuery('.#mobile').show();
	}

// ZEBRA STRIPING
	jQuery('TABLE.zebra TR:even').addClass('even');
	jQuery('TABLE.zebra TR:odd').addClass('odd');

// SETUP HIDE FOR NOTES
	jQuery('.note').click(function(){
		jQuery(this).hide();
	});
// 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();
	});

// CLEAR LAST LI BORDER
	jQuery('.lined LI:last-child').css('border','none');

// CAPTURE AJAX BUTTONS - in your code use the format <a href="/ajax/page-name">
	jQuery('a[href*="ajax"]').click(function () {
		var temp = jQuery(this).attr('href');
		temp = temp.split('/');
		var page = temp.pop();
		revealDialog(page);
		return false;
	});
	jQuery('.buttonContact').click(function () {
		revealDialog('contact');
		return false;
	});
	jQuery('.buttonPrivacy').click(function () {
		revealDialog('privacy');
		return false;
	});
	jQuery('.buttonError').click(function () {
		revealDialog('errorMessage');
		return false;
	});
});

// DIALOG BOX WITH AJAX
function revealDialog(element){
	jQuery('#dialog').css('height', jQuery(window).height()-170+'px');
	jQuery('#ajax').css('height', jQuery('#dialog').height()-100+'px');
	jQuery('BODY').css('overflow','hidden');
	jQuery('#ajax').load(loadUrl + ' #' + element, null, function(){
		// VALIDATE FORM THEN AJAX SUBMIT
		var t = jQuery('#formWithCaptcha').captcha();
		var v = jQuery('#formContact').validate({
			submitHandler: function(form){
				jQuery(form).ajaxSubmit({
					target: "#ajax",
					success: function() { 
						jQuery('#dialogWrapper').toggle();
						}  
				});
			}
		});
	});
	jQuery('#close').click(function () {
		jQuery('BODY').css('overflow','auto');
		jQuery('#dim').hide();
		jQuery('#dialog').hide();

	});
	jQuery('#dialog').css('top', (jQuery(window).scrollTop() + 50) + 'px');
	var tempHeight = jQuery(window).height();
	//jQuery('#dialog').css('height', tempHeight-100 + 'px');
	jQuery('#dim').toggle();
	jQuery('#dialog').toggle();
}

// RESIZE DIM ON WINDOW CHANGE
jQuery(window).bind('resize', function(){
	jQuery('#dim').css('height', jQuery(window).height());
	jQuery('#dialog').css('height', jQuery(window).height()-170+'px');
	jQuery('#ajax').css('height', jQuery('#dialog').height()-100+'px');
});

