var curWidth = 1;
var curHeight = 1;
var curLeft = 500;
var bandOpac = 0;
var bandFiltOpac = 0;
var bandFadeIn = true;
//Speed of gallery pix sizing
var thespeed = 20;
var ztoday = new Date();
var zyear = ztoday.getFullYear();
var zcopyrighttext = "All content &copy; " + zyear + " <a href=\"http://www.nextexitproductions.net/contact/contact-emailform.php\" target=\"_blank\">Andrew Robinson</a> | Site designed by <a href=\"http://www.12gaugechicken.com/contact/contact.php\" target=\"_blank\">Greg DiGenti</a> with help from <a href=\"http://templates.arcsin.se\">Arcsin</a>.";

//////////////////////////////////////////////////////////////////////////////////////
////// These arrays keep track of all of the big versions in image galleries ////////
var infoTracker = 0; //for holding onto the number of the image for cycling
var theImages = new Array(); 
var theWidths = new Array();
var theHeights = new Array(); 
var theHeaders = new Array(); 
var theDescriptions = new Array();
//////////////////////////////////////////////////////////////////////////////////////

///// Makes band in header fade in
function header_fade(){
	var band_div = document.getElementById('the_band');
	if(bandFadeIn==true && bandFiltOpac<100){
		band_div.style.filter = 'alpha(opacity=' + bandFiltOpac + ')';
		band_div.style.opacity = bandOpac;
		setTimeout('header_fade()',1);
		bandFiltOpac+=.5;
		bandOpac+=.005;
	}else{
		bandFadeIn=false;
		band_div.style.filter = 'alpha(opacity=' + 100 + ')';
		band_div.style.opacity = 1;
	}
}

// Gets the page size
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less than height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function paypalButton(item_name,amount){
var paypal_text = "<form name=\"_xclick\" target=\"paypal\" action=\"https://www.paypal.com\" method=\"post\"><input type=\"hidden\" name=\"cmd\" value=\"_cart\"><input type=\"hidden\" name=\"business\" value=\"" + email1 + "@" + email2 + "\"><input type=\"hidden\" name=\"currency_code\" value=\"USD\"><input type=\"hidden\" name=\"item_name\" value=\"" + item_name + "\"><input type=\"hidden\" name=\"amount\" value=\"" + amount  + "\"><input type=\"hidden\" name=\"on0\" value=\"Shipping\"><input type=\"hidden\" name=\"os0\" value=\"Please add $5 to the total for shipping within the US, and $10 outside the US.\"><input type=\"image\" src=\"../images/add-to-cart.gif\" border=\"0\" name=\"submit\" alt=\"Make payments with PayPal - it's fast, free and secure!\"><input type=\"hidden\" name=\"add\" value=\"1\"></form>";
}

//prepares the larger version of the image to be opened
function openbigimage(zNumber){
	var arrayPageSize = getPageSize();
	var objOverlay = document.getElementById('grayoutbox');
	var photoHolder = document.getElementById('imageBox');
	infoTracker = zNumber;
	//scroll(0,0);
	curImage = theImages[infoTracker];
	destWidth = theWidths[infoTracker];
	destHeight = theHeights[infoTracker];
	curHeader = theHeaders[infoTracker] + " ... [Image " + (infoTracker + 1) + " of " + (theImages.length + 1) + "]";
	curDescript = theDescriptions[infoTracker];
	scrollTo = (window.pageYOffset - 330);
	keepGrowingWide = true;
	keepGrowingTall = true;
	zbuttons = "<div id=\"imageButtons\"><a href=\"javascript:cycleImage('back')\" class=\"backLink\" onmouseover=\"showButtons()\"></a><a href=\"javascript:cycleImage('next')\" class=\"nextLink\" onmouseover=\"showButtons()\"></a></div>";
	headerAndDescript = "<p><em class=\"hdr\">" + curHeader + "</em><br />" + curDescript + "</p>";
	zhtml = "<a href=\"javascript:closebox()\" onmouseover=\"showButtons()\" title=\"Click to close image\"><img src=\"images/" + curImage + "\" id=\"boxid\" width=\"1\" height=\"1\" border=\"0\" alt=\"\" /></a>";
	photoHolder.style.visibility = "visible";
	photoHolder.innerHTML = (zbuttons + zhtml + headerAndDescript);
	photoHolder.style.top = (scrollTo + 'px');
	objOverlay.style.visibility = 'visible';
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	boxGrow();
}

///// Makes box grow
function boxGrow(){
	if(keepGrowingWide == true || keepGrowingTall == true){
		if(curWidth <= destWidth){
			document.getElementById('boxid').style.width = curWidth+"px";
			curWidth+=thespeed;
		}else{
			document.getElementById('boxid').style.width = destWidth+"px";
			keepGrowingWide = false;
		}
		if(curHeight <= destHeight){
			document.getElementById('boxid').style.height = curHeight+"px";
			curHeight+=thespeed;
		}else{
			document.getElementById('boxid').style.height = destHeight+"px";
			keepGrowingTall = false;
		}
	setTimeout('boxGrow()',1);
	}else{
		curWidth = 1;
		curHeight = 1;
		destWidth = 0;
		destHeight = 0;
		curTop = 0;
		keepGrowingWide = false;
		keepGrowingTall = false;
	}
}

//closes big image
function closebox(){
	document.getElementById('imageBox').style.visibility = "hidden";
	document.getElementById('imageBox').innerHTML = "";
	document.getElementById('grayoutbox').style.height = '50%';
	document.getElementById('grayoutbox').style.visibility = 'hidden';
	//scroll(0,scrollTo);
}

//shows buttons for enlarged images
function showButtons(){
	document.getElementById('imageButtons').style.visibility = "visible";
}

//hides buttons for enlarged images
function hideButtons(){
	document.getElementById('imageButtons').style.visibility = "hidden";
}

//Adjusts the infoTracker number, then runs the openbigimage function again
function cycleImage(zDirection){
picHolder = document.getElementById('movieBox');
imageBox = document.getElementById('boxid');
	for(i=0;i<theImages.length;i++){
		zz=i;
		if(theImages[zz]==curImage){
		infoTracker = zz;
		}
	}
	if(zDirection=='next'){
		infoTracker++;
	}else{
		infoTracker--;
	}
	if(infoTracker==theImages.length){
		infoTracker=0;
	}else if(infoTracker<0){
		infoTracker=theImages.length-1;
	}
openbigimage(infoTracker);
}
