
	var slideshow_ids = new Array();
	
  function user_zwfbestelsysteem_MateriaalViewmenu_togglemenu(section){
    var elem = document.getElementById('user_zwfbestelsysteem_MateriaalViewmenu_window');
    if(elem==null) return;
    var elems = elem.getElementsByTagName('div');
    for(var i in elems){
      if(!elems[i].className) continue;
      if(!hasClass(elems[i], 'productsection')) continue;
      else if(hasClass(elems[i], section)){
        elems[i].style.display = 'block';
      }
      else elems[i].style.display = 'none';
    }
    
    var elems = document.getElementsByTagName('ul');
    for(var i in elems){
      if(!elems[i].className) continue;
      if(!hasClass(elems[i], 'menusection')) continue;
      
      var elems2 = elems[i].getElementsByTagName('li');
      for(var j in elems2){
        if(!elems2[j].className) continue;
        if(hasClass(elems2[j], section)) addClass(elems2[j], 'selected');
        else removeClass(elems2[j], 'selected');
      }
    }
  }
  function orderNowMouse(evt, getx){
    var IE = document.all ? true : false;   
    if(getx) return IE ? evt.clientX + document.body.scrollLeft : evt.pageX;
    else     return IE ? evt.clientY + document.body.scrollTop  : evt.pageY;
  }
  function orderNow(evt, obj, id){
    if(!obj) return false;
    if(!evt) evt = window.event;
    var bpnode = obj.parentNode;
    if(!bpnode) return false;
    var pnode = bpnode.parentNode;
    if(!pnode) return false;
    var childs = pnode.childNodes;
    for(var i in childs){
      if(!childs[i].className) continue;
      if(hasClass(childs[i], 'ordernowpopup')){
        childs[i].style.display = 'block';
        var x = bpnode.offsetLeft+'px';
        var y = bpnode.offsetTop+'px';
        childs[i].style.left = x;
        childs[i].style.top  = y;
        childs[i].style.minWidth = bpnode.offsetWidth+'px';
        addClass(bpnode, 'gbutton-180-active');
        return false;
      }
    }
    if(id) zwfb_bipcus.addBlockClient('', 'http://www.photogifts.nl/stream/bestel/bipcus/materiaal/set'+'/materiaal/'+id);       
    return true;
  }
  function filterCloseOrderNowPopup(evt, obj, id){
    var targ = null;
    if(evt) targ = evt.target;
    else{
      targ = window.event.srcElement;
      evt  = window.event; 
    }
    if(targ==null) return;
    if(!hasClass(targ, 'ordernowpopup')) return;
    
    var to = evt.relatedTarget ? evt.relatedTarget : evt.toElement;
    if(to==null) return;
    
    while(to && to!=targ) to = to.parentNode;
    if(to!=targ) return closeOrderNowPopup(evt, obj, id);
    else return;
  }
  function closeOrderNowPopup(evt, obj, id){
    if(!obj) return false;
    if(!evt) evt = window.event;
    var bpnode = obj;
    while(!hasClass(bpnode, 'ordernowpopup')){
      bpnode = bpnode.parentNode;
      if(!bpnode) return false;
    }
    var pnode = bpnode.parentNode;
    if(!pnode) return false;
    var childs = pnode.childNodes;
    for(var i in childs){
      if(!childs[i].className) continue;
      if(hasClass(childs[i], 'ordernowbutton')){
        removeClass(childs[i], 'gbutton-180-active');
        if(!id){
          bpnode.style.display = 'none';
          return false; 
        }
        else{
          zwfb_bipcus.addBlockClient('', 'http://www.photogifts.nl/stream/bestel/bipcus/materiaal/set'+'/materiaal/'+id);        
          return true;
        }
      }
    }
    return true;
  } 
  function openGallery(url, w, h){    
    var max_w = document.body.offsetWidth  - 100;
    var max_h = document.body.offsetHeight - 100;
    var new_w;
    var new_h;
    
    if(w/max_w < h/max_h){
      new_h = max_h;
      new_w = (max_h/h) * w;
    } 
    else{
      new_w = max_w;
      new_h = (max_w/w) * h;
    }
    
    var relem = document.createElement('div');
    relem.setAttribute('style'  , 'position: fixed; left: 0px; top: 0px; bottom: 0px; right: 0px; background: url("fileadmin/templates/img/08-06-2011/bg.png") repeat center center; z-index: 1000;');
    relem.setAttribute('id'     , 'image_gallery');
    
    var elem = document.createElement('div');
    elem.setAttribute('style'  , 'position: fixed; left: 50%; top: 50%; margin-left: '+(-new_w/2-5)+'px; margin-top: '+(-new_h/2-5)+'px; width: '+new_w+'px; height: '+(new_h+20)+'px; background-color: #FFFFFF; padding: 5px; border: 1px solid #000000; z-index: 1000;');
    elem.setAttribute('onclick', 'closeGallery();');
    var result = '<';
    result += 'img style="width: '+new_w+'px; height: '+new_h+'px;" src="'+url+'" ';
    result += '/>';
    result += '<'+'a href="/" onclick="closeGallery(); return false;" style="position: absolute; bottom: 5px; left: 0px; right: 0px; text-align: center; display: block;">(klik hier om het venster te sluiten)</a>';
    elem.innerHTML = result;
    relem.appendChild(elem);
    document.body.appendChild(relem);
    
    return false;
  }
  function closeGallery(){
    var elem = document.getElementById('image_gallery');
    if(elem==null) return;
    document.body.removeChild(elem);
  }
  function showSlideShow(iid){
  	var elem = document.getElementById('slideshow');
  	if(elem==null) return;
  	var childs = elem.childNodes;
  	for(var i=0; i<childs.length; ++i){
  		if(!hasClass(childs[i], 'canvas')) continue;
  		if(hasClass(childs[i], 'canvas_'+iid)) childs[i].style.display = 'block';
  		else childs[i].style.display = 'none';
  	}
  }
  function registerSlideShow(iid){
  	slideshow_ids.push(iid);
  }
  function autoRunSlideShow(){
  	var id = slideshow_ids.shift();
  	showSlideShow(id);
  	slideshow_ids.push(id);
  	setTimeout('autoRunSlideShow();', 5000);
  }
  
  	function FrontGalleryItem(icon, full, thumb, material){
  		this.icon     = icon.replace(' ', '%20');
  		this.full     = full.replace(' ', '%20');
  		this.material = material;
  		this.thumb    = thumb.replace(' ', '%20');
  	}
  	function FrontGallery(){
  		this.images  = new Array();
  		this.items   = new Array();
  		this.visible = new Array();
  		this.top     = null;
  		this.topname = null;
  		this.toplock = 0;
  		
  		this.add     = function(image){this.images.push(image);}
  		this.addRaw  = function(icon, full, thumb, mat){this.add(new FrontGalleryItem(icon, full, thumb, mat));}
  		this.init    = function(){
  			var elems  = document.getElementsByTagName('div');
  			var me     = null;
  			for(var i in elems){
  				if(!elems[i].className) continue;
  				if(!hasClass(elems[i], 'frontgallery')) continue;
  			  me = elems[i];
  			  break;
  			}
  			if(!me) return;
  			for(var i in me.childNodes){
  				if(!me.childNodes[i].className) continue;
  				else if(hasClass(me.childNodes[i], 'gallerytop')) this.top = me.childNodes[i];
  				else if(hasClass(me.childNodes[i], 'gallerytopname')) this.topname = me.childNodes[i];  				
  				else if(!hasClass(me.childNodes[i], 'galleryitem')) continue;
  				else this.items.push(me.childNodes[i]);
  		  }
  		  for(var i=0; i<8; ++i) this.run();
  		  setInterval('frontGallery.run();', 10000);
  		}
  		this.getImg = function(item){
  			var elems = item.getElementsByTagName('img');
  			if(elems.length>0) return elems[0];
  			else{
  				item.innerHTML = '<img src="" alt="Voorbeeld" />';
  				return this.getImg(item);
  			}
  		}
  		this.setTop = function(item, lock){
  			if(this.toplock>0 && !lock){
  				this.toplock--;
  			  return;
  			}
  			else if(lock) this.toplock = lock;
  			
 			  var iurl = this.getImg(item);
 			  if(iurl) iurl = iurl.src;
 			  for(var i in this.images){
 				  if(iurl.indexOf(this.images[i].icon)==-1) continue;
 				  var mimg = this.getImg(this.top);
 				  if(mimg) mimg.src = this.images[i].thumb;
 				  if(this.topname) this.topname.innerHTML = this.images[i].material;
 				  break;
 				}
  		}
  		this.setItem = function(item){
  			for(var i in this.visible){
  				if(this.visible[i]!=item) continue;
  				this.visible.splice(i, 1);
  				item.style.display = 'none';
  				this.setTop(item, true);
  				this.run();
  				break; 
  			}
  		}
  		this.run = function(){
  			if(this.visible.length>=6){
  				var item = this.visible.shift();
  				item.style.display = 'none';
  				this.setTop(item, false);
  			}

 				var max  = this.items.length;
 				var rnd  = 0;//Math.floor(Math.random()*max);
 				var item = null;//this.items[rnd];
 				do{
 				  rnd  = Math.floor(Math.random()*max);
 				  item = this.items[rnd];
 				}while(item==null || item.style.display=='block');
 				var par = item.parentNode;
 				par.removeChild(item);
 				par.appendChild(item);
 				item.style.display = 'block';
 				this.visible.push(item);
  		}
  	}
  	var frontGallery = new FrontGallery();

