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() {
// SETUP ZEBRA
	jQuery('TABLE.zebra TR:even').addClass('zebraEven');
	jQuery('TABLE.zebra TR:odd').addClass('zebraOdd');
// VALIDATE JOBS FORM
	jQuery('#formSendYourResume').validate();
// 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');

// add class to PDF downloads
	jQuery("a[href$='.pdf']").addClass("pdf"); 
	jQuery("a[href$='.PDF']").addClass("pdf");
	
// 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('/');
		page = temp.pop();
		revealDialog(page);
		return false;
	});
	jQuery('.buttonContact').click(function () {
		revealDialog('contact');
		return false;
	});
	jQuery('.buttonPrivacy').click(function () {
		revealDialog('privacy');
		return false;
	});

// NAV DESCRIPTION
	jQuery("#topNav LI").hover(function() {
		jQuery(this).css({'background':'#999 url(topnav_active.gif) repeat-x','cursor':'pointer'});
	}, function() {
		jQuery(this).css({'background':'none'}); 
	});
	jQuery("#topNav LI").click(function() {
		jQuery(this).parent().find('DIV').hide();
		jQuery(this).find('DIV').toggleClass('top').toggle().doTimeout(7000, function() {
			jQuery(this).hide();
		});
	})

// SETUP COLORBOX FOR PHOTO GALLERY
	jQuery("a[rel='photogallery']").colorbox({transition:"none"});
	jQuery("a[rel='photogallery'] IMG").hover(function() {
		jQuery(this).addClass('hover');
	}, function() {
		jQuery(this).removeClass('hover');
	});

// SETUP SHARING
	jQuery('#socialSharing').Sharing();

	
//PREVENT ENTER FROM SUBMITING THE OBIT FINDER FORM, INSTEAD CALL CUSTOM FUNCTION
	jQuery('#term').keydown(function(event) {
		if ((event.keyCode == 13) || (event.keyCode == '13')) {
			event.preventDefault();
			sendresults();
		}
	});

});

// DIALOG BOX WITH AJAX
function revealDialog(element){
	jQuery('#dialog').css('height', jQuery(window).height()-100+'px');
	jQuery('#ajax').css('height', jQuery('#dialog').height()-150+'px');
	jQuery('#ajax').load(loadUrl + ' #' + element, null, function(){
		if (element == 'contact') {
			jQuery('#ajax TABLE.zebra tr:even').addClass('zebraEven');
		}

		jQuery("#formContact").append("<input type='hidden' name='JS' value='enabled' />");
		jQuery("#formWithCaptcha").append("<input type='hidden' name='JS' value='enabled' />");
		// 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-150 + '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()-150+'px');
	jQuery('#ajax').css('height', jQuery('#dialog').height()-100+'px');
});


