var actP = 0;
function showP(nr) {
 setInfoBoxState(0);
 var curActObj = document.getElementById("p" + actP);
 curActObj.style.display = "none";
 var obj = document.getElementById("p" + nr);
 //obj.style.display = "inline";
 actP = nr;
 var imageHolder = document.getElementById("ppic");
 if (imageHolder) {
  //currentPicture = productPics[nr].length - 1;
  currentPicture = 0;
  showAlignPicture("http://www.freja-brudekjoler.dk/" + productPics[nr][currentPicture]);
  var obj = document.getElementById('npicl');
  if (productPics[nr].length < 2) {
   obj.className = "pasNextPic";
  } else {
   obj.className = "actNextPic";
  }
 } else {
  alert("No holder for pic" + nr);
 }
 return false;
}
var currentPicture=0;
function showNextPicture() {
 var imageHolder = document.getElementById("ppic");
 if (imageHolder) {
  if (productPics[actP].length > (currentPicture+1)) {
   ++currentPicture;
  } else {
   currentPicture = 0;
  }
  showAlignPicture("http://www.freja-brudekjoler.dk/" + productPics[actP][currentPicture]);
 }
 return false;
}
function showAlignPicture(pictureUrl) {
 var img=new Image();
 img.onload=function(){
  var leftMargin = 0;
  if (img.width != 350) {	
	leftMargin = (350 - img.width) / 2;
	if (location.href.indexOf("brudesko") != -1) { // shoe page
	 leftMargin -= 25;	
	}
  }
  var imageHolder = document.getElementById("ppic");
  imageHolder.style.marginLeft = leftMargin + "px";
  imageHolder.src = img.src;
 }
 img.src=pictureUrl;
}
var currentInfoState = 0;
function setInfoBoxState(state){
 var adjustTop = 0;
 if (state == 0) {
  adjustTop = 471;
 } else {
  adjustTop = 400;
 }
 var obj = document.getElementById("pInfoBox");
 obj.style.top = adjustTop + "px";
 var curActObj = document.getElementById("p" + actP);
 if (state == 0) {
  curActObj.style.display = "none";
 } else {
  curActObj.style.display = "inline";
 }
 currentInfoState = state;
}
function switchInfoBox(){
 if (currentInfoState == 0) {
  setInfoBoxState(1);
 } else {
  setInfoBoxState(0);
 }
 return false;
}
function init() {
 if (typeof activeProduct != "undefined") {
  showP(activeProduct);
 }
}
var scrollObj = null;
var scrollScrolled = 0;
var scrollScroll = 0;
var scrollingUp = false;
function scrollUp() {
 if (scrollScroll > 0) return;
 var startScroll = false;
 if (scrollObj == null) {
  scrollObj = document.getElementById("kollektionSelection");
  startScroll = true;
 }
 scrollScroll += scrollObj.scrollTop % 118 * -1 -118
 if (startScroll) {
  smoothScroll();
 }
}
function scrollDown() {
 if (scrollScroll < 0) return;
 var startScroll = false;
 if (scrollObj == null) {
  scrollObj = document.getElementById("kollektionSelection");
  startScroll = true;
 }
 scrollScroll += 118;
  if (startScroll) {
  smoothScroll();
 }
}
function smoothScroll() { 
 if (scrollScrolled >= Math.abs(scrollScroll)) {
  scrollObj = null;
  scrollScrolled = 0; 
  scrollScroll = 0;
  return;
 }
 var nextVal = 0;
 if (!isNaN(scrollObj.scrollTop)) {
  nextVal = scrollObj.scrollTop;
 }
 var scrollVal = 0;
 if (scrollScrolled < 5) {
  scrollVal = 2
 } else if (scrollScrolled < 10) {
  scrollVal = 4
 } else if ((Math.abs(scrollScroll) - scrollScrolled) < 10) {
  scrollVal = 4
 } else if ((Math.abs(scrollScroll) - scrollScrolled) < 5) {
  scrollVal = 2
 } else {
  scrollVal = 6
 }
 if (scrollScrolled + scrollVal >= Math.abs(scrollScroll)) {
  scrollVal = Math.abs(scrollScroll) - scrollScrolled;
 }
 scrollScrolled += scrollVal;
 if (scrollScroll < 0) {
  scrollVal *= -1;
 }
 nextVal += scrollVal;  
 scrollObj.scrollTop = nextVal; 	
 setTimeout('smoothScroll()', 30)
}