function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function getImageName(cString){
// the string includes several slashes. I want the last string
	var nLen;
	aStrings=new Array;
	aStrings=cString.split("/");
	nLen=aStrings.length;
	imageName =aStrings[nLen-1]; //base 0
	return imageName
}

function getImagePath(cString){
// the string includes several slashes. I want the last string
	var nLen;
	aStrings=new Array;
	aStrings=cString.split("/");
	nLen=aStrings.length;	
	imagePath = '';
	if (aStrings[0] != 'images') {
		imagePath = 'images/'		
	}
	for(i=0; i < nLen - 1; i++)
	{
		
		imagePath = imagePath + aStrings[i] + "/";
	}
	return imagePath
}

function openStockWindow(src,nWidth,nHeight,cMsg, detailSrc, detailWidth, detailHeight){
	var cPict;
	var cWindow;
	var stats;
	var objwin;
	var cButton;
	var cString;
	
	// get the name of the new picture, from the src remove the sm prefix
	cPict=getImageName(src);	
	imagePath = getImagePath(src);
	cPict=cPict.substr(2,cPict.length-1)
	// get the .jpg ending
	cWindow=cPict.substr(0,cPict.length-4)	
	// add to width and height so that close button can be seen and no scrollbars appear
	totalWidth = parseInt(nWidth)+ 50;
	totalHeight = parseInt(nHeight) + 130;	
	stats="toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,Top=0";
	stats+=",resizable=yes,width="+totalWidth+",height="+totalHeight;	
	objwin=window.open("",cWindow,stats);	
	objwin.document.write("<html>");
	objwin.document.write("<head><title>Gareth McCormack Photography - "+cWindow+"</title></head>");
	//objwin.document.write("<script language='Javascript' src='openWindow.js'></script>");
	descript = '<script>function swapImage(originalImgSrc, detailImgSrc ) { aStrings=new Array;	aStrings=document.images["deImage"].src.split("/"); nLen=aStrings.length;	currentImg = aStrings[nLen-1]; if (currentImg != detailImgSrc)document.images["deImage"].src = "images/"+detailImgSrc; else document.images["deImage"].src= "images/"+ originalImgSrc;	}</script>';
	objwin.document.write(descript);
	objwin.document.write("<body bgcolor='#ffffff' readonly='true'>");
	objwin.document.write("<center>");
	cString="<img id='deImage' border='0' src='"+imagePath+cPict+"'>";
	if (detailSrc != '' && detailSrc != null) {
	  cString="<a border='0' href='javascript:swapImage(\""+ cPict +"\", \""+detailSrc+"\")'><img id='deImage' border='0' oncontextmenu='return false;'src='"+imagePath+cPict+"'></a>";
	}
	objwin.document.write(cString);
	objwin.document.write("<br/>");
	objwin.document.write("<br/>");
	objwin.document.write ("<font face=verdana size=2>"+cMsg+"</font><br/>");
	objwin.document.write("<br/>");
	cButton="<input type='button' value='Close' onClick='window.close()'>"
	
	objwin.document.write(cButton);
	if (detailSrc != '' && detailSrc != null) {
	  objwin.document.write ("<br/><br/><font face=verdana size=1>Click image to alternate between fine detail and full print</font><br/>");
	}
	objwin.document.write("</center>");
	objwin.document.write("</body>");
	objwin.document.write("</html>");
	objwin.document.close();
}




function openDetailWindow(src,nWidth,nHeight,cMsg, detailSrc, detailWidth, detailHeight){
	var cPict;
	var cWindow;
	var stats;
	var objwin;
	var cButton;
	var cString;
	
	// get the name of the new picture, from the src remove the sm prefix
	cPict=getImageName(src);	
	imagePath = getImagePath(src);
	cPict=cPict.substr(2,cPict.length-1)
	// get the .jpg ending
	cWindow=cPict.substr(0,cPict.length-4)	
	// add to width and height so that close button can be seen and no scrollbars appear
	totalWidth = parseInt(nWidth)+ 180;
	totalHeight = parseInt(nHeight) + 290;	
	stats="toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,Top=0";
	stats+=",resizable=yes,width="+totalWidth+",height="+totalHeight;
	// get the class of image, portrait, landscape, panorama
	ratio = nWidth/nHeight;	
	imageClass = 'imageBoxLandscapeStyleLarge';
	if (ratio < 1) {
	  imageClass = 'imageBoxPortraitStyleLarge';
	} else if (ratio > 2) {
	  imageClass = 'imageBoxPanoramaStyleLarge';
	}
	objwin=window.open("",cWindow,stats);
	objwin.document.write("<html>");
	objwin.document.write("<head><title>Gareth McCormack Photography - "+cWindow+"</title><link rel='stylesheet' href='stylesheet.css'></head>");
	//objwin.document.write("<script language='Javascript' src='openWindow.js'></script>");
	descript = '<script> \
	function swapImage(originalImgSrc, detailImgSrc, imageClass ) \
	{ \
	  aStrings=new Array; \
	  aStrings=document.images["deImage"].src.split("/"); \
	  nLen=aStrings.length;	\
	  currentImg = aStrings[nLen-1]; \
	  if (currentImg != detailImgSrc) {\
		document.images["deImage"].src = "images/"+detailImgSrc; \
		document.getElementById("imagebox").setAttribute("className", ""); \
		document.getElementById("imagebox").setAttribute("class", ""); \
	  } else { \
		document.images["deImage"].src= "images/"+ originalImgSrc;	\
		document.getElementById("imagebox").setAttribute("className", imageClass); \
		document.getElementById("imagebox").setAttribute("class", imageClass);\
	  } \
	} 	</script>';
	objwin.document.write(descript);
	objwin.document.write("<body bgcolor='#ffffff' readonly='true'>");
	objwin.document.write("<center>");	
	objwin.document.write("<table  border='0'cellpadding='70'><tr><td id='imagebox' class='"+imageClass+"' align='center'>");
	
	cString="<img id='deImage' border='10' style='border-color:#eeeeee' oncontextmenu='return false;'src='"+imagePath+cPict+"'>";
	if (detailSrc != '' && detailSrc != null) {
	  cString="<a border='0' href='javascript:swapImage(\""+ cPict +"\", \""+detailSrc+"\", \""+imageClass+"\")'><img id='deImage' border='10' style='border-color:#eeeeee' oncontextmenu='return false;'src='"+imagePath+cPict+"'></a>";
	}
	objwin.document.write(cString);
	objwin.document.write("</td></tr></table>");
	objwin.document.write ("<font face=verdana size=2><b>"+cMsg+"</b></font><br/>");
	objwin.document.write("<br/>");
	cButton="<input type='button' value='Close' onClick='window.close()'>"
	
	objwin.document.write(cButton);
	if (detailSrc != '' && detailSrc != null) {
	  objwin.document.write ("<br/><br/><font face=verdana size=2>Click image to alternate between fine detail and full print</font><br/>");
	}
	objwin.document.write('<p class="smallText">Frame added for display purposes only – watermark will not appear on print.</p>');
	objwin.document.write("</center>");
	objwin.document.write("</body>");
	objwin.document.write("</html>");
	objwin.document.close();
}


function openWindow(url, width, height)
{
	try {		
		if (width == null) width = 480;
		if (height == null) height = 640;
		var w = window.open (url, "win", "height="+height+",width="+width+",location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no");
	}
	catch(e) {
		alert(e);
	}
}






