/**************************\
  GSSI Environment script
\**************************/

if (! GSSI) { var GSSI = new Object; };
if (! GSSI.Environment ) { GSSI.Environment = new Object(); };

GSSI.Environment._DOMHandlers = [];
GSSI.Environment._DOMFired = false;

GSSI.Environment.Agent = navigator.userAgent.toLowerCase();

GSSI.Environment.Browser = {  /* Browser sniffing based on Prototype's */
	IE:     !!(window.attachEvent && !window.opera),
	Opera:  !!window.opera,
	WebKit: GSSI.Environment.Agent.indexOf('applewebkit/') > -1,
	Gecko:  GSSI.Environment.Agent.indexOf('gecko') > -1 &&
			GSSI.Environment.Agent.indexOf('khtml') == -1
};

GSSI.Environment.Browser.IE6 = GSSI.Environment.Browser.IE && (GSSI.Environment.Agent.indexOf("msie 6")!=-1);
GSSI.Environment.Browser.IE7 = GSSI.Environment.Browser.IE && (GSSI.Environment.Agent.indexOf("msie 7")!=-1);

GSSI.Environment.OS = {
	Windows: GSSI.Environment.Agent.indexOf("win") != -1,
	Win2K:   GSSI.Environment.Agent.indexOf("windows nt 5.0") != -1,
	WinXP:   GSSI.Environment.Agent.indexOf("windows nt 5.1") != -1,
	Vista:   GSSI.Environment.Agent.indexOf("windows nt 6.0") != -1,
	Mac:     GSSI.Environment.Agent.indexOf("mac") != -1
};



GSSI.Environment.addClass = function ( node, name ){
	if(node) node.className = ((node.className || '') == '' ? '' : node.className + ' ') + name;
}

GSSI.Environment.withDOM = function () {
	GSSI.Environment._setup();
	GSSI.Environment._DOMFired = true;
	var f;
	for( var i=GSSI.Environment._DOMHandlers.length-1; i>=0; i-- ) {
		f = GSSI.Environment._DOMHandlers[i];
		if ( f ) { f(); };
		 GSSI.Environment._DOMHandlers[i] = null;
	}
}

GSSI.Environment.onDOMReady = function( func ) {
	if (GSSI.Environment._DOMFired) {
		if (func) { func(); }
		return;
	};
	
	GSSI.Environment._DOMHandlers.push( func );
}

GSSI.Environment._setup = function () {
	try {
		if ( GSSI.Environment.Browser.IE ) {
			GSSI.Environment.addClass( document.body, "ie" );
			if ( GSSI.Environment.Browser.IE6 ) {
				GSSI.Environment.addClass( document.body, "ie6" );
			} else if ( GSSI.Environment.Browser.IE7 ) {
				GSSI.Environment.addClass( document.body, "ie7" );
			}
		} else if ( GSSI.Environment.Browser.Gecko ) {
			GSSI.Environment.addClass( document.body, "gecko" );
		} else if ( GSSI.Environment.Browser.WebKit ) {
			GSSI.Environment.addClass( document.body, "webkit" );
		} else if ( GSSI.Environment.Browser.Opera ) {
			GSSI.Environment.addClass( document.body, "opera" );
		}
	
		if ( GSSI.Environment.OS.Windows ) {
			GSSI.Environment.addClass( document.documentElement, "win" );
			if ( GSSI.Environment.OS.WinXP ) {
				GSSI.Environment.addClass( document.documentElement, "winxp" );
			} else if ( GSSI.Environment.OS.Win2K ) {
				GSSI.Environment.addClass( document.documentElement, "win2k" );
			} else if ( GSSI.Environment.OS.Vista ) {
				GSSI.Environment.addClass( document.documentElement, "vista" );
			}
		} else if ( GSSI.Environment.OS.Mac ) {
			GSSI.Environment.addClass( document.documentElement, "mac" );
		}
	} catch (e) {}
};

/********************\
  Font resize script
\********************/

var GrouseMountain = {};

GrouseMountain.setTextSize = function ( size ) {
	size = 0 + size;
	document.getElementById("centercol").style.fontSize = size + "px";
	
	var sizestring = ('00' + size).slice(-2);
	
	var tsb = document.getElementById( 'textsizeblock' );
	if (tsb) {
		var allanchors = tsb.getElementsByTagName('A');
		for (var i=0; i<allanchors.length; i++) {
			allanchors[i].className = "";
		}
		document.getElementById( 'textsizeanchor_' + sizestring ).className = "current";
	}
	
	document.cookie = "fontsize=" + sizestring + "; path=/";
};

GrouseMountain.init = function () {
	var cookies = ' ' + document.cookie;
	
	var utilsblock = document.getElementById("utils");
	if (utilsblock) {
		utilsblock.innerHTML = utilsblock.innerHTML +
			'&nbsp;<span id="textsizeblock">\n'
		+	'   Text size:'
		+	'   <a id="textsizeanchor_10" style="font-size: 8px;" href="javascript:GrouseMountain.setTextSize(10)" class=""><span>A</span></a>&nbsp;\n'
		+	'   <a id="textsizeanchor_12" style="font-size: 11px;" href="javascript:GrouseMountain.setTextSize(12)" class=""><span>A</span></a>&nbsp;\n'
		+	'   <a id="textsizeanchor_14" style="font-size: 14px;" href="javascript:GrouseMountain.setTextSize(14)" class=""><span>A</span></a>\n'
		+	'</span>&nbsp;';
	}
	
	var at = cookies.indexOf( ' fontsize=' );
	GrouseMountain.rawTextSize = '10';
	if ( at >= 0 ) {
		GrouseMountain.rawTextSize = cookies.substr( at + 10, 2 ); // always 2 digits	
	}

	GrouseMountain.setTextSize(parseInt(GrouseMountain.rawTextSize));
};

GSSI.Environment.onDOMReady(GrouseMountain.init);

/************************\
  OnDOMReady incantation
\************************/

do {
	/* Internet Explorer */
	/*@cc_on @*/
	/*@if (@_win32)
		if ( window.location.protocol != "https:" ) {
			document.write("<sc" + "ript id='__ie_gssi_observeDOMReady' defer='defer' src='javascript:void(0);'><\/sc" + "ript>");
			GSSI.Environment.DOMReadyBrowserDevice = document.getElementById("__ie_gssi_observeDOMReady");
			GSSI.Environment.DOMReadyBrowserDevice.onreadystatechange = function() {
				if (this.readyState == "complete") {
					GSSI.Environment.withDOM(); // call the onload handler
				}
			};
			break;
		}
	/*@end @*/
	
	/* Safari/Konqueror */
	/* WebKit must be tested for before DOM2 standard because WebKit supports document.addEventListener but NOT the 
	   DOMContentLoaded event. */
	if (/WebKit/i.test(navigator.userAgent)) { 
		GSSI.Environment.DOMReadyBrowserDevice = setInterval(function() {
			if (/loaded|complete/.test(document.readyState)) {
				clearInterval(GSSI.Environment.DOMReadyBrowserDevice);
				GSSI.Environment.withDOM(); 
			}
		}, 10);
		break;
	}
	
	/* Mozilla/Opera9/DOM2 Compliant browsers */
	if (document.addEventListener) {
		document.addEventListener("DOMContentLoaded", GSSI.Environment.withDOM, false);
		break;
	}

	/* Anything else */
	if (window.addEventListener) {
		window.addEventListener("load", GSSI.Environment.withDOM, false);
	} else if(window.attachEvent) {
		window.attachEvent("onload", GSSI.Environment.withDOM);
	}

} while(0);


/*******\
  NIFTI
\*******/

/*if (window.IsSummer) {*/
	NIFTI.init( "/images/nifti/nifti.ashx",
		".summer h1 .section ",
		".summer h1 .subsection ",
		".summer .contentpage h2 ",
		".summer .eventpage h1 ",
		".summer .eventpage h2 ",
		".summer #events .contentcol h3 a ",
		".summer #events .contentcol h3 a:hover ",
		".summer #events .eventswitch a ",
		".summer #events .eventswitch a:hover ",
		".summer #events .eventswitch span ",
		".summer .linkblock h3 a ",
		".summer .featureblock h3 a "
		);
		NIFTI.init( "/images/nifti/nifti.ashx",
		".winter h1 .section ",
		".winter h1 .subsection ",
		".winter .contentpage h2 ",
		".winter .eventpage h1 ",
		".winter .eventpage h2 ",
		".winter #events .contentcol h3 a ",
		".winter #events .contentcol h3 a:hover ",
		".winter #events .eventswitch a ",
		".winter #events .eventswitch a:hover ",
		".winter #events .eventswitch span ",
		".winter .linkblock h3 a ",
		".winter .featureblock h3 a "
	);
		
	
/*} else {
	
}*/

/***********/


GrouseMountain.formatNumber = function ( number, digits ) {
	var s = "0000000000" + number.toString();
	return s.substr(s.length - digits);
}

GrouseMountain.writeDate = function (datestr) {
	var d = new Date();
	d.setTime(Date.parse(datestr));
	document.write( GrouseMountain.formatNumber(d.getDate(), 2) + '.' + GrouseMountain.formatNumber((d.getMonth()+1), 2) + '.' + GrouseMountain.formatNumber(d.getYear(), 2));
}

GrouseMountain.popUp = function (url) {
	id = "gm" + (new Date()).getTime() + "_" + Math.floor(Math.random() * 1000);
	window.open(url, id, 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,scrollbars=1,width=686,height=470,left = 297,top = 277');
}
GrouseMountain.popUpMusic = function ( season ) {
	season = (season || "winter").toString().toLowerCase();
	id = "gmm" + (new Date()).getTime() + "_" + Math.floor(Math.random() * 1000);
	window.open(("/mp3player/"+season+".htm"), id, 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,scrollbars=1,width=260,height=246,left=297,top=277');
}
GrouseMountain.popUpRequest = function (url) {
	id = "gmr" + (new Date()).getTime() + "_" + Math.floor(Math.random() * 1000);
	window.open(url, id, 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,scrollbars=1,width=460,height=500,left = 297,top = 277');
}
GrouseMountain.popUpSubscribe = function (url) {
	id = "gms" + (new Date()).getTime() + "_" + Math.floor(Math.random() * 1000);
	window.open(url, id, 'toolbar=0,scrollbars=1,location=1,statusbar=0,menubar=1,resizable=1,scrollbars=1,width=674,height=696,left=297,top=277');
}