// JavaScript Document
var loopid = 'banner';
var viewid=1;
// Perform on initial page load.
$(function() {
	$.history.init(callback);
	$.ajaxSetup ({
		// Disable caching of AJAX responses */
		// cache: false
	});		  
	setOverlay();
	$('ul#leftNav a').click(function() {
		var view = $(this).attr('href').split('view=');
		$.history.load(view[1]);
		return false;
	});
	$.doTimeout(loopid, 5000, function(){
		if(0==1) return false;
		if(viewid==1){
			switchBanner('banner/survey-banner.htm');
			viewid = 2;
		}else{
			switchBanner('banner/assessment-banner.htm');
			viewid = 1;
		}
		return true;
	});
	//switch banners and cancel rotation
	$('div#bannerNavigation a[rel]').click(function(){
		$.doTimeout(loopid);					
		var banner = $(this).attr('rel');
		switchBanner(banner);
		return false;
	});
	
});

// switch banner
function switchBanner(banner){
	$('div#banner div').fadeOut(
		500
		, function(){
			$('div#banner div').empty().load(
				banner
				, function(){
					$('div#banner div').fadeIn(500);
				}
			);
		}
	);
}
// set overlay
function setOverlay(){
	$('div.thumbnail img[rel]').overlay({effect: 'apple'});
}
// this function is used to maintain history in the browser when
	// someone clicks one of the ajaxified links
	// this is essentially HIJAX.
function callback(hash)
{
	if(hash!=''){
		var source = $('ul#leftNav a[href$=' + hash + ']');
		var folder = source.attr('href').split('.php');
		var height = $('div#bodyContent').height();
		var ext = ((hash!='send-us-a-message')?'.htm':'.php');
		// update the navigation so that the correct page is selected
		$('ul#leftNav li').removeClass('selected');
		source.parent().addClass('selected');
		// use animation to change the content on the page
		$('div#bodyContent').hide('slide'
			, function(){
				$('div#bodyContent').empty().load(
					folder[0] + '/' + hash + ext
					,function(response, status, xhr) {
						$('div#bodyContent').show('slide');				
						setOverlay();
					}
				);
			}								  
		);
	}
}


