/*** MOVE STRIPEPICS ***/


firstleftstart = 272;
rasterleft = 720;
difftomove = rasterleft - firstleftstart;
step = 32;
speed = 6;
moved = 0;
movedpicsright = 0;
marginRight = 0;
marginRightAfter = 0;
hasChildNodes = false;
amountChildNodes = 0;

// to prevent parallel calls of moving functions
movingCurrenttly = false;


// init functions
initMoveItDone = false;
function initMoveIt() {
	
	if (typeof(beforeleft)=='undefined') {
		// get init left position of beforepics (depending on amount of which pictures)
		beforeleft = parseInt(document.getElementById('stripepics').style.left.replace(/px/, ''));
		//alert(beforeleft);
  	}
  	
  	if (typeof(beforepics)=='undefined') {
		beforepics = document.getElementById('stripepics');
		if (beforepics.hasChildNodes) {
			hasChildNodes = true;
			amountChildNodes = beforepics.childNodes.length;
			//alert(amountChildNodes);
		}
	}
}


function showhidePlus(child) {
	
	childonclick = child.getAttribute('onclick');
	if (childonclick == null) {
		document.getElementById("navplus").style.display = "none";
	} else {
		document.getElementById("navplus").style.display = "block";
	}
	
}
function updateCounter(minus) {
	//piccounter = amountChildNodes-minus;
	piccounter = minus+1;
	if (parseInt(piccounter)<10) {
		piccounter = "0"+piccounter;
	}
	document.getElementById("picCounter").firstChild.nodeValue = piccounter;
}



function moveRightClick() {
	
	if (initMoveItDone == false) {
		initMoveIt();
		initMoveItDone = true;
	}
	
	// prevent multiple calls to moveRight&moveLeft function
	if (movingCurrenttly==false) {
  		movingCurrenttly = true;
  		
  		if (hasChildNodes && amountChildNodes > (movedpicsright+1)) {
			childindex = amountChildNodes - movedpicsright - 2;
			//alert(childindex);
			child = beforepics.childNodes[childindex];
			childwidth = child.getAttribute('width');
			childafter = beforepics.childNodes[childindex+1];
			if (childwidth!=null) {
				
				// marginRightAfter
				marginRightAfter = marginRight;
				marginRight = 0;
				
				showhidePlus(child);
				updateCounter(childindex);
				moveRight();
			
			} else {
				movingCurrenttly = false;
			}
		} else {
			movingCurrenttly = false;
		}
	}
}

function moveLeftClick() {
	
	if (initMoveItDone == false) {
		initMoveIt();
		initMoveItDone = true;
	}
	
	// prevent multiple calls to moveRight&moveLeft function
	if (movingCurrenttly==false) {
  		movingCurrenttly = true;
  		
  		if (hasChildNodes && movedpicsright>0) {
			childindex = amountChildNodes - movedpicsright - 1;
			child = beforepics.childNodes[childindex];
			childwidth = child.getAttribute('width');
			childafter = beforepics.childNodes[childindex+1];
			childafterwidth = childafter.getAttribute('width');
			
			if (childafterwidth!=null) {
				
				showhidePlus(childafter);
				updateCounter(childindex+1);
				moveLeft();
			
			} else {
				movingCurrenttly = false;
			}
		} else {
			movingCurrenttly = false;
		}
	}
}



function moveRight() {  
  
  if (moved >= difftomove) {
	
	// one move finished!
	
	//alert(moved);
	//child.style.marginRight = '0px';
	//alert(marginRight);
	
	moved = 0;
	
	
	// moved one more pic of beforepics to the right
	movedpicsright++;
	//alert(movedpicsright);
	
	movingCurrenttly = false;
	
  } else {
  
	// still moving...		
	
	// move 'stripepics'
	//alert(moved+step);
	if (moved+step <= childwidth) {
		
		//alert('a');
		
		// move all pictures...
		
		// if current pictures has right margin, reduce it to 0 step by step
		if (marginRightAfter > 0) {
			if (marginRightAfter < step) {
				//alert('kleiner '+marginRightAfter);
				marginDiff = marginRightAfter;
				marginRightAfter = 0;
				
				// and move
				beforeleft = beforeleft + marginDiff;
				beforepics.style.left = beforeleft + 'px';
				// inc position counter
				moved = moved + marginDiff;
				
			} else {
				marginRightAfter = marginRightAfter - step;
				
				// and move
				beforeleft = beforeleft + step;
				beforepics.style.left = beforeleft + 'px';
				// inc position counter
				moved = moved + step;
			}
			childafter.style.marginRight = marginRightAfter + 'px';
			//alert(marginRight);
			//marginRightAfter = marginRight;
			
		} else {
			
			// just move
			beforeleft = beforeleft + step;
			beforepics.style.left = beforeleft + 'px';
			// inc position counter
			moved = moved + step;
		}
	
	} else if (moved+step > childwidth && moved < childwidth) {
		
		//alert('b');
		
		// close gap left
		beforeleft = beforeleft + (childwidth-moved);
		beforepics.style.left = beforeleft + 'px';
		
		// inc position counter
		moved = moved + (childwidth-moved);
	
	} else if (moved+step > childwidth) {
	
		/*alert('c');
		alert('mr'+marginRight);
		alert('mra'+marginRightAfter);*/
		
		
		// close the gap right with childafter
		//alert(marginRightAfter);
		if (marginRightAfter>0) {
			//alert(marginRightAfter);
			if (marginRightAfter < step) {
				marginDiffAfter = marginRightAfter;
				marginRightAfter = 0;
				childafter.style.marginRight = marginRightAfter + 'px';
				//moved = moved + marginDiffAfter;
			} else {
				marginRightAfter = marginRightAfter - step;
				childafter.style.marginRight = marginRightAfter + 'px';
				//moved = moved + step;
			}
		}
		
		
		// current picture needs right margin...
		//alert(marginRight);
		marginRight = marginRight + step;
		child.style.marginRight = marginRight + 'px';
		
		// inc position counter
		moved = moved + step;
		
		
		// close the gap right
		if (moved+step > difftomove) {
			
			// gap is to big, close it again
			marginRight = marginRight + (difftomove-moved);
			child.style.marginRight = marginRight + 'px';
			
			// also have to move?
			if (moved < difftomove) {
				//alert('c1');
				moved = moved + (difftomove-moved);
			}
		} 
	}
	
	
	// inc position counter
	//moved = moved + step;
	
	// loop
	window.setTimeout("moveRight()", speed);
  }
}



function moveLeft() {  
  
  if (moved >= difftomove) {
	
	// one move finished!
	
	moved = 0;
	
	// marginRightAfter
	marginRight = marginRightAfter;
	marginRightAfter = 0;
	
	// moved one more pic of beforepics to the right
	movedpicsright--;
	//alert(movedpicsright);
	
	movingCurrenttly = false;
	
  } else {
  
	// still moving...		
	
	if (marginRight > 0) {
		
		//alert('la');
		
		// if current pictures has right margin, reduce it to 0 step by step
		
		if (marginRight < step) {
			// inc position counter
			moved = moved + marginRight;
			diffstep = marginRight;
			
			marginRight = 0;
		} else {
			// inc position counter
			moved = moved + step;
			diffstep = step;
			
			marginRight = marginRight - step;
		}
		child.style.marginRight = marginRight + 'px';
		
		
		// picture after needs right margin?
		
		if ((parseInt(childwidth)+parseInt(childafterwidth)+parseInt(marginRight)+parseInt(marginRightAfter)) < difftomove) {
			//alert('lb');
			//alert((parseInt(childwidth)+parseInt(childafterwidth)+parseInt(marginRight)+parseInt(marginRightAfter)));
			marginRightAfter = marginRightAfter + diffstep;
			childafter.style.marginRight = marginRightAfter + 'px';
		}
		
		
	} else {
		
		
		if (moved+step > childafterwidth) {
	
			// after picture needs right margin...
			
			marginRightAfter = marginRightAfter + step;
			childafter.style.marginRight = marginRightAfter + 'px';
		}
		
		// move all pictures...
		
		beforeleft = beforeleft - step;
		beforepics.style.left = beforeleft + 'px';
		
		// inc position counter
		moved = moved + step;
		
		
		// close gap
		if (moved+step > difftomove) {
			
			// right
			if (moved+step > childafterwidth) {
				marginRightAfter = (difftomove-childafterwidth);
				childafter.style.marginRight = marginRightAfter + 'px';
			}

			// left
			beforeleft = beforeleft - (difftomove-moved);
			beforepics.style.left = beforeleft + 'px';
			// inc position counter
			moved = moved + (difftomove-moved);
		}
	}
		
	
	// inc position counter
	//moved = moved + step;	
	
			
	// loop
	window.setTimeout("moveLeft()", speed);
  }
}



function openCurrentPicWindow() {
	if (initMoveItDone == false) {
		initMoveIt();
		initMoveItDone = true;
	}
	n = amountChildNodes-movedpicsright-1;
	child = beforepics.childNodes[n];
	childonclick = child.getAttribute('onclick');
	//alert(childonclick);
	if (childonclick != null) {
		eval(childonclick);
	}
	/*
	src = child.getAttribute('src');
	newsrc = src.replace(/thumbnails/, "popup");
	openPicWindow(newsrc);
	*/
}
