var storyInfoIsVisible=0;
var galleryViewPointer = 0;
var nextImageButState;
var previousImageButState;
var infoScrollUp = 0;
var infoScrollDown =0;
var fader;



function showGalleryInfo(){
	if(storyInfoIsVisible == 0){
		document.getElementById("imgFrame").innerHTML = "<iframe src='galleryInfo.php?galleryID=" + galleryID + "' id='infoFrame' style='width:560px; height:451px; top:0px;' align='center' scrolling='no' marginheight='0' marginwidth='0' frameborder='0'>";
		storyInfoIsVisible = 1;
		document.getElementById("infoButDiv").innerHTML = "<a href='#' onclick='showGalleryInfo();' onMouseOut='MM_swapImgRestore()' onMouseOver='MM_swapImage(\"Image11\",\"\",\"img/information_close_on.gif\",1)' onFocus='this.blur()'><img src='img/information_close_off.gif' alt='Close Information On Story' name='Image11' width='32' height='24' border='0'></a>";
		nextImageButState = document.getElementById("nextImageBut").style.visibility;
		previousImageButState = document.getElementById("previousImageBut").style.visibility;
		document.getElementById("nextImageBut").style.visibility = 'hidden';
		document.getElementById("previousImageBut").style.visibility = 'hidden';
		document.getElementById("imageCounter").style.visibility ='hidden';
		document.getElementById("captionDiv").style.visibility ='hidden';
	}else{
		document.getElementById("imgFrame").innerHTML="<a href=# onMouseOver='displayCaption("+(galleryViewPointer+currentThumb-1)+");' onMouseOut='hideCaption();'><img id='imageFrameImg' border='0' align='left' style='opacity:0;' src='bin/galleries/"+galleryTitle+galleryID+"/"+thumbList[galleryViewPointer+currentThumb-1]+"' /></a>";	
		faderLevel=0;
		fader = window.setInterval ('fadeUpImage()', 20);
		storyInfoIsVisible = 0;
		document.getElementById("infoButDiv").innerHTML = '<a href=# onclick="showGalleryInfo();" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'Image11\',\'\',\'img/information_open_on.gif\',1)" onFocus="this.blur()"><img src="img/information_open_off.gif" alt=" Open Information On Story" name="Image11" width="32" height="24" border="0"></a>';
		document.getElementById("nextImageBut").style.visibility = "visible";
		document.getElementById("previousImageBut").style.visibility = "visible";
		document.getElementById("imageCounter").style.visibility ='visible';
		document.getElementById("captionDiv").style.visibility ='visible';
	}  
}

function sayHello(){
	alert("Ok Ok, Don't push us when we're hot !! ");

}



function galleryPreviousImage(){
		//alert('currentThumb='+currentThumb);
	document.getElementById("nextImageBut").style.visibility="visible";
	if(currentThumb>1){
		currentThumb-=1;
			if(galleryViewPointer==0 && currentThumb==1){
		
		}
	}else{
		
		if(galleryViewPointer==0){
			galleryViewPointer = parseInt(thumbList.length/5) *5;
			currentThumb= thumbList.length % 5;
		
		}else{
			galleryViewPointer-=5;
			currentThumb=5;
		}
	
	
	}
	
	for(xtd=1; xtd<=5; xtd++){
		if(document.getElementById("thumbBg" + xtd)!= null){
		document.getElementById("thumbBg" + xtd).innerHTML="";
		}
	}
		showHideThumbIndicator(currentThumb);
	var remainder =5;
	if((thumbList.length - galleryViewPointer) > 5){
			document.getElementById("thumbScrolldownBut").style.visibility="visible";
	}else{
		remainder = thumbList.length - galleryViewPointer;
	}
	
	for(xtd=1; xtd<=remainder; xtd++){
	if(document.getElementById("thumbBg" + xtd)!= null){
		document.getElementById("thumbBg" + xtd).innerHTML="<a href=# onclick='javascript:showHideThumbIndicator("+xtd+",\""+thumbList[(galleryViewPointer+xtd-1)]+"\",\""+galleryTitle+"\",\""+galleryID+"\" );' ><img id='galleryThumb"+xtd+"' border='0' align='right' src='thumbs/galleryContents/"+galleryTitle+galleryID+"/"+thumbList[(galleryViewPointer+xtd-1)]+"'/></a>";
		}
	}
	
		if(galleryViewPointer==0 && currentThumb==5){
			}
			
		displayImageCounter();

}

function galleryNextImage(){
	if((galleryViewPointer+currentThumb) == thumbList.length){
		galleryViewPointer=0;
		currentThumb=1
	}else{
		
	if(currentThumb<5){
		currentThumb+=1;
	}else{
		currentThumb = 1;
		galleryViewPointer+=5;
		
		document.getElementById("thumbScrollupBut").style.visibility="visible";
	}
}
	
	for(xtd=1; xtd<=5; xtd++){
		if(document.getElementById("thumbBg" + xtd)!= null){
		document.getElementById("thumbBg" + xtd).innerHTML="";
		}
	}

	var remainder =5;
	if((thumbList.length - galleryViewPointer) > 5){

	}else{
	
		//document.getElementById("thumbScrolldownBut").style.visibility="hidden";
		remainder = thumbList.length - galleryViewPointer;
	}
	for(xtd=1; xtd<=remainder; xtd++){
	if(document.getElementById("thumbBg" + xtd)!= null){
	document.getElementById("thumbBg" + xtd).innerHTML="<a href=# onclick='javascript:showHideThumbIndicator("+xtd+",\""+thumbList[(galleryViewPointer+xtd-1)]+"\",\""+galleryTitle+"\",\""+galleryID+"\" );' ><img id='galleryThumb"+xtd+"' border='0' align='right' src='thumbs/galleryContents/"+galleryTitle+galleryID+"/"+thumbList[(galleryViewPointer+xtd-1)]+"'/></a>";
		}
	}
	showHideThumbIndicator(currentThumb);
	document.getElementById("previousImageBut").style.visibility="visible";
	if(galleryViewPointer+currentThumb == thumbList.length){
		//document.getElementById("nextImageBut").style.visibility="hidden";
	}
		displayImageCounter();
}
function displayImageCounter(){
	var tempCounter=galleryViewPointer+currentThumb;
	if(tempCounter<10){
		tempCounter = "0"+tempCounter;
	}
	var tempImageCount = thumbList.length;
	if(thumbList.length <10){
		tempImageCount = "0"+thumbList.length;
	}
		document.getElementById("imageCounter").innerHTML = "<span  class='thumbcounter'>"+tempCounter+" / "+tempImageCount+"</span>";
}
function galleryThumbsPrevious(){
	resetInfo();
		galleryViewPointer-=5;
			currentThumb = 1;
		document.getElementById("thumbScrolldownBut").style.visibility="visible";
		
	if(galleryViewPointer > 0){
		
	}else{
		galleryViewPointer = 0;
	}


	for(xtd=1; xtd<=5; xtd++){
	if(document.getElementById("thumbBg" + xtd)!= null){
	document.getElementById("thumbBg" + xtd).innerHTML="<a href=# onclick='javascript:showHideThumbIndicator("+xtd+",\""+thumbList[(galleryViewPointer+xtd-1)]+"\",\""+galleryTitle+"\",\""+galleryID+"\" );' ><img id='galleryThumb"+xtd+"' border='0' align='right' src='thumbs/galleryContents/"+galleryTitle+galleryID+"/"+thumbList[(galleryViewPointer+xtd-1)]+"'/></a>";
		}
	}
	
	//document.getElementById("imgFrame").innerHTML="<img id='imageFrameImg' align='left' src='bin/galleries/"+galleryTitle+galleryID+"/"+thumbList[galleryViewPointer]+"' />";
	//document.getElementById("imgFrame").innerHTML="<img id='imageFrameImg' align='left' src='bin/galleries/"+galleryTitle+galleryID+"/"+thumbList[galleryViewPointer]+"' />";
	document.getElementById("imgFrame").innerHTML="<a href=# onMouseOver='displayCaption("+(galleryViewPointer+currentThumb-1)+");' onMouseOut='hideCaption();'><img id='imageFrameImg' border='0'  style='opacity:0;'  align='left' src='bin/galleries/"+galleryTitle+galleryID+"/"+thumbList[galleryViewPointer+currentThumb-1]+"' /></a>";	
	faderLevel=0;
	fader = window.setInterval ('fadeUpImage()', 20);
	
	clearThumbs();
	document.getElementById("thumbBg1").style.backgroundImage="url('img/thumbIndicatorBar_on.gif')";
	document.getElementById("nextImageBut").style.visibility="visible";
	
		displayImageCounter();
}
function galleryThumbsNext(){
		if((thumbList.length - galleryViewPointer) > 5){
		galleryViewPointer+=5;	
		resetInfo();
		currentThumb = 1;
		var remainder = 5;
		if((thumbList.length - galleryViewPointer) > 5){
		}else{	
		
			remainder = thumbList.length - galleryViewPointer;
	}
		
	for(xtd=1; xtd<=5; xtd++){
		if(document.getElementById("thumbBg" + xtd)!= null){
		document.getElementById("thumbBg" + xtd).innerHTML="";
		}
	}
	clearThumbs();
	
	for(xtd=1; xtd<=remainder; xtd++){
	if(document.getElementById("thumbBg" + xtd)!= null){
	document.getElementById("thumbBg" + xtd).innerHTML="<a href=# onclick='javascript:showHideThumbIndicator("+xtd+",\""+thumbList[(galleryViewPointer+xtd-1)]+"\",\""+galleryTitle+"\",\""+galleryID+"\" );' ><img id='galleryThumb"+xtd+"' border='0' align='right' src='thumbs/galleryContents/"+galleryTitle+galleryID+"/"+thumbList[(galleryViewPointer+xtd-1)]+"'/></a>";
		}
	}
	
	//document.getElementById("imgFrame").innerHTML="<img id='imageFrameImg' align='left' src='bin/galleries/"+galleryTitle+galleryID+"/"+thumbList[galleryViewPointer]+"' />";
	document.getElementById("imgFrame").innerHTML="<a href=# onMouseOver='displayCaption("+(galleryViewPointer+currentThumb-1)+");' onMouseOut='hideCaption();'><img id='imageFrameImg' border='0' align='left' style='opacity:0;' src='bin/galleries/"+galleryTitle+galleryID+"/"+thumbList[galleryViewPointer+currentThumb-1]+"' /></a>";	
	faderLevel=0;
	var fader = window.setInterval ('fadeUpImage()', 20);
	document.getElementById("thumbBg1").style.backgroundImage="url('img/thumbIndicatorBar_on.gif')";
	
		displayImageCounter();
			
	}
}
var faderLevel=0;
function fadeUpImage(){
	if(document.getElementById("imageFrameImg").style.opacity <1){
		faderLevel+=0.08;
		document.getElementById("imageFrameImg").style.opacity=faderLevel;
	}else{
		window.clearInterval(fader);
		}
}
function clearThumbs(){
	for(xtd=1; xtd<=5; xtd++){
		if(document.getElementById("thumbBg" + xtd)!= null){
		document.getElementById("thumbBg" + xtd).style.backgroundImage="url('img/thumbIndicatorBar_off.gif')" ;
		}
	}
}

var currentThumb;

function showHideThumbIndicator(whichThumb){
	currentThumb = whichThumb;
	clearThumbs();
	var tempImage = galleryViewPointer+currentThumb-1;

	document.getElementById("thumbBg" + currentThumb).style.backgroundImage="url('img/thumbIndicatorBar_on.gif')";
		if(currentThumb==1 && galleryViewPointer==0){

		}else{
			document.getElementById("previousImageBut").style.visibility = 'visible';
		}
		if((currentThumb + galleryViewPointer) == thumbList.length){
		}else{
			document.getElementById("nextImageBut").style.visibility = 'visible';
		}
			resetInfo();
	displayImageCounter();
	
}
function resetInfo(){
	storyInfoIsVisible = 1;
	showGalleryInfo();
}
function displayGalleryViewer(galleryTitle,galleryID){

	var mydiv = this.parent.document.getElementById("infoArea");

	var newdiv = document.createElement('div');
 	var divIdName ='thumbViewDiv';
  	newdiv.setAttribute('id',divIdName);
	newdiv.innerHTML = '<iframe src="galleryViewer.php?thumbView=true&galleryTitle='+galleryTitle+'&galleryID='+galleryID+'" id="galleryViewer" width="808" height="476" scrolling="no" marginheight="0" marginwidth="0" frameborder="0">';
 	mydiv.appendChild(newdiv); 
	mydiv.style.overflow ="visible";
	
	this.parent.document.getElementById('infoArea').removeChild(this.parent.document.getElementById("galleryMenuIframe"));
 
}

var galleryScrollUp = 0;
function galleryScrollup(dir) {

	if(dir == 'stop'){
		 window.clearTimeout(galleryScrollUp);
	}else{
		var curPos = document.getElementById("galleryMenu").style.top;
			//alert('curPos='+ curPos);
			maxPos =  440 - parseInt(galleryHeight);
			newPos = parseInt(curPos) -4;
			
		if (maxPos < newPos){
			document.getElementById("galleryMenu").style.top = newPos + "px";
			galleryScrollUp = window.setTimeout("galleryScrollup('up')", 35);
		}else{
			window.clearTimeout(galleryScrollUp);
		}
	}
}
var infoHeight =0;
function checkinfoHeight(){

	var x,y;
		var test1 = document.body.scrollHeight;
		var test2 = document.body.offsetHeight
		if (test1 > test2) // all but Explorer Mac
		{
			x = document.body.scrollWidth;
			y = document.body.scrollHeight;
		}
		else // Explorer Mac;
			 //would also work in Explorer 6 Strict, Mozilla and Safari
		{
			x = document.body.offsetWidth;
			y = document.body.offsetHeight;
		}
		
		infoHeight = y ;

//	if(infoHeight > 456){
		//document.getElementById("infoScrollupBut").style.visibility = "visible";
	//}
	
}
function infoScrollup(dir) {

	if(dir == 'stop'){
		 window.clearTimeout(infoScrollUp);
	}else{
			document.getElementById("infoScrolldownBut").style.visibility = "visible";
		var curPos = document.getElementById("storytext").style.top;

			maxPos =  456 - parseInt(infoHeight) -3;
			newPos = parseInt(curPos) -4;
			
		if (maxPos < newPos){
			document.getElementById("storytext").style.top = newPos + "px";
			infoScrollUp = window.setTimeout("infoScrollup('up')", 35);
		}else{
			//document.getElementById("infoScrollupBut").style.visibility = "hidden";
			window.clearTimeout(infoScrollUp);
		}
	}
}

function infoScrolldown(dir){

	if(dir == 'stop'){
		 window.clearTimeout(infoScrollDown);
	}
	else{
			document.getElementById("infoScrollupBut").style.visibility = "visible";
			var curPos = document.getElementById("storytext").style.top;

			maxPos =  0;
			newPos = parseInt(curPos) + 4;			
		if (maxPos >= newPos){
			document.getElementById("storytext").style.top = newPos + "px";
			infoScrollDown = window.setTimeout("infoScrolldown('down')", 35);
		}
		else{
			//document.getElementById("infoScrolldownBut").style.visibility = "hidden";
			window.clearTimeout(infoScrollDown);
		}
	}
}



var galleryScrollDown =0;
function galleryScrolldown(dir){

	if(dir == 'stop'){
		 window.clearTimeout(galleryScrollDown);
	}
	else{
		var curPos = document.getElementById("galleryMenu").style.top;
	
			maxPos =  0;
			newPos = parseInt(curPos) + 4;			
		if (maxPos >= newPos){
			document.getElementById("galleryMenu").style.top = newPos + "px";
			galleryScrollDown = window.setTimeout("galleryScrolldown('down')", 35);
		}
		else{
			window.clearTimeout(galleryScrollDown);
		}
	}
}
var galleryHeight = 0;

function checkGalleryHeight(){
	
	var x,y;
		var test1 = document.body.scrollHeight;
		var test2 = document.body.offsetHeight
		if (test1 > test2) // all but Explorer Mac
		{
			x = document.body.scrollWidth;
			y = document.body.scrollHeight;
		}
		else // Explorer Mac;
			 //would also work in Explorer 6 Strict, Mozilla and Safari
		{
			x = document.body.offsetWidth;
			y = document.body.offsetHeight;
		}
		
		galleryHeight = y ;
	if(galleryHeight > 456){
	
		document.getElementById("galleryScrolldownBut").style.visibility = "visible";
		document.getElementById("galleryScrollupBut").style.visibility = "visible";
		
	}
		//alert('galleryHeight='+galleryHeight);
}

function findImg(){
		var whichImage = (Math.round(Math.random() * bilderNum));
		 document.getElementById("imgArea").innerHTML = "<img id='home_fade' style='FILTER: alpha(opacity=0); opacity:0;' src='bin/home/" + bilder[whichImage] + "\' border='0' name='imgregion'  onClick='loadMainPage()' class='hand' onFocus='this.blur()'/>";	
		img_fade_in();
}
function displayCaption(whichImage){

		document.getElementById("captionDiv").innerHTML ="<span class='infotext'>"+captionList[whichImage]+"</span>";
} 
function hideCaption(){
		document.getElementById("captionDiv").innerHTML ="<span class='infotext'></span>";
}
function loadMainPage(){
		location.replace("index2.php?pageID="+pageID+"&navLayer=1");
	
}
function menu_mouse_over(wer){
				document.getElementById("story" + wer).style.backgroundColor = "#A9958B";
	
}
function menu_mouse_off(whichMenuButton){

			for(var s=1; s<=pagesNum; s++){
				document.getElementById("story" + s).style.backgroundColor = "#DCD5D1";
		
		}
		if(navLayer!=0){
				document.getElementById("story" + navLayer).style.backgroundColor = "#A9958B";
		}
}

function updateAfterTileUpload(whichGallery){
	this.opener.location.replace("edit_galleries.php?galleryToEdit="+whichGallery);
	window.close();

}
function createAddContentForm(galleryID,galleryTitle,gallerySortID){

	document.getElementById("addContentFrame").innerHTML ="<form name='saveNewContent' action='edit_galleries.php' method='post' enctype='multipart/form-data' onsubmit='return checkNewContentForm(this);'><table width='100%' border='0' cellspacing='3' cellpadding='0'  class='topline'><td width='96px' ><a href='#' onclick='uploadTilePic(\".$galleryID.\")'><img src='../thumbs/gallery/gallery_default.jpg' width='96px' height='74px' border='0'></a></td><td class='storytext'>Sort-Nr:&nbsp;<input type='text' name='sortID' value='' style='width:40px' class='storytext'></td><td align='right' valign='top' style='width:100%' ><input type='submit' name='saveNewContent' value='Save New Content' class='button1'></td><input type='text' name='galleryID' value='"+galleryID+"' class='navitext'><input type='text' name='galleryTitle' value='"+galleryTitle+"' class='navitext'><input type='text' name='gallerySortID' value='"+gallerySortID+"' class='navitext'></table></form>";		
							
}
function checkDeleteContent(form){
	
	Check = confirm('Delete this Content? No way to undo this action! --------------------------------------------');
		if (Check == true){
			return true;
		}
}
function createNewGalleryForm(){
	document.getElementById("galleryEditForm").innerHTML ="<form name='archiveHead' action='edit_galleries.php' method='post' enctype='multipart/form-data' onsubmit='return checkNewGalleryForm(this);'><table width='100%' border='0' cellspacing='3' cellpadding='0'  class='topline'><td class='storytext'>Title:&nbsp;<input type='text' size='20' maxlength='20' name='galleryTitle' value='' class='navitext'></td><td class='storytext'>Date:&nbsp;<input type='text' size='20' maxlength='20' name='galleryDate' value='' class='navitext'></td><td class='storytext'>Sort-Nr:&nbsp;<input type='text' name='gallerySortID' value='' style='width:40px' class='storytext'></td><td align='right' valign='top' style='width:100%' ><input type='submit' name='newGallery' value='Create New Gallery' class='button1'></td></table></form>";
	document.getElementById('galleryToEdit').selectedIndex=0;		
							
}
function checkNewContentForm(form){

var result = true;

	return result;
}
function checkNewGalleryForm(form){
	var result = true;
	switch (true){
		case form.galleryTitle.value == "" :
    		alert( "Please enter your Gallery Title." );
    		form.galleryTitle.focus();
    		result= false ;
		break;
		case  form.gallerySortID.value == "" :
    		alert( "Please enter your Gallery sort number." );
    		form.gallerySortID.focus();
    		result= false ;
		break;
		default:
		break;
	}
	return result;
}
var uploadContentWindow;
function uploadContent(galleryID,galleryTitle,gallerySortID){
	//uploadContentWindow = window.open('http://www.stevonritchie.info/ilan/cms/uploadContent.php?galleryID='+galleryID+'&galleryTitle='+galleryTitle+'&gallerySortID='+gallerySortID,'uploadTileWindow','width=765,height=240,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
	uploadContentWindow = window.open('http://ilangodfrey.com/cms/uploadContent.php?galleryID='+galleryID+'&galleryTitle='+galleryTitle+'&gallerySortID='+gallerySortID,'uploadTileWindow','width=765,height=240,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');

}
var uploadTileWindow;
function uploadTilePic(whichGallery){

	//uploadTileWindow = window.open('http://www.stevonritchie.info/ilan/cms/uploadTilePic.php?whichGallery='+whichGallery,'uploadTileWindow','width=765,height=240,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
	uploadTileWindow = window.open('http://ilangodfrey.com/cms/uploadTilePic.php?whichGallery='+whichGallery,'uploadTileWindow','width=765,height=240,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');

}

