// Get query string data and set as page variables
var sData = new Array();
var sTemp;
var sQueryString = document.location.search.substr(1);
var doubles =  sQueryString.split("&");
for (var i = 0; i < doubles.length; i ++){
	sTemp = doubles[i].split("=");
	window[sTemp[0]] = sTemp[1];
}

// Set local domain (dynamically)
var myDomain="http://"+window.location.host;

// Member authentification - set cookie and send to members page (if cookie not present they will be denied access)
var ckie="";
if(document.cookie){
	ckie=document.cookie.substring(document.cookie.indexOf('member='),document.cookie.length);
}
if((window.location.pathname.toLowerCase().indexOf('memberpage')!='-1')&&(ckie!="member=OK")){
	document.location=myDomain+'/members.html';
}

// Members Login - change form action to send to test username/password
function login(){
	document.siteform.action="memberlogin.php";
	document.siteform.method="POST";
	document.siteform.submit();
}

// Image Pop-up (onclick) // Also used for gallery images
function popUp(page, winname, width, height, text ){
	var theWidth=(text!="")?width+20:width;
	var theScroll=(theWidth==width)?'no':'yes';
	var imageWindow=window.open('about:blank', winname, 'width='+theWidth+', height='+height+',scrollbars='+theScroll);
	imageWindow.document.write('<body style="padding:0px;margin:0px">');
	imageWindow.document.write('<img align="left" style="margin-right:10px;" src='+page+' border=0>');
	var theText="</body>";
	if(text) theText=(text!="")?'<div style="font-family:arial;font-size:11px;color:black;width:150px;padding:10px;">'+unescape(text)+'</div></body>':'</body>';
	imageWindow.document.write(unescape(theText));
	imageWindow.document.close();
}

// Image Rollovers
function chngImOver(image1, id){
	document.images[id].src="images/"+image1;
}

function chngImOut(image2, id){
	document.images[id].src="images/"+image2;
}

// Gallery - open large image window
function showIm(image){
	window.open("viewimage.html?image="+image, "_imageview");
}

// Gallery - Move through pages and re-populate the Gallery table
function chgIms(page){
	var siteurl = myDomain+"/images/";
	page = (page == '' || page == 'NULL' || !(page)) ? 0 : page;
	var totalpages=(theGallery.length%limit==0)?theGallery.length/limit:Math.floor(theGallery.length/limit)+1;
	for (i=0;i < limit ; i++){
		var arPos=page*limit+i;
		if(!theGallery[arPos]){
			document.all['space_'+i].innerHTML = '';
		}
		else{
			//document.all['space_'+i].innerHTML = '<a href="#" onclick="popUp(\''+siteurl+theGallery[arPos]['image_'+arPos+'_large']+'\',\'Gallery_image\','+theGallery[arPos]['image_'+arPos+'_width']+','+theGallery[arPos]['image_'+arPos+'_height']+',\''+theGallery[arPos]['image_'+arPos+'_text']+'\');return false;"><img src="'+siteurl+theGallery[arPos]['image_'+arPos+'_thumb']+'" border="0"></a>';		
			document.all['space_'+i].innerHTML = '<a href="#" onclick="popUp(\''+siteurl+theGallery[arPos]['large']+'\',\'Gallery_image\','+theGallery[arPos]['width']+','+theGallery[arPos]['height']+',\''+theGallery[arPos]['text']+'\');return false;"><img src="'+siteurl+theGallery[arPos]['thumb']+'" border="0"></a>';
		}
	}
	pagelinks = "<font face='arial' size='2'>Page </font>";
	for (k=1;k <= totalpages ;k++ ){
		var arraynum = k - 1;
		pagelinks += (arraynum == page) ? '<a onclick="chgIms('+arraynum+');return false;">['+k+']</a>&nbsp;&nbsp;' : '<a onclick="chgIms('+arraynum+');return false;">'+k+'</a>&nbsp;&nbsp;';
	}
	document.all.pages.innerHTML = pagelinks;
}