/*
 * Sitewide, UI interactivity configuration
 */
var siteConfig = {
	self: {
		endpoints: {
			email: "data/email.php",
			pdf: "data/pdf.php"
		}
	},
	inquire: {
		form: {
			retrieveFromUrl: 	"data/inquire.php", //http://myllu.llu.edu/apps/ask/inquire.php?html_segment_only_in=Y
			action: 			"http://myllu.llu.edu/apps/ask/inquire.php"
		}
	},
	campusMap: {
		centerLatLon: [34.052615,-117.261693],
		serviceUrl: "data/campus-map.php",
		endpoints: {
			getBuildings: 			"?opt=buildings",
			search: 				"?opt=search",
			getBuildingDetails: 	"?opt=buildingInfo"
		}
	},
	ams: { // this is the ams data proxy service, in use only in the wizard for the moment
		serviceUrl: "data/ams.php", //../marketing/prospective_students_proxy.php
		endpoints: {
			getProgramFinancialInfo:	"?action=get_financial_info"
			,getContentList: 			"?action=search_programs"
			,getProgramList: 			"?action=get_programs"
			,getSchoolList: 			"?action=get_schools"
			,getDegreeList: 			"?action=get_degrees"
			,search: 					"?action=search_programs"
		}		
	},
	calendar: {
		iframeBaseUrl: "data/restylegc/restylegc.php",
		serviceUrl: "data/calendars.php",
		endpoints: {
			getList: "?opt=list",
			getDefault: "?opt=default"
		}
	}
};

/*
 * Remove the focus bar from clicked elements
 */
$("a").each(function() {
	$(this).click(function() { this.blur(); });
});


/*
 * Make sure that all of the wizard pages keep the previously selected state
 */
if (document.location.hash != '') {
	$("a.context").each(function() {
		$(this).attr('href', $(this).attr('href')+document.location.hash);
	});
}


/*
 * Sitemap functionality
 */
$('#sitemap').bind('toggleSitemap', function(e, show) {
	var sitemap = $(this);
	if (sitemap.is(':hidden') && show) {
		$('body').click(function(event) {
			sitemap.trigger('toggleSitemap', false);
		});
		sitemap.click(function(event) {
			event.stopPropagation();
		});
	} else if (!show) {
		$('body').unbind('click');
		sitemap.unbind('click');
	}
	sitemap.fadeToggle('fast');
});
$('#showSitemap > a').click(function(){
	$('#sitemap').trigger('toggleSitemap', true);
	return false;
});
$('#hideSitemap img').click(function(event){
	$('#sitemap').trigger('toggleSitemap', false);
	event.stopPropagation();
});

/*
 * handle when a field did not return data
 */
function fieldNotAvailable(field, title) {
	var html = '';
	if (typeof(title) != 'undefined' && title != null && title != '')
		html = '<div class="error">'+title+'not currently available</div>';
	$('#' + field).hide().html(html).fadeIn('fast');
}

/* validate an email properly
 * @source: http://rosskendall.com/blog/web/javascript-function-to-check-an-email-address-conforms-to-rfc822
 */
function isRFC822ValidEmail(sEmail) {

  var sQtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
  var sDtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
  var sAtom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
  var sQuotedPair = '\\x5c[\\x00-\\x7f]';
  var sDomainLiteral = '\\x5b(' + sDtext + '|' + sQuotedPair + ')*\\x5d';
  var sQuotedString = '\\x22(' + sQtext + '|' + sQuotedPair + ')*\\x22';
  var sDomain_ref = sAtom;
  var sSubDomain = '(' + sDomain_ref + '|' + sDomainLiteral + ')';
  var sWord = '(' + sAtom + '|' + sQuotedString + ')';
  var sDomain = sSubDomain + '(\\x2e' + sSubDomain + ')*';
  var sLocalPart = sWord + '(\\x2e' + sWord + ')*';
  var sAddrSpec = sLocalPart + '\\x40' + sDomain; // complete RFC822 email address spec
  var sValidEmail = '^' + sAddrSpec + '$'; // as whole string
  
  var reValidEmail = new RegExp(sValidEmail);
  
  if (reValidEmail.test(sEmail)) {
    return true;
  }
  
  return false;
}

/* add an idle function to jquery
 * @source http://stackoverflow.com/questions/316278/timeout-jquery-effects
 */
jQuery.fn.idle = function(time) {
  var o = $(this); 
  o.queue(function() { 
     setTimeout(function() {
        o.dequeue(); 
     }, time);
  });
  return this;
};

/*
 * add a toggle that fades between states
 */
jQuery.fn.fadeToggle = function(speed, easing, callback) {
   return this.animate({opacity: 'toggle'}, speed, easing, callback);

};