// Sliding headings

jQuery(document).ready( function() {               
	var isSliding = false;
	jQuery(".pointplan h3").click(function() {
		if (isSliding == false) {
			isSliding = true;
			jQuery(this).next().slideToggle("normal", function() {
				isSliding = false;
			});          
		} 
	});
	var anchor = (window.location.toString()).replace(/^.*#([a-z]+)$/, '$1');
	if (anchor != "") {
		jQuery('.pointplan h3:has(a[name=' + anchor + '])').click();
	}
});



// Random text image on home page

jQuery(document).ready( function() {  
	if( jQuery("body").hasClass("s-home") ) {	
		var splash = new Array();
		// Edit this array with the image file names.
		// eg. "text.gif"
		splash[0] = "text.gif";

		var numberofimages = splash.length;
		var randSplash = Math.floor(Math.random() * numberofimages);
		var splashURL = "/images/" + splash[randSplash];
		jQuery("#text img").attr("src", splashURL);
	}
});


// Lightbox
/*jQuery(function() {
	jQuery('.gallery a[rel*=lightbox]').lightBox({
		//fixedNavigation:true,
		imageLoading: '/images/loading.gif',
		imageBtnClose: '/images/close.gif',
		imageBtnPrev: '/images/prev.gif',
		imageBtnNext: '/images/next.gif'
	});
});*/


function getFileName(place) {
var url = place,
i = url.lastIndexOf('/') + 1,
j = url.indexOf('#', i),
k = url.indexOf('?', i);

if(-1 == j) {j = url.length;}
if(-1 == k) {k = url.length;}

return url.substring(i, Math.min(j, k));
}

// Greg's sidenav attempt 1
jQuery(document).ready( function() {
   var myurl = getFileName(document.URL);
   jQuery('#backnav a').each( function(i) {
	    var itemhref = jQuery(this).attr("href");
		var convertedhref = getFileName(itemhref);
		if (convertedhref == myurl) {
			jQuery(this).addClass("active");
		}
	});
});


/* Show splash screen
jQuery(document).ready( function() {
	if ( jQuery("body").hasClass("s-home") ) {
			var visited = amt();
			//alert(visited);
			if (visited != "yes") {
				document.location = "splash.aspx";
			}
	}
});
*/


jQuery(function(){
	jQuery('#nav ul').superfish();
});


jQuery(function() {
	jQuery(".s-home .preview a").innerfade({
		speed: 750,
		timeout: 3000,
		containerheight: "139px"
	});
});



jQuery(function() {
	jQuery("#backnav .searchbox input").focus(function(){
		jQuery("#backnav .searchbox a").addClass("focus");
		jQuery(this).addClass("focus");
	});
	jQuery("#backnav .searchbox input").blur(function() {
		jQuery("#backnav .searchbox a").removeClass("focus");
		jQuery(this).removeClass("focus");
	});

	
	jQuery("#search .searchbox input").focus(function(){
		jQuery("#search .searchbox a").addClass("focus");
		jQuery(this).addClass("focus");
	});
	jQuery("#search .searchbox input").blur(function() {
		jQuery("#search .searchbox a").removeClass("focus");
		jQuery(this).removeClass("focus");
	});
});


// 'FancyBox' calls. (Pretty new lightbox)
/*jQuery(document).ready(function(){
	jQuery("a.fancybox, .thumb a").fancybox({
		'overlayShow':true	
	});
	jQuery(".thumb a").fancybox();
});*/

jQuery(document).ready(function() {
	jQuery('form[name*=search]').submit(function() {
		var query = jQuery.trim(jQuery('input[name=q]', this).val());
		if (query == 'Search' || query == '')
			return false;
	});
});

/*
jQuery(function(){
	var $bodyclass = jQuery("body").attr("class");
	if(typeof sIFR == "function"){
	    sIFR.replaceElement("#twitter_update_list li", named({
	    	sFlashSrc: "/flash/annifont.swf", 
	    	sColor: "#FFFFFF",
	    	sWmode: "transparent"
	    }));
	}
	jQuery("body").attr("class",$bodyclass);
});
*/