var nf = window.nf || {}; // Initialize namespace.

function OpenWindow(url,wWidth,wHeight,scrollbar) {
	if (scrollbar == true) {
		scrollbar = 1
	} else {
		scrollbar = 0
	} // if
	NewWindow=window.open( url ,"_NewWindow_","toolbar=0,width="+wWidth+",height="+wHeight+",location=0,menubar=0,scrollbars="+scrollbar+",resizable=0")
	NewWindow.focus()
} // OpenWindow

function randStrings(howMany, howLong) {
	// define a string with valid characters
	var characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ"+"abcdefghiklmnopqrstuvwxyz";
	for (var i=0;i<howMany;i++) {
		var word="";
		for (var j=0;j<howLong;j++) {
			var rand = Math.floor(Math.random() * characters.length);
			word += characters.substring(rand,rand+1);
		}
	}
	return word;
} // randStrings

function new_captcha() {
	// loads new freeCap image
	if(document.getElementById) {
		// extract image name from image source (i.e. cut off ?randomness)
		thesrc = document.getElementById("captcha").src;
		thesrc = thesrc.substring(0,thesrc.lastIndexOf(".")+4);
		// add ?(random) to prevent browser/isp caching
		document.getElementById("captcha").src = thesrc+"?action=captcha&"+randStrings(1,5);
	} else {
		alert("Sorry, cannot auto-reload security code image\nSubmit the form and a new security code will be loaded");
	} // if
} // new_captcha

function windowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
/*  window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );*/ 
  return new Array (myWidth, myHeight);
} // windowSize

function windowSizeWithScroll() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
    	//Non-IE
    	myWidth = window.innerWidth;
        myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myWidth = document.documentElement.clientWidth;
	    myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { 
    	//IE 4 compatible
    	myWidth = document.body.clientWidth;
    	myHeight = document.body.clientHeight;
	}
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
	    //Netscape compliant
	    scrOfY = window.pageYOffset;
	    scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
	    //DOM compliant
    	scrOfY = document.body.scrollTop;
    	scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
	    //IE6 standards compliant mode
    	scrOfY = document.documentElement.scrollTop;
    	scrOfX = document.documentElement.scrollLeft;
	}

	return [ myWidth + scrOfX, myHeight + scrOfY ];
} // windowSizeWithScroll

function changePage (page) {
	if (page == 'events') {
		window.location='index.php?module=Calendar&view=tiled';
	} else {
		window.location='index.php?module=Page&page='+page;
	}
}

var min_fade = 20;
var max_fade = 100;
var fade_speed = 15;
function trans_init () {
	if (navigator.appName == "Microsoft Internet Explorer") {
		browserdetect = "ie";
	} else if (navigator.appName == "Netscape") {
		browserdetect = "mozilla";
	}
}

function slowhigh (element) {
	cleartimer();
	fadeobj = element;
	instantset(element,min_fade);
	highlighting = setInterval("gradualfade(fadeobj)",fade_speed);
}

function slowlow (element,opacity) {
	cleartimer();
	fadeobj = element;
	instantset(element,max_fade);
	highlighting = setInterval("gradualfadedown(fadeobj)",fade_speed);
}

function instantset (element,degree) {
	if (browserdetect=="mozilla")
		element.style.MozOpacity=degree/100;
	else if (browserdetect=="ie")
		element.style.filter = 'alpha(opacity='+degree+')';
}

function cleartimer () {
	if (window.highlighting) clearInterval(highlighting)
}

function gradualfade (cur2) {
	if (browserdetect=="mozilla" && cur2.style.MozOpacity<(max_fade/100)) {
		cur2.style.MozOpacity=Math.min(parseFloat(cur2.style.MozOpacity)+0.01,(max_fade/100));
	} else if (browserdetect=="ie" && cur2.filters.alpha.opacity<max_fade) {
		cur2.filters.alpha.opacity+=1;
	} else if (window.highlighting) {
		clearInterval(highlighting);
	}
}

function gradualfadedown (cur2) {
	if (browserdetect=="mozilla" && cur2.style.MozOpacity>(min_fade/100)) {
		cur2.style.MozOpacity=Math.min(parseFloat(cur2.style.MozOpacity)-0.01, (max_fade/100));
	} else if (browserdetect=="mozilla" && cur2.style.MozOpacity<=(min_fade/100)) {
		slowhigh (cur2);
	} else if (browserdetect=="ie" && cur2.filters.alpha.opacity>min_fade) {
		cur2.filters.alpha.opacity-=1;
	} else if (browserdetect=="ie" && cur2.filters.alpha.opacity<=min_fade) {
		slowhigh (cur2);
	} else if (window.highlighting) {
		clearInterval(highlighting);
	}
}

var rand = self.setInterval("randFace()",5000);
var last_rand = 1;
function randFace() {
	random_num = (Math.round((Math.random()*5)+1));
	while (random_num == last_rand) random_num = (Math.round((Math.random()*5)+1));
	last_rand = random_num;
	var face = document.getElementById('face_'+random_num);
	slowlow (face);
}

$(document).ready(function() {
	$('.nav').hover (function() {
		$(this).addClass('nav_hover');
	}, function() {
		$(this).removeClass('nav_hover');
	});
});