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 PRE FOR NOTES
	jQuery('PRE').toggle(function() {
		jQuery(this).addClass('noteClick');
		jQuery(this).attr("title", "Click to close notes")
	} , function() {
		jQuery(this).removeClass('noteClick');
		jQuery(this).attr("title", "Click to view notes")
	}).attr("title", "Click to view notes");
// 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;
	});



// PEEL
	jQuery('#pageflip IMG').stop() //On hover out, go back to original
			.animate({
				width: '60px',
				height: '62px'
			}, 1220);
	jQuery('#pageflip').hover(function() { //On hover...
		jQuery('#pageflip IMG, .msg_block').stop()
			.animate({ //Animate and expand the image and the msg_block (Width + height)
				width: '307px',
				height: '319px'
			}, 500);
		} , function() {
		jQuery('#pageflip IMG').stop() //On hover out, go back to original size
			.animate({
				width: '60px',
				height: '62px'
			}, 220);
		jQuery('.msg_block').stop() //On hover out, go back to original size
			.animate({
				width: '60px',
				height: '60px'
			}, 200); //Note this one retracts a bit faster (to prevent glitching in IE)
	});

// 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();

});

// DIALOG BOX WITH AJAX
function revealDialog(element){
	jQuery('#dialog').css('height', jQuery(window).height()-100+'px');
	jQuery('#ajax').css('height', jQuery('#dialog').height()-100+'px');
	jQuery('BODY').css('overflow','hidden');
	jQuery('#ajax').load(loadUrl + ' #' + element, null, function(){
		if (element == 'contact') {
			jQuery('#ajax TABLE.zebra tr:even').addClass('zebraEven');
		}

		// 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()-100+'px');
	jQuery('#ajax').css('height', jQuery('#dialog').height()-100+'px');
});

