var SearchOptionPanels = new Array('galleryFilter');
var PaddingTop_NormalPage = 337; /* Set top padding size for normal pages here */
var PaddingTop_GalleryPage = 141; /* Set top padding size for gallery pages here */
var HeaderScrollStatus; /* Records the scrolling mode of the header, ie Fixed or Scrolling */

//Prevent right mouse clicks
//if (document.layers) 
//{
//	document.captureEvents(Event.MOUSEDOWN);
//}
//document.onmousedown=nrclick;

function scrollWindow(ScrollPos)	
{
	var ScrollPos_Final;
	
//	alert (HeaderScrollStatus);
	
	// Check for normal page / gallery page and foxed header / scrolling header
	switch (HeaderScrollStatus)
	{
		case "NP_FH":
			ScrollPos_Final = ScrollPos;
			break;
		case "NP_SH":
			ScrollPos_Final = ScrollPos + PaddingTop_NormalPage;
			break;
		case "GP_FH":
			ScrollPos_Final = ScrollPos;
			break;
		case "GP_SH":
			ScrollPos_Final = ScrollPos + PaddingTop_GalleryPage;
			break;
	}
	
//	alert(ScrollPos_Final);
	scroll(0,ScrollPos_Final);
	
}

function galleryOptionsClick(ItemName)
{

	// Close open panels other than the one clicked on
//	for (var i = 0; i < SearchOptionPanels.length; i++)
//	{
//		// Ignore current open tab
//		if (SearchOptionPanels[i] != ItemName)
//		{
//			document.getElementById(SearchOptionPanels[i] + "Panel").style.display = "none";
//			document.getElementById(SearchOptionPanels[i] + "Arrow").src = document.getElementById(SearchOptionPanels[i] + "Arrow").src.replace(/clicked-hover/, 'default');
//			document.getElementById(SearchOptionPanels[i] + "Image").src = document.getElementById(SearchOptionPanels[i] + "Image").src.replace(/hover/, 'default');
//		}
//	}

	// Toggle current panel
	if ((document.getElementById(ItemName + "Panel").style.display == "block") || (document.getElementById(ItemName + "Panel").style.display == ""))
	{
		document.getElementById(ItemName + "Panel").style.display = "none";
		document.getElementById(ItemName + "Image").style.background = "url(images/" + "gallery-filter-show-hover.png" + ") no-repeat"
//		document.getElementById(ItemName + "Image").src = document.getElementById(ItemName + "Image").src.replace(/hide/, 'show');
		//show filter status summary
//		document.getElementById("galleryPageTitleFilter").style.display = "block";
	}
	else
	{
		document.getElementById(ItemName + "Panel").style.display = "block";
		document.getElementById(ItemName + "Image").style.background = "url(images/" + "gallery-filter-hide-hover.png" + ") no-repeat"
//		document.getElementById(ItemName + "Image").src = document.getElementById(ItemName + "Image").src.replace(/show/, 'hide');
		//hide filter status summary
//		document.getElementById("galleryPageTitleFilter").style.display = "none";
	}

}

function galleryFormatTooltipShow(ItemName)
{
		document.getElementById(ItemName).style.display = "block";
}

function galleryFormatTooltipHide(ItemName)
{
		document.getElementById(ItemName).style.display = "none";
}

function galleryOptionsHover(bShowHover)
{

	if ((document.getElementById("galleryFilterPanel").style.display == "block") || (document.getElementById("galleryFilterPanel").style.display == ""))
	{
		if (bShowHover == 1)
		{
			document.getElementById("galleryFilterImage").style.background = "url(images/" + "gallery-filter-hide-hover.png" + ") no-repeat"
		}
		else
		{
			document.getElementById("galleryFilterImage").style.background = "url(images/" + "gallery-filter-hide-default.png" + ") no-repeat"
		}
	}
	else
	{
		if (bShowHover == 1)
		{
			document.getElementById("galleryFilterImage").style.background = "url(images/" + "gallery-filter-show-hover.png" + ") no-repeat"
		}
		else
		{
			document.getElementById("galleryFilterImage").style.background = "url(images/" + "gallery-filter-show-default.png" + ") no-repeat"
		}
	}

}

function gallerySearchImageSwap(ID)
{

	if (document.getElementById(ID).src.match('small-bw') == "small-bw")
	{
		document.getElementById(ID).src = document.getElementById(ID).src.replace(/small-bw/, 'small')
	}
	else
	{
		document.getElementById(ID).src = document.getElementById(ID).src.replace(/small/, 'small-bw')
	}

}
function gallerySearchImageColour(ID)
{

	if (document.getElementById(ID).src.match('small-bw') == "small-bw")
	{
		document.getElementById(ID).src = document.getElementById(ID).src.replace(/small-bw/, 'small')
	}

}
function gallerySearchImageBW(ID, chkSelect)
{

	if (document.getElementById(ID).src.match('small/') == "small/")
	{
	   if (document.getElementById(chkSelect).checked == false)
	   {
		   document.getElementById(ID).src = document.getElementById(ID).src.replace(/small/, 'small-bw')
		}
	}

}

function galleryImageBGSwap(ID)
{
	var imgPath = new String();
	imgPath = document.getElementById(ID).style.background;
	document.getElementById(ID).gets
//	alert(document.getElementById(ID).id);
	alert(imgPath);
	return;

	if (document.getElementById(ID).style.backgroundImage.match('default') == "default")
	{
		document.getElementById(ID).style.backgroundImage = document.getElementById(ID).src.replace(/default/, 'hover')
	}
	else
	{
		document.getElementById(ID).style.backgroundImage = document.getElementById(ID).src.replace(/hover/, 'default')
	}

}

function galleryImageViewOver(ID)
{

	document.getElementById(ID).style.background = "url(images/gallery-image-back-hover.jpg) no-repeat"

}

function galleryImageViewOut(ID)
{

	document.getElementById(ID).style.background = "url(images/gallery-image-back-default.jpg) no-repeat"

}

function galleryImageBuyViewOver(ID)
{

	document.getElementById(ID).style.background = "url(images/gallery-image-buy-back-hover.jpg) no-repeat"

}

function galleryImageBuyViewOut(ID)
{

	document.getElementById(ID).style.background = "url(images/gallery-image-buy-back-default.jpg) no-repeat"

}

function galleryImageBuyOver(ID)
{

	document.getElementById(ID).style.background = "url(images/gallery-image-back-buy.jpg) no-repeat"

}

function galleryImageBuyOut(ID)
{

	document.getElementById(ID).style.background = "url(images/gallery-image-back-default.jpg) no-repeat"

}

function galleryImageZoomOver(ID)
{

	document.getElementById(ID).style.background = "url(images/gallery-image-back-zoom.jpg) no-repeat"

}

function galleryImageZoomOut(ID)
{

	document.getElementById(ID).style.background = "url(images/gallery-image-back-default.jpg) no-repeat"

}

function galleryImageSwap(ID)
{

	if (document.getElementById(ID).src.match('default') == "default")
	{
		document.getElementById(ID).src = document.getElementById(ID).src.replace(/default/, 'hover')
	}
	else
	{
		document.getElementById(ID).src = document.getElementById(ID).src.replace(/hover/, 'default')
	}

}

function SwapBackground (ID, ImgSrc)
{

	document.getElementById(ID).style.background = "url(images/" + ImgSrc + ") no-repeat"

}

function checkClientSize()
{

	//Check for window size below 768px high
	if ((getClientHeight() <= 600) || (getClientWidth() <= 1024))
	{
//	alert (getClientWidth());
//	alert (getClientHeight());
		document.getElementById("header_container").style.position = "relative";
		if (document.getElementById("content_container") != undefined)
		{
			document.getElementById("content_container").style.paddingTop = "0px";
			HeaderScrollStatus = "NP_SH";
		}
		else
		{
			document.getElementById("content_container_gallery").style.paddingTop = "0px";
			HeaderScrollStatus = "GP_SH";
		}
//		document.getElementById("headerlogo-container").style.position = "relative";
//		document.getElementById("headerlogo-container").style.textAlign = "relative";
//		document.getElementById("headerlogo-container").style.paddingLeft = 206;
	}
	else
	{
		if (document.getElementById("content_container") != undefined)
		{
			// Check for IE6
			if (navigator.appVersion.match("MSIE 6.0") == "MSIE 6.0")
			{
				HeaderScrollStatus = "NP_SH";
			}
			else
			{
				HeaderScrollStatus = "NP_FH";
			}
		}
		else
		{
			// Check for IE6
			if (navigator.appVersion.match("MSIE 6.0") == "MSIE 6.0")
			{
				HeaderScrollStatus = "GP_SH";
			}
			else
			{
				HeaderScrollStatus = "GP_FH";
			}
		}
	}

}

function getClientWidth()
{
	
	var w;

	if(document.innerWidth)
	{
		w=document.innerWidth;
	} 
	else if(document.documentElement.clientWidth)
	{
		w=document.documentElement.clientWidth;
	} 
	else if(document.body)
	{
		w=document.body.clientWidth; 
	}
	
	return w;
	
}
function getClientHeight()
{

	var h;
	
	if(document.innerHeight)
	{
		h=document.innerHeight;
	} 
	else if(document.documentElement.clientHeight)
	{
		h=document.documentElement.clientHeight;
	} 
	else if(document.body)
	{
		h=document.body.clientHeight; 
	}
	
	return h;
	
}

function DisplayImage1(imgSrc, imgAlt, imgWidth, imgHeight, imgLink, linkTarget, imgClass) 
{

	document.write("<div id='imgBox' style='width:" + (imgWidth + 10) + "px;' class='" + imgClass + "' >");
	document.write("	<div id='imgBox_1'><a href='" + imgLink + "' target='" + linkTarget + "'><img src='" + imgSrc + "' alt='" + imgAlt + "' border='0' /></a></div>");
   document.write("  <div id='imgBox_2' style='margin-left:" + (imgWidth - 4) + "px;margin-top:-" + imgHeight + "px;'><img src='images/is-tr.png' width='14px' height='14px' border='0' /><br/><img src='images/is-r.png' width='14px' height='" + (imgHeight - 19) + "px' border='0' /><br/><img src='images/is-br.png' width='14px' height='14px' border='0' /></div>");
   document.write("  <div id='imgBox_3' style='margin-top:-14px;'><img src='images/is-bl.png' width='14px' height='14px' border='0' /><img src='images/is-b.png' width='" + (imgWidth - 18) + "px' height='14px' border='0' /></div>");
   document.write("  <div id='imgBox_4' style='margin-top:-" + (imgHeight + 9) + "px;'><img src='images/is-tl.png' width='14px' height='14px' border='0' /><img src='images/is-t.png' width='" + (imgWidth - 18) + "px' height='14px' border='0' /></div>");
   document.write("  <div id='imgBox_5' ><img src='images/is-l.png' width='14px' height='" + (imgHeight - 19) + "px' border='0' /></div>");
	document.write("</div>");

}

// function to return a named page viable from the Querystring
function getQueryVariable(variable) 
{  

	var query = window.location.search.substring(1);  
	var vars = query.split("&");  
	
	for (var i=0;i<vars.length;i++) {    
		var pair = vars[i].split("=");    
		if (pair[0] == variable) {      
			return pair[1];    
		}  
	}   

	return "x";

}

function DisplayEmailLink1 () {
	document.write("<a href='mailto:");
	document.write("madcat@");
	document.write("madcat.com.au");
	document.write("'>");
	document.write("madcat@");
	document.write("madcat.com.au");
	document.write("</a>");
}

function DisplayEmailLink2 () {
	document.write("<a href='mailto:");
	document.write("dave@");
	document.write("madcat.com.au");
	document.write("'>");
	document.write("Email: ");
	document.write("dave@");
	document.write("madcat.com.au");
	document.write("</a>");
}

function DisplayEmailLink3 () {
	document.write("<a href='mailto:");
	document.write("maggie@");
	document.write("madcat.com.au");
	document.write("'>");
	document.write("Email: ");
	document.write("maggie@");
	document.write("madcat.com.au");
	document.write("</a>");
}

function DisplayEmailLink4 () {
	document.write("<a href='mailto:");
	document.write("remove@");
	document.write("madcat.com.au");
	document.write("?subject=Unsubscribe");
	document.write("'>");
	document.write("remove@");
	document.write("madcat.com.au");
	document.write("</a>");
}

function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}
function checkEmail()
{
   if (document.getElementById("txtSubscribeName").value == "")
   {
      alert("You must enter your name");
      return false;
   }
   if (document.getElementById("txtSubscribeEmail").value == "")
   {
      alert("You must enter your email address");
      return false;
   }
   return true;
}
function checkComment()
{
   if (document.getElementById("txtFirstName").value == "")
   {
      alert("You must enter your name");
      return false;
   }
   if (document.getElementById("txtEmail").value == "")
   {
      alert("You must enter your email address");
      return false;
   }
   if (document.getElementById("txtComments").value == "")
   {
      alert("Please enter your comment");
      return false;
   }
   return true;
}

// Prevent right clicks 
function nrclick(e)
{
	var sMsg = "All images on this web site are Copyright Dave Catley, please contact us or visit our stock library if you wish to license our images. Thank you";
	
	if (document.all) 
	{
		if (event.button == 2) 
		{
			alert(sMsg);
			return false;
		}
	}
	if (document.layers) 
	{
		if (e.which == 3) 
		{
			alert(sMsg);
			return false;
		}
	}
}

function TextboxEntertoSubmit(event, sSubmitButtonName)
{

	if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13))
	{
	   document.getElementById(sSubmitButtonName).click();
		return false;
	} 
	else return true;

}