jssm.settings.blankurl = './blank.html';
jssm.settings.basetitle = 'JSSM Test';
jssm.settings.titleseparator = ' : ';

jssm.functions.pageload = function (hash) {
	if (hash) {
		jssm.functions.load(hash);
	} else {
		// start page
		$("#loadedContent").load('/startpage.php',function() {
			$('div#fpRotating').jcarousel({
				scroll: 1,
				visible: 1,
				auto: 3,
				wrap: "both",
				itemLoadCallback: mycarousel_itemLoadCallback
			});
			$('#indexWpContent').load('/wordpress/?page_id=255',function() {
				setMinHeightFromSidebar();
			});
		});
	}
}

jssm.functions.beforeload = function (hash) {

}

jssm.functions.load = function (hash) {
	
	$("html, body").animate({scrollTop: 0}, 500, "easeInOutBounce");

	// hash doesn't contain the first # character.
	$('#loadingAnim').fadeIn('fast');
	$('#loadedContent').fadeOut('fast');
	// restore ajax loaded state
	/*$.ajax({
		type: "GET",
		url: '/'+hash,
		success: function(XMLHTTPRequest, response) {
			$('#loadedContent').html(response);
			makeFancyButtons();
			setMinHeightFromSidebar();
			countSearchResults("adding");
		}
	});*/
	$("#loadedContent").load(hash, function(){
		$('#loadingAnim').fadeOut('fast',function() {
			//always clear any alerts first
			/*$('#alertsBottom').fadeOut('fast',function() {
				$('#alertsBottom').html('');
			});*/
			
			$("a[rel='history']","#loadedContent").jssm('click');
			$("form#manageEvents","#loadedContent").jssm('submit');
			$("form#radiusForm","#loadedContent").jssm('submit');
			
			$('#loadedContent').fadeIn('fast',function() {
				makeFancyButtons();
				setMinHeightFromSidebar();
				countSearchResults("adding");
				
				//check for search ads
				if ($('#showSearchAds').length > 0) {
					var adArray = explode("|",$('#showSearchAds').text());
					$('#searchAdContainer').html('<a href="'+adArray[1]+'"><img src="/img/advertisements/'+adArray[0]+'" /></a>');
					$('#searchAdContainer').slideDown('slow');
				}
				else
					$('#searchAdContainer').slideUp('fast');
					
				var pkBaseURL = (("https:" == document.location.protocol) ? "https://tev.educationvacation.com/piwik/" : "http://tev.educationvacation.com/piwik/");
				piwik_action_name = hash;
				piwik_idsite = 1;
				piwik_url = pkBaseURL + "piwik.php";
				piwik_log(piwik_action_name, piwik_idsite, piwik_url);
				
				//if this is the start page, intialize the carousel and load the wp content for startpage
				if ($('div#fpRotating').length > 0) {
					$('div#fpRotating').jcarousel({
						scroll: 1,
						visible: 1,
						auto: 3,
						wrap: "both",
						itemLoadCallback: mycarousel_itemLoadCallback
					});
					$('#indexWpContent').load('/wordpress/?page_id=255', function(){
						setMinHeightFromSidebar();
					});
				}
			});
			
		});
		
		//if this is an attraction page, set up a lightbox for the images
		if ( $('#accountPicContainer').length > 0 )
			$('#accountPicContainer a.singleImage').lightBox();
			
	});

	/*$.get('/'+jssm.getCurrentPath()+hash, function(response) {

		/* Process the response, light edition. 

		/* Set page title based upon the response. 
		var regextitle = new RegExp('<title>([^<]*)<\/title>');
		var matches = regextitle.exec(response);
		jssm.setTitle(jssm.buildTitle(matches[1]));

		/* Get the new content. 
		var inside = response.substring(response.indexOf('<body>') + 6, response.indexOf('</body>'));

		/* Fade in time. 
		$('.wrapper').queue(function () { 
			$(this).html($(inside).filter('div.wrapper').html());
			$('a', this).jssm('click');
			$('form', this).jssm('submit');
			$(this).fadeIn(500);
			$(this).dequeue();
		});
//
//		/* Add CSS to the page based upon the response. */
//		$('link', response).each(function(i) {
//			var css = document.createElement("link");
//			css.setAttribute('rel', 'stylesheet');
//			css.setAttribute('type', 'text/css');
//			css.setAttribute('href', $(this).attr('href'));
//			document.getElementsByTagName('head')[0].appendChild(css);
//		});
//
//		/* Add page content based upon the response. */
//		$('#wrapper').html($('body', response).text()).fadeIn(500);
//
//		/* Add scripts to the page based upon the response. */
//		$('script', response).each(function(i) {
//			$.globalEval($(this).text());
//		});

	//});

}

jssm.functions.afterload = function (hash) {

}

jssm.functions.beforeunload = function (hash) {

}

jssm.functions.unload = function (hash) {
	$('.wrapper').queue(function () { 
		$(this).fadeOut(500);
		$(this).dequeue();
	});
}

jssm.functions.afterunload = function (hash) {

}