var _callBackFunction = null;

var _baseURLcollection = "http://www.nomad.info/";
var _baseURLajax = "http://www.nomad.info/collectionAjax.asp?q=";

var _ajaxResponse = null;
var _currentBoxToAppand = null;
var _alastCall = [];
var _poslastCall = 0;
var _blnLastCall = false;
var _lastTypeResponse = "";
var _bcp = null;

function initCollection(){
	hoverProduct($('body'));
	initCarusel($('body'));
	initCarusel2($('body'));
	
	 _currentBoxToAppand = $('#rubrieken').parent();
	$('ul.product li a').each(function(i){
		$(this).click(doClickProduct);
	});
	$('ul.big-buttons li a').each(function(i){
		$(this).click(doClickBigButton);
	});
	
	_bcp = $('div.bread-crumb ul');
	
	_alastCall[_poslastCall++] = document.location.href;
	$('.btn-vorige a', $('div.bread-crumb')).click(doPreLastCall);
	
	initProduct();
	
	initProductLarge();
}

function initProductLarge() {
	$('a[rel=product-image-large]').click(function() {
		$('.product-detail-overlay .product-foto').attr('src', this.href);
		$('.product-detail-overlay').fadeIn("750");
		
		return false;
	});
	
	$('.product-detail-overlay .sluiten').click(function () {
		$('.product-detail-overlay').fadeOut("250");
		
		return false;
	});
}

// hover affects
function hoverProduct(_obj) {
	//_obj.removeAttr('style');
	
	//$('ul.product img',_obj).css({opacity:0.5});
	
	$('ul.product li',_obj).hover(function(){
		if (!$(this).is('.active'))
			$(this).addClass('hover');
		//find('img').animate({opacity:1},{queue:false, duration:250});
	}, function() {
		if (!$(this).is('.active'))
			$(this).removeClass('hover');
		//$(this).find('img').animate({opacity:0.5},{queue:false, duration:250});
	});
	//$('ul.product li.active img',_obj).css({opacity:1});

}

function doClickProduct(){
	if(!$(this).parent().hasClass('active')){
		//_bcp.append("<li class=\"second-link product\"><span>"+  +"</span></li>");
		//kruimelkopjeToevoegen($(this).attr('title'), "product");
		
		$(this).parents('ul.product')
			.find('li.active').removeClass('active');
			//.find('img').animate({opacity:0.5},{queue:false, duration:250});
		$(this).parent().addClass('active').removeClass('hover');
		doServerCall($(this).attr('href'));
	}
	return false;
}

function doClickBigButton(){ 
	if(!$(this).parent().hasClass('active')){
		//_bcp.append("<li class=\"second-link product\"><span>"+  +"</span></li>");
		//kruimelkopjeToevoegen($(this).attr('title'), "product");
		
		$(this).parents('ul.big-buttons')
			.find('li.active').removeClass('active');
			//.find('img').animate({opacity:0.5},{queue:false, duration:250});
		$(this).parent().addClass('active').removeClass('hover');
		doServerCall($(this).attr('href'));
	}
	return false;
}

function wizardAnsChange(sel,wizBaseURL,ansIds){
  if(ansIds!=''){
    ansIds+='-';
  }
  if(sel!=0){
	doServerCall(wizBaseURL+ansIds+sel.options[sel.selectedIndex].value+'/');
  }else{
	doServerCall(wizBaseURL+ansIds+0+'/');
  }
}

// carusel
function initCarusel(_obg) {
	$('div.box', _obg).galleryScroll({
		btPrev:'ul.gallery-btn li.back a',
		btNext:'ul.gallery-btn li.next a',
		holderList:'div.carrousel',
		scrollElParent:'div.carrousel ul.product-list',
		scrollEl:'div.carrousel ul.product-list > li',
		circleSlide:false,
		funcOnclick:doClickkert

	});
}

function doClickkert(newMargin){
	var currentMargin = parseInt($(this).find('div.carrousel').css('margin-left'));
	newMargin = parseInt(newMargin);
	if($(this).find('div.carrousel').css('margin-left') == "auto"){
		currentMargin = 0;	
	}
	//alert(newMargin);
	//alert(currentMargin);//.css('margin')
	var el = $(this).find('h3').find('.sIFR-alternate:last');
	var text = el.text();
	var slash = text.indexOf("/");
	var pos = parseInt(text.slice(slash - 1, slash + 1));
	//text = text[0].substr(0, text[0].length -1 );
	//alert(pos);
	//alert(newMargin);
	//alert(currentMargin);
	//if(newMargin != currentMargin){
		if(newMargin > currentMargin ){
			pos++;
		}else{
			pos--;
		}
		text = text.slice(0, slash-1) + ' ' + pos + text.slice(slash);
		
		//$(this).find('h3').find('.sIFR-alternate:last').text(text);
		$(this).find('h3').html("<span>" + text + "</span>");
		h3kopjes();
		//alert(text);
	//}
}

function initCarusel2(_obg) {
	$('div.small-gallery', _obg).galleryScroll({
		btPrev:'span.back a',
		btNext:'span.next a',
		holderList:'div',
		scrollElParent:'div > ul',
		scrollEl:'ul > li',
		circleSlide:false,
		caruType:'small'
	});
	//alert($('div.small-gallery', _obg).html());
	/*$('div.small-gallery', _obg).galleryScroll({
		btPrev:'span.back a',
		btNext:'span.next a',
		holderList:'div',
		scrollElParent:'div > ul',
		scrollEl:'ul > li',
		circleSlide:false
	});*/
}


//foto column van 2 naar 1 of andersom bewegen
function slideImageBox(){
	var imgColumn = $('div.img-column');
	//alert(imgColumn.css('width'));
	if(!imgColumn.hasClass('smallblock')){
		imgColumn.animate({left:632+314+16}, {queue:false,duration:400, complete:function(){
			$(this).addClass('smallblock');
			$(this).remove();
			doCallBackFunction();
		}});
	}else{
		imgColumn.animate({width:632}, {queue:false,duration:400, complete:function(){
			$(this).removeClass('smallblock');
			doCallBackFunction();
		}});
	}	
}

function doCallBackFunction(){
	if(_callBackFunction){
		_callBackFunction();
		_callBackFunction = null;
	}
}
function doPreLastCall(){
	if(_poslastCall > 1){
		var pos = _alastCall[_poslastCall -2 ];
		_poslastCall--;
		_poslastCall--;
		_blnLastCall = true;
		doServerCall(pos);
		return false;
	}else{
		return true;
	}

}
var rURL = "";
function doServerCall(_url){
	var len = _baseURLcollection.length;
	_alastCall[_poslastCall++] = _url;
	rURL = _url;
	_url = _url.substr(len,  _url.length  - _baseURLcollection.length);
	//alert(_url);
	
	pageTracker._trackPageview('/' + _url);
	
	_url = _baseURLajax + _url
	
	$('h3.loading').show();
	$.ajax({
		url: _url,
		dataType:'xml',
		error:function(XMLHttpRequest, textStatus, errorThrown){
			//alert(XMLHttpRequest);
			//alert(textStatus);
			//alert(errorThrown);
			//alert(rURL);
			document.location.href= rURL;
		},
		success: function(msg){
			$('h3.loading').hide();
			//alert(msg.data.type);
			//$("data", msg).each(function(){
			//	alert($(this).text())
			//	alert($(this).attr("type"));
			//});
			
			_ajaxResponse = msg;
      
			//rubriek data terug gekomen.
			if($("data", _ajaxResponse).attr("type") == "rubrieken"){
				if($('#categorieen').html() || $('#filter').html()){ // box images weer groter maken
					fadeColumnOut($('.col1'), function(){
						//$('.col1').html($("data", _ajaxResponse).text());
						$(this).remove();
						$('.columns-wrap').append("<div class=\"col1\">" + $("data", _ajaxResponse).text() + "</div>");
						fadeColumnIn($('.col1'), function(){
							resetCategorieen($('.col1'));
							initCategorieen($('.col1'));

						});
					});
					fadeColumnOut($('.col3'), function(){
						$(this).remove();
						//$('.img-column').html($("image", _ajaxResponse).text());
						$('.col1').after("<div class=\"img-column\">" + $("image", _ajaxResponse).text() + "</div>");
						fadeColumnIn($('.img-column'));
					});
					fadeColumnOut($('.col2'), function(){
						$(this).remove();
					});
				}
			}
			
			//filtered categorie data terug gekomen
			if($("data", _ajaxResponse).attr("type") == "filtered"){
			  	
			  	if(_lastTypeResponse == "producten"){ 
			    	fadeColumnOut($('.col3'), function(){
						$(this).remove();
					});

					//$('.col2').animate({left:642}, {queue:false,duration:400, complete:function(){
					fadeColumnOut($('.col2'), function(){
						$(this).remove();
						$('.col1').animate({left:318}, {queue:false,duration:400, complete:function(){
							$(this).removeClass('col1');
							$(this).attr('style', '');
							$(this).addClass('col2');
							
							$('.col2').before("<div class=\"col1\">" + $("data", _ajaxResponse).text() + "</div>");
		            		$('.col2').after("<div class=\"col3\">" + $("text", _ajaxResponse).text() + "</div>");
    						fadeColumnIn($('.col1'));
    						fadeColumnIn($('.col3'));
    						initCategorieen($('.col3'));
    						initCategorieen($('.col1'));
						}});
					});					
				}else{  
		          if($('#categorieen').html()){ 
		            if($('.img-column').html()){ 
		              fadeColumnOut($('.col2'), function(){
		        				$(this).remove();    
		        				 //alert($("image", _ajaxResponse).text())
		        				$('.col1').after("<div class=\"col2\">" + $("data", _ajaxResponse).text() + "</div>");
		        				fadeColumnIn($('.col2'));
		        				initCategorieen($('.col2'));
		        			});
		              fadeColumnOut($('.img-column'), function(){
		        				$(this).remove();    
		        				 //alert($("image", _ajaxResponse).text())
		        				$('.col2').after("<div class=\"col3\">" + $("data2", _ajaxResponse).text() + "</div>");
		        				fadeColumnIn($('.col3'));
		        				initCategorieen($('.col3'));
		        			});  
		            }else{            
		              fadeColumnOut($('.col3'), function(){
		              	$(this).remove();
		              });
		              fadeColumnOut($('.col2'), function(){
		        				$(this).remove();    
		        				 //alert($("image", _ajaxResponse).text())
		        				$('.col1').after("<div class=\"col2\">" + $("data2", _ajaxResponse).text() + "</div>");
		        				$('.col2').after("<div class=\"col3\">" + $("text", _ajaxResponse).text() + "</div>");
		      					fadeColumnIn($('.col2'));
		        				fadeColumnIn($('.col3'));
		      					initCategorieen($('.col2'));
		        			});
		      			}
		          }else{
		          		fadeColumnOut($('.col3'), function(){
		          			$(this).remove();
		          		});
		    			fadeColumnOut($('.col2'), function(){
		      				$(this).remove();    
		      				 //alert($("image", _ajaxResponse).text())
		      				$('.col1').after("<div class=\"col2\">" + $("data2", _ajaxResponse).text() + "</div>");
		      				$('.col2').after("<div class=\"col3\">" + $("text", _ajaxResponse).text() + "</div>");
		      				fadeColumnIn($('.col2'));
		      				fadeColumnIn($('.col3'));
		      				initCategorieen($('.col2'));
		      			});
				  }
			  }
			  
			}
			
			//categorie data terug gekomen
			if($("data", _ajaxResponse).attr("type") == "categorieen"){
		  		//if(_lastTypeResponse == "wizard"){ 
			    	fadeColumnOut($('.col3'), function(){
						$(this).remove();
					});

					//$('.col2').animate({left:632}, {queue:false, duration:400, complete:function(){
					fadeColumnOut($('.col2'), function(){
						$(this).remove();
						//$(this).addClass('img-column');
						//$(this).addClass('smallblock');
						//resetCategorieen($('.img-column'));   
            
		            	$('.col1').after("<div class=\"col2 o-image\">" + $("image", _ajaxResponse).text() + "</div>");
	    					fadeColumnIn($('.col2'));
	    					initCategorieen($('.col2'));
	    					resetCategorieen($('.col2'));	
	    					$('.col2').after("<div class=\"col3\">" + $("text", _ajaxResponse).text() + "</div>");
	  						//$('.img-column').addClass('smallblock');
	  						fadeColumnIn($('.col3'));
	  						//});
						//}}
					});
				/*}else{
  					if($('.col3').html()){		//er word een plaatje verwacht in paneel 3 dus neerzetten
  						fadeColumnOut($('.col2'), function(){
  							$(this).remove();
  							$('.col1').after("<div class=\"col2 o-image\">" + $("image", _ajaxResponse).text() + "</div>");
  							fadeColumnIn($('.col2'));
  							initCategorieen($('.col2'));
  							
  							$('.col2').after("<div class=\"col3\">" + $("text", _ajaxResponse).text() + "</div>");
	  						//$('.img-column').addClass('smallblock');
	  						fadeColumnIn($('.col3'));
  						});
  						resetCategorieen($('.col2'));
  					}
        		}*/    
				if($('#categorieen').html()){ // bij bestaande categorie column vervangen....	
					if(_lastTypeResponse != "producten" || _lastTypeResponse != "wizard" || !_blnLastCall){
						fadeColumnOut($('.col2'), function(){
							$(this).remove();
							$('.col1').after("<div class=\"col2\">" + $("data", _ajaxResponse).text() + "</div>");
							fadeColumnIn($('.col2'));
							initCategorieen($('.col2'));
						});
            
  					if($('#wizard').html() || ($("image", _ajaxResponse).text()).search(/wizard/i)>-1){
  					  fadeColumnOut($('.img-column'), function(){
  							$(this).remove();
  							 //alert($("image", _ajaxResponse).text())
  							$('.col2').after("<div class=\"img-column\">" + $("image", _ajaxResponse).text() + "</div>");
  							$('.img-column').addClass('smallblock');
  							fadeColumnIn($('.img-column'));
  							initCategorieen($('.img-column'));
  						});
  					}
					}else{
						resetCategorieen($('.col2'));
					}
				}else if($('#filter').html()){
				  	fadeColumnOut($('.col2'), function(){
						$(this).remove();
						$('.col1').after("<div class=\"col2\">" + $("data", _ajaxResponse).text() + "</div>");
						fadeColumnIn($('.col2'));
						initCategorieen($('.col2'));
					});
				}else{
					//rubrieken uit het beeld halen
					$('.col1').animate({left:-314}, {queue:false, duration:400, complete:function(){
						$(this).remove();
            		}});
					
					//bij nieuwe categorie ruimte maken en content plaatsen
					_callBackFunction = function(){
						//alert($("image", _ajaxResponse).text());
						$('.columns-wrap').append("<div class=\"col1\">" + $("data", _ajaxResponse).text() + "</div>");
						fadeColumnIn($('.col1'));
						initCategorieen($('.col1')); 
						//if(($("image", _ajaxResponse).text()).search(/wizard/i)>-1){
  					  		//fadeColumnOut($('.img-column'), function(){
  								$(this).remove();
  								$('.col1').after("<div class=\"col2  o-image\">" + $("image", _ajaxResponse).text() + "</div>");
  								$('.col2').after("<div class=\"col3\">" + $("text", _ajaxResponse).text() + "</div>");
  								//$('.img-column').addClass('smallblock');
  								fadeColumnIn($('.col2'));
  								fadeColumnIn($('.col3'))
  								initCategorieen($('.col2'));
  							//});
  						//}
					}
					slideImageBox(); //box even op de goede breedte zetten
				}
			}
			
			//wizzard
			if($("data", _ajaxResponse).attr("type") == "wizard"){	
				if(_lastTypeResponse == "producttext"){		//actie voor vorige
					fadeColumnOut($('.col2'), function(){
						$(this).remove();
					});
					fadeColumnOut($('.col3'), function(){
						$(this).remove();
						
						$('.col1').animate({left:632}, {queue:false,duration:400,complete:function(){
							$(this).removeClass('col1');
							$(this).removeAttr('style');
							$(this).addClass('col3');
	
							$('.col3').before("<div class=\"col2\">" + $("wizard", _ajaxResponse).text() + "</div>");
							$('.col2').before("<div class=\"col1\">" + $("data2", _ajaxResponse).text() + "</div>");
							
							fadeColumnIn($('.col2'));
							initCategorieen($('.col2'));
							fadeColumnIn($('.col1'));
							initCategorieen($('.col1'));
							}
							});
		 				/*$('.col-1').animate({left:314}, {queue:false,duration:400, complete:function(){
								$(this).removeClass('col-1');
								$(this).removeAttr('style');
								$(this).addClass('col2');
							}});
						$('.col-2').animate({left:4}, {queue:false,duration:400, complete:function(){
								$(this).removeClass('col-2');
								$(this).removeAttr('style');
								$(this).addClass('col1');			
								}}
						);*/
						
					});
				}else{
        if($('.col2 #wizard').html()){
          fadeColumnOut($('.col2'), function(){
						$(this).remove();
						$('.col1').after("<div class=\"col2\">" + $("wizard", _ajaxResponse).text() + "</div>");
						fadeColumnIn($('.col2'));
						initCategorieen($('.col2')); 
					});
          fadeColumnOut($('.col3'), function(){
						$(this).remove();
						$('.col2').after("<div class=\"col3\">" + $("data", _ajaxResponse).text() + "</div>");
						fadeColumnIn($('.col3'));
						initCategorieen($('.col3')); 
					});  
        }else{
    	    //schuiven met panelen en product toevoegen.
    		  fadeColumnOut($('.col2'), function(){
    					$(this).remove();
    				});
          
          //Transform img-column to col3
    			//$('.img-column').addClass('col3');
    			//$('.img-column').removeClass('smallblock');
          //$('.img-column').removeClass('img-column');	
    			 
    			$('.img-column').css({left:632});
    			$('.img-column').animate({left:322}, {queue:false,duration:400, complete:function(){
    					//$(this).removeClass('img-column');
    					//$(this).addClass('col2');   
              
              			$('.img-column').after("<div class=\"col3\">" + $("data", _ajaxResponse).text() + "</div>");
    					fadeColumnIn($('.col3'));
    					initCategorieen($('.col3'));
              
              			fadeColumnOut($('.img-column'), function(){
  							$(this).remove();
  							$('.col1').after("<div class=\"col2\">" + $("wizard", _ajaxResponse).text() + "</div>");
  							fadeColumnIn($('.col2'));
  							initCategorieen($('.col2')); 
  						}); 
  					}}
    			); 
    		}
        }					
			}
//alert($("data", _ajaxResponse).attr("type"));			
			//product overzicht is teruggekomen.
			if($("data", _ajaxResponse).attr("type") == "producten"){
			
				if($('#producten').html()){ // bij bestaan product vervangen..
					if(_lastTypeResponse == "producttext"){		//actie voor vorige
						fadeColumnOut($('.col2'), function(){
							$(this).remove();
						});
						fadeColumnOut($('.col3'), function(){
							$(this).remove();
							
							$('.col1').animate({left:314}, {queue:false,duration:400,complete:function(){
								$(this).removeClass('col1');
								$(this).removeAttr('style');
								$(this).addClass('col2');

								//$('.col1').after("<div class=\"col2\">" + $("data", _ajaxResponse).text() + "</div>");
								$('.col2').before("<div class=\"col1\">" + $("data2", _ajaxResponse).text() + "</div>");
								
								$('.col2').after("<div class=\"col3\">" + $("text", _ajaxResponse).text() + "</div>");
								//fadeColumnIn($('.col2'));
								fadeColumnIn($('.col1'));
								fadeColumnIn($('.col3'));
								initCategorieen($('.col1'));
							
								}
							});
								
							
							
							
						});
					}else{
						fadeColumnOut($('.col2'), function(){
							$(this).remove();
						});
						//productoverizicht vervangen.
						fadeColumnOut($('.col3'), function(){
							$(this).remove();
							$('.col1').after("<div class=\"col2\">" + $("data", _ajaxResponse).text() + "</div>");
							$('.col2').after("<div class=\"col3\">" + $("text", _ajaxResponse).text() + "</div>");
							fadeColumnIn($('.col2'));
							fadeColumnIn($('.col3'));
							initCategorieen($('.col2'));
							
						});
					}
				}else{
				  
				  //schuif eventueel filter weg
  			  	if($('#filter').html()){
  			  		 _callBackFunction = function(){
  						$('.col1').after("<div class=\"col2\">" + $("data", _ajaxResponse).text() + "</div>");
  						$('.col2').after("<div class=\"col3\">" + $("text", _ajaxResponse).text() + "</div>");
  						fadeColumnIn($('.col2'));
  						fadeColumnIn($('.col3'));
  						
  						initCategorieen($('.col2'));
  					}
  						fadeColumnOut($('.col3'), function(){
  							$(this).remove();
  						});
            			fadeColumnOut($('.col1'), function(){
  							$(this).remove();
  						});
    				$('.col2').animate({left:0}, {queue:false,duration:400, complete:function(){
    					$(this).removeClass('col2');
    					$(this).removeAttr('style');
    					$(this).addClass('col1');
    					doCallBackFunction();
    				}});
            
  					
  			  }else{ 
				  
  					//bij nieuwe ruimte maken en doorgaan
  					_callBackFunction = function(){
  						$('.col1').after("<div class=\"col2\">" + $("data", _ajaxResponse).text() + "</div>");
  						$('.col2').after("<div class=\"col3\">" + $("text", _ajaxResponse).text() + "</div>");
  						fadeColumnIn($('.col2'));
  						fadeColumnIn($('.col3'));
  						initCategorieen($('.col2'));
  					}
  					fadeColumnOut($('.col3'), function(){
  						$(this).remove();
  					});
  					fadeColumnOut($('.col2'), function(){
  						$(this).remove();
  						doCallBackFunction();
  					});
					}
				}
			}
			
			
			//product detail pagina
			if($("data", _ajaxResponse).attr("type") == "producttext"){
				if($('#producttext').html()){	//product vervangen
					fadeColumnOut($('.col2'), function(){	$(this).remove(); });
					fadeColumnOut($('.col3'), function(){
						$(this).remove();
						$('.col1').after("<div class=\"col3\">" + $("data", _ajaxResponse).text() + "</div>");
						$('.col1').after("<div class=\"col2\">" + $("data2", _ajaxResponse).text() + "</div>");
						initProduct();
						fadeColumnIn($('.col2'));
						fadeColumnIn($('.col3'));
					});
				}else{
					//schuiven met panelen en product toevoegen.
					//alert(_lastTypeResponse);
					if(_lastTypeResponse == "wizard"){
						fadeColumnOut($('.col2'), function(){
							$(this).remove();
						});
						fadeColumnOut($('.col1'), function(){
							$(this).remove();
							$('.col3').css({left:632});
							$('.col3').animate({left:4}, {queue:false,duration:400, complete:function(){
									$(this).removeClass('col3');
									$(this).addClass('col1');
									$(this).after("<div class=\"col3\">" + $("data", _ajaxResponse).text() + "</div>");
									$(this).after("<div class=\"col2\">" + $("data2", _ajaxResponse).text() + "</div>");
									initProduct();
									fadeColumnIn($('.col2'));
									fadeColumnIn($('.col3'));
			
									}}
							);
						});
					}else{
					
						fadeColumnOut($('.col3'), function(){
							$(this).remove();
						});
						fadeColumnOut($('.col1'), function(){
							$(this).remove();
							$('.col2').css({left:314});
							$('.col2').animate({left:4}, {queue:false,duration:400, complete:function(){
									$(this).removeClass('col2');
									$(this).addClass('col1');
									$(this).after("<div class=\"col3\">" + $("data", _ajaxResponse).text() + "</div>");
									$(this).after("<div class=\"col2\">" + $("data2", _ajaxResponse).text() + "</div>");
									initProduct();
									fadeColumnIn($('.col2'));
									fadeColumnIn($('.col3'));
			
									}}
							);
						});
						/*$('.col1').animate({left:-632}, {queue:false,duration:400,complete:function(){
							$(this).removeClass('col1');
							$(this).addClass('col-2');
							$(this).remove();
							}
						});
						$('.col3').animate({left:-314}, {queue:false,duration:400, complete:function(){
								$(this).removeClass('col2');
								$(this).addClass('col-1');
							}});
							*/
					}
				}
				
			}
			//_bcp.html($("bread", _ajaxResponse).text());
			_bcp.find('li').each(function(i){
				if(i > 0){
					$(this).remove();
				}
			})
			_bcp.append($("bread", _ajaxResponse).text());
			kruimelkopjes();

			_lastTypeResponse = $("data", _ajaxResponse).attr("type");
			_blnLastCall = false;
		}

	});
}

/*
Functie
*/
function fadeColumnIn(el, callback){
	if(!$.browser.msie){	//ie 6 zegt wil niet..
		el.css({opacity:0});
		el.animate({opacity:1}, {queue:false,duration:400, complete:callback});
	}else{	
		if(callback){
			callback();
		}
	}
}

function fadeColumnOut(el, callback){
	el.animate({opacity:0}, {queue:false,duration:400, complete:callback});
}

function initProduct(){
	h3kopjes();
	initTabs();
	
	$('.termhighlight').fancybox({
		hideOnContentClick:	false,
		zoomSpeedIn:		0,
		zoomSpeedOut:		0,
		frameWidth:			520,
		frameHeight:		380,
		overlayShow:		true,
		overlayOpacity:		0.5,
		itemLoadCallback:	null
	});

/*	var _heightParent = $('img.big-product').parent().height() - 72;
	var _thisIMGheight = $('img.big-product').height();
	$('img.big-product').css('marginTop',(_heightParent-_thisIMGheight)/2);*/

	$('.columns-wrap').galleryLight({
		galleryList: '.small-gallery ul li a',
		largeIMG: 'img.big-product',
		largeIMGcon: 'a.product-image-large'
	});
							
	initCarusel2($('.col2'));
	initCarusel2($('.col3'));
	
	initProductLarge();
}

function resetCategorieen(el){
	$('ul.product', el).find('li.active').removeClass('active');
	//.find('img').animate({opacity:0.5},{queue:false, duration:250});
}

function initCategorieen(el){
	//alert('init');
	hoverProduct(el);
	h3kopjes();
	initCarusel(el);
	_currentBoxToAppand = el;
	$('ul.product li a', el).each(function(i){
		$(this).click(doClickProduct);
	});
	$('ul.big-buttons li a', el).each(function(i){
		$(this).click(doClickBigButton);
	});
}

$(document).ready(initCollection);