/*** MOVE STRIPEPICS2 ***/


firstleftstart = 272;
rasterleft = 720;
difftomove2 = rasterleft - firstleftstart;
step = 32;
speed = 6;
moved2 = 0;
movedpicsright2 = 0;
marginRight2 = 0;
marginRightAfter2 = 0;
hasChildNodes2 = false;
amountChildNodes2 = 0;

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


// init functions
initMoveItDone2 = false;
function initMoveIt2() {
	
	if (typeof(beforeleft2)=='undefined') {
		// get init left position of beforepic2 (depending on amount of which pictures)
		beforeleft2 = parseInt(document.getElementById('stripepics2').style.left.replace(/px/, ''));
		//alert(beforeleft2);
  	}
  	
  	if (typeof(beforepic2)=='undefined') {
		beforepic2 = document.getElementById('stripepics2');
		if (beforepic2.hasChildNodes) {
			hasChildNodes2 = true;
			amountChildNodes2 = beforepic2.childNodes.length;
		}
	}
}


function showhidePlus2(child) {
	
	childonclick = child.getAttribute('onclick');
	if (childonclick == null) {
		document.getElementById("navplus2").style.display = "none";
	} else {
		document.getElementById("navplus2").style.display = "block";
	}
	
}
function updateCounter2(minus) {
	//piccounter = amountChildNodes2-minus;
	piccounter = minus+1;
	if (parseInt(piccounter)<10) {
		piccounter = "0"+piccounter;
	}
	document.getElementById("picCounter2").firstChild.nodeValue = piccounter;
}



function moveRightClick2() {
	
	if (initMoveItDone2 == false) {
		initMoveIt2();
		initMoveItDone2 = true;
	}
	
	// prevent multiple calls to moveRight&moveLeft function
	if (movingCurrenttly2==false) {
  		movingCurrenttly2 = true;
  		
  		if (hasChildNodes2 && amountChildNodes2 > (movedpicsright2+1)) {
			childindex = amountChildNodes2 - movedpicsright2 - 2;
			//alert(childindex);
			child = beforepic2.childNodes[childindex];
			childwidth2 = child.getAttribute('width');
			childafter = beforepic2.childNodes[childindex+1];
			if (childwidth2!=null) {
				
				// marginRightAfter2
				marginRightAfter2 = marginRight2;
				marginRight2 = 0;
				
				showhidePlus2(child);
				updateCounter2(childindex);
				moveRight2();
			
			} else {
				movingCurrenttly2 = false;
			}
		} else {
			movingCurrenttly2 = false;
		}
	}
}

function moveLeftClick2() {
	
	if (initMoveItDone2 == false) {
		initMoveIt2();
		initMoveItDone2 = true;
	}
	
	// prevent multiple calls to moveRight&moveLeft function
	if (movingCurrenttly2==false) {
  		movingCurrenttly2 = true;
  		
  		if (hasChildNodes2 && movedpicsright2>0) {
			childindex = amountChildNodes2 - movedpicsright2 - 1;
			child = beforepic2.childNodes[childindex];
			childwidth2 = child.getAttribute('width');
			childafter = beforepic2.childNodes[childindex+1];
			childafterwidth = childafter.getAttribute('width');
			
			if (childafterwidth!=null) {
				
				showhidePlus2(childafter);
				updateCounter2(childindex+1);
				moveLeft2();
			
			} else {
				movingCurrenttly2 = false;
			}
		} else {
			movingCurrenttly2 = false;
		}
	}
}



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



function moveLeft2() {  
  
  if (moved2 >= difftomove2) {
	
	// one move finished!
	
	moved2 = 0;
	
	// marginRightAfter2
	marginRight2 = marginRightAfter2;
	marginRightAfter2 = 0;
	
	// moved one more pic of beforepic2 to the right
	movedpicsright2--;
	//alert(movedpicsright2);
	
	movingCurrenttly2 = false;
	
  } else {
  
	// still moving...		
	
	if (marginRight2 > 0) {
		
		//alert('la');
		
		// if current pictures has right margin, reduce it to 0 step by step
		
		if (marginRight2 < step) {
			// inc position counter
			moved2 = moved2 + marginRight2;
			diffstep = marginRight2;
			
			marginRight2 = 0;
		} else {
			// inc position counter
			moved2 = moved2 + step;
			diffstep = step;
			
			marginRight2 = marginRight2 - step;
		}
		child.style.marginRight = marginRight2 + 'px';
		
		
		// picture after needs right margin?
		
		if ((parseInt(childwidth2)+parseInt(childafterwidth)+parseInt(marginRight2)+parseInt(marginRightAfter2)) < difftomove2) {
			//alert('lb');
			//alert((parseInt(childwidth2)+parseInt(childafterwidth)+parseInt(marginRight2)+parseInt(marginRightAfter2)));
			marginRightAfter2 = marginRightAfter2 + diffstep;
			childafter.style.marginRight = marginRightAfter2 + 'px';
		}
		
		
	} else {
		
		
		if (moved2+step > childafterwidth) {
	
			// after picture needs right margin...
			
			marginRightAfter2 = marginRightAfter2 + step;
			childafter.style.marginRight = marginRightAfter2 + 'px';
		}
		
		// move all pictures...
		
		beforeleft2 = beforeleft2 - step;
		beforepic2.style.left = beforeleft2 + 'px';
		
		// inc position counter
		moved2 = moved2 + step;
		
		
		// close gap
		if (moved2+step > difftomove2) {
			
			// right
			if (moved2+step > childafterwidth) {
				marginRightAfter2 = (difftomove2-childafterwidth);
				childafter.style.marginRight = marginRightAfter2 + 'px';
			}

			// left
			beforeleft2 = beforeleft2 - (difftomove2-moved2);
			beforepic2.style.left = beforeleft2 + 'px';
			// inc position counter
			moved2 = moved2 + (difftomove2-moved2);
		}
	}
		
	
	// inc position counter
	//moved2 = moved2 + step;	
	
			
	// loop
	window.setTimeout("moveLeft2()", speed);
  }
}



function openCurrentPicWindow2() {
	if (initMoveItDone2 == false) {
		initMoveIt2();
		initMoveItDone2 = true;
	}
	n = amountChildNodes2-movedpicsright2-1;
	child = beforepic2.childNodes[n];
	childonclick = child.getAttribute('onclick');
	//alert(childonclick);
	if (childonclick != null) {
		eval(childonclick);
	}
	/*
	src = child.getAttribute('src');
	newsrc = src.replace(/thumbnails/, "popup");
	openPicWindow(newsrc);
	*/
}
