// <![CDATA[

/* THIS SCRIPT IS USED IN ALL OF MY GALLERIES */
/* This script is dependedent upon gallery_style1.css */
/* ©2007 Scott Murray, all rights reserved */


//keep this page out of frames
   if(top.location != self.location) {
	  top.location = self.location;
}


//display message (msg) in status bar
	function setMsg (msg){
		window.status = msg
		return true
}

//display info in status bar
function showStatusIndexPage() {
	setMsg('Welcome.  Click on the image to enter the site.');
	return true;
	}
	
//display info in status bar
function showStatusHomePage() {
	setMsg('Click on a gallery thumbnail to go to that gallery.');
	return true;
	}	
	
//display info in status bar
function showStatusGalleryPage() {
	setMsg('Mouse over a thumbnail image to see a larger version displayed.');
	return true;
	}





// gets the width and height of the current window
// returns and array [winWidth, winHeight]
// *** have not tested with Safari ***
function getWindowWH () {
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			winWidth = window.innerWidth;
			winHeight = window.innerHeight;
		}
		if (navigator.appName=="Opera") {
			winWidth = window.innerWidth;
			winHeight = window.innerHeight;
		}
		if (navigator.appName=="Safari") {
			winWidth = window.innerWidth;
			winHeight = window.innerHeight;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			//winHeight = document.body.offsetHeight;
			//winWidth = document.body.offsetWidth;
			if(self.innerWidth!=undefined) {
				winWidth = self.innerWidth;
				winHeight = self.innerHeight;
				}
			else {
				d = document.documentElement;
				if(d) {
					winWidth = d.clientWidth;
					winHeight = d.clientHeight;
				}
			}
		}
	}
	 return [winWidth, winHeight];
}




// style sheet is set up for screens at least 780x700 
// on these screens gallery is centered horizontally and vertically.
// this function handles smaller screens and prevents cropping due to margins offsets.
// this pegs the logo in upper left on small screens and centers the page on bigger ones
// *** this is dependent upon values in gallery_style1.css ***
// this is called by onLoad() and onResize()
// this only works if entire html content is wrapped in: <div class='centered-content'></div>
// 
function smallScreenHandler (){

	WindowWH = getWindowWH ();
	winWidth = WindowWH[0];
	winHeight = WindowWH[1];

	cc = document.getElementById('centered-content');


	// adjust positioning for very small screens (at origin vs centered)
	// handle width, height changes
	// values of cc (390, 350) are from gallery_style1.css file
	if ( (winWidth < 780) ) {
		cc.style.left = '390px'; 
		cc.style.marginleft = '0px';    /* always 0 that what this does*/
	}
	else {
		//reset to style sheet default values
		cc.style.left = '50%';
		cc.style.marginleft = '-390px';
	}

	// adjust positioning for very small screens (at origin vs centered)
	// handle height changes
	if  (winHeight < 680) {
		cc.style.top = '350px';
		cc.style.margintop = '0px';     /* always 0 for small screens */
	}

	else {
		//reset to style sheet default values
		cc.style.top = '50%';
		cc.style.margintop =  '-350px';
	} /**/
	return true;
}


// called by Gallery Pages' onLoad
// The browser triggers onLoad when the document is finished loading
function initGalleryPage(){
	showStatusGalleryPage();	/* give users welcome and instructions */
	smallScreenHandler();	/* prevent cropping due to small screens */
	cacheBigImages(); 	/* call onLoad to speed painting of display */
	return true;
}

// called by Index Page onLoad
// The browser triggers onLoad when the document is finished loading
function initIndexPage(){
	showStatusIndexPage();	/* give users welcome and instructions */
	smallScreenHandler();	/* prevent cropping due to small screens */
	return true;
}

// called by Home Page onLoad
// The browser triggers onLoad when the document is finished loading
function initHomePage(){
	showStatusHomePage();	/* give users welcome and instructions */
	smallScreenHandler();	/* prevent cropping due to small screens */
	return true;
}

// called by onLoad
// The browser triggers onLoad when the document is finished loading
function init(){
	smallScreenHandler();	/* prevent cropping due to small screens */
	return true;
}

// handle resize events
// note - in the registration of an event handler you do not use brackets ()
window.onresize = smallScreenHandler;


// ]]>

