/*
var btnDisabled = 'Right mouse button disabled. Sorry.' 
*/
if (document.layers)  {
	window.captureEvents(Event.MOUSEDOWN)
}

document.onmousedown=enlargePic(e);

function enlargePic(e) {
	if(navigator.appName != 'Microsoft Internet Explorer') {
		var obj = e;
	} else {
		if(!isValidButton(e)) return;
		var obj = window.event.srcElement
	}

	if(obj.src) // make sure the click happened over an image
		openPic(getPath(obj.src), isPortrait(obj.id))
}


function isValidButton(e) {
	if(navigator.appName != 'Microsoft Internet Explorer')	// check mouse button event to try to make
	{																	//	a little more time consuming to
		if (e.which == 3) 											//	save pictures from the site
		{
			alert(btnDisabled);
			return false;
		}
//		alert('Sorry. Function currently available only for Internet Explorer');
		return false;
	}
	if (event.button == 2) 
	{
		alert(btnDisabled);
		return false;
	}
	return true;
}



function getPath(someValue)
{	//	gets the path based on 			/NUMBERS.jpg
	var pattern = /\/\d*\.jpg$/
//	return 'image' + pattern.exec(someValue);
	return 'large' + pattern.exec(someValue);
}	


function getNumber(someValue)
{	//	Get a number out without converting it to an integer data type (i.e., via parseInt())
	var pattern = /\d+/
	return pattern.exec(someValue);
}


function isPortrait(someValue)
{	//	A regexp check (used with value from img id, which includes "_p" if portrait)
	var pattern = /_p/
	return pattern.test(someValue)
}


function isOffSite(someValue)
{	//	Determines whether or not the images are stored in another location (i.e. on tripod)
/*	ORIGINAL RIGHT HERE
	var galleryCount = 10
	for(var i = 8; i <= galleryCount; i++)
	{
		var theGallery = 'Gallery' + i
		if(someValue.indexOf(theGallery) > -1)	// was originally 0; might have to change it back
			return true;
	}
	return false;						TO HERE */
	return false;	
}


function getOffSiteImage(theImage, theLocation)
{	//	Reconstructs the src for the image to an off-site location
	var patternStaging = /http:\/\/ggb7n01\//	//regular expressions for replace function
	var patternLive = /http:\/\/glscott\.net/
	var patternIndex = /index\.html/
			
	if(patternStaging.test(theLocation))
		theLocation = theLocation.replace(patternStaging, urlOffSite);
	else
		theLocation = theLocation.replace(patternLive, urlOffSite);
	
	theLocation = theLocation.replace(patternIndex, '');
	return theLocation + theImage
}


function openPic(path, isPortrait, caption)
{
	var theTitle = ''
	if(isPortrait) 
		OpenImageWin(path, 480, 640, caption, theTitle, isPortrait);
	else 
		OpenImageWin(path, 640, 480, caption, theTitle,  isPortrait);
}


function OpenImageWin(Picture, intWidth, intHeight, Caption, Title, isPortrait) 
{	
	if(!Title)
	{
		if(document.title != '')
			Title= document.title
		else
			Title='kingary.net'
	}
		
	if(Caption=='--Sony')
		Caption = ''
	var blnScroll = 0;

	if(isOffSite(window.location.href))
		Picture = getOffSiteImage(Picture, window.location.href)
	
	if(isPortrait) // aligning the picture window in the screen
		{var intLeft = 150; var intTop = 1}
	else
		{var intLeft = 57; var intTop = 37}
		
	if (navigator.appName == "Microsoft Internet Explorer")  
	{
		objWin = window.open("", "", "left="+ intLeft + ",top=" + intTop + ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=" + blnScroll + ",resizable=yes,copyhistory=no,width=" + intWidth + ",height=" + intHeight);
		with(objWin.document)
		{
			clear(); open();
			writeln('<html><head><title>' + Title + '</title><link rel="stylesheet" type="text/css" href="/assets/css/pic.css"><style>Img{cursor:hand;}</style></head><body bgcolor="#EFEFEF" onBlur="window.close();">' + writeLayer() + wrapLayer('<img id="theImage" src="' + Picture + '">') + '</body></html>')
			close();
		}
	}

	if(navigator.appName == "Netscape")  
	{
		intWidth+=100;
		intHeight+=150;

		objWin = window.open("", "", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=" + blnScroll + ",resizable=yes,width=20,height=20");
		objWin.moveTo(5,5)
		with(objWin.document)
		{
			clear();
	    		open();
			writeln('<html><head><title>' + Caption + '</title><style>Img{cursor:hand;}</style></head><body bgcolor="#666666"><img src="' + Picture + '"><p><b><font color=white>' + Caption + '</font></p></body></html>');
			close();
		}
		objWin.resizeTo(intWidth,intHeight)
	}
}


function writeLayer() {return '<div class="UploadMessage" id="layMess" onClick="window.close()">If the image fails to appear it means that the large version has not yet been uploaded.</div>'}

function wrapLayer(imageHTML) {return '<div class="PictureLayer" id="layPic" onClick="window.close();">' + imageHTML + '</div>'}