$(".product_overlay").hide();

function Group(name,code,products,linkedGroups,active){
	this.name 			= name;
	this.code 			= code;
	this.products		= products;
	this.linkedGroups 	= linkedGroups;
	this.active			= active;
}

function Product(URLname,name,id,image,pdf,description){
	this.name 			= name;
	this.id 			= id;
	this.image 			= image;
	this.pdf 			= pdf;
	this.description 	= description;
	this.URLname        = URLname;
}

var Amazone 			= new Product("amazone","NESCAF&Eacute; Amazone",1,"nescafe_amazone.jpg","amazone_brochure.pdf","De kleinste koffiemachine. Met perfecte koffie voor wie alléén koffie wil. Schenkt tot 150 kopjes koffie per uur. eenvoudig in bediening en onderhoud. ");
var Amazone_l 			= new Product("amazone_l","NESCAF&Eacute; Amazone L",2,"nescafe_amazone_l.jpg","amazone_l_brochure.pdf","Koffie en heet water, plus heerlijke hot chocolate. Klein, snel en simpel. Ieder kopje koffie vers gezet, binnen enkele seconden. Met een druk op de knop de lekkerste koffie en hot chocolate, tot wel 150 kopjes koffie per uur.");
var Amazone_xl 			= new Product("amazone_xl","NESCAF&Eacute; Amazone XL",3,"nescafe_amazone_xl.jpg","amazone_xl_brochure.pdf","De uitgebreidste NESCAFÉ Amazone koffiemachine, met maar liefst 10 koffievariaties inclusief heet water. Iedere koffievariant klaar met een druk op de knop,tot 200 kopjes koffie per uur.");



var Colombia 			= new Product("colombia","NESCAF&Eacute; Colombia",4,"nescafe_colombia.jpg","colombia_brochure.pdf","De snelheidskoffiemachine. Schenkt tot 10 liter koffie in maar 2 minuten (tot 1000 koppen koffie per uur). In slechts 4 seconden beschikt u over een  heerlijk vers kopje koffie, 24 uur per dag.");
var Colombia_s 			= new Product("colombia_s","NESCAF&Eacute; Colombia S",5,"nescafe_colombia_s.jpg","colombia_s_brochure.pdf","Met een minimum aan ruimtebeslag en een maximum aan capaciteit. In hoogte verstelbaar. 500 kopjes koffie per uur, een literkan koffie in 40 seconden.");
var Vista_quick 		= new Product("vista_quick","NESCAF&Eacute; Vista Quick",6,"nescafe_vista_quick.jpg","vista_quick_brochure.pdf","De design koffiemachine. Lekkere looks met lekker veel koffievariatie. Van espresso tot macchiato , van zwarte koffie tot cappuccino. Schenkt tot 300 koppen koffie per uur. Met innovatief touchscreen.");
var Cappuccino 			= new Product("nescafe_cappuccino_black_edition","NESCAF&Eacute; Cappuccino Black Edition",7,"nescafe_cappuccino_black.jpg","cappuccino_black_brochure.pdf","De koploper in koffievariatie. De roestvrij stalen koffiemachine schenkt 10 koffievariaties, plus hot chocolate en heet water. Een keer vullen voor ruim 900 koffieconsumpties.");
var Cappuccino_select 	= new Product("cappuccino_select_edition","NESCAF&Eacute; Cappuccino Select Edition",8,"nescafe_cappuccino_select.jpg","cappuccino_select_brochure.pdf","Met 8 koffievariaties, plus hot chocolate en heet water. Snel, krachtig en compact. En zoals al onze koffiemachines: afval-. tijd- en dus kostenbesparend.");
var Compact_one 		= new Product("compact_one","NESCAF&Eacute; Compact One",10,"nescafe_compact_one.jpg","compact_one_brochure.pdf","Compact koffiekanon. Schenkt 700 koffieconsumpties per uur, met één druk op de knop. Topkwaliteit koffiemelanges en natuurlijk met een aparte koffiekannentoets. Afval-, ruimte-en tijdbesparend.");
var Crane_genesis 		= new Product("crane_genesis","NESCAF&Eacute; Crane Genesis",11,"nescafe_crane_genesis.jpg","crane_genesis_brochure.pdf","Compacte volautomaat. 10 warme koffievariaties plus koud water. Twee uitschenkposities, inclusief automatische suiker- en melkdosering. Lekbak- en bekersensor. Optioneel betaalsysteem.");
var Crane_evolution 	= new Product("crane_evolution","NESCAF&Eacute; Crane Evolution",12,"nescafe_crane_evolution.jpg","crane_evolution_brochure.pdf","De nieuwste generatie in koffiemachines. Met 12 heerlijke koffievariaties plus heet water. Een volautomaat met maximale capaciteiten, automatisch spoelprogramma en ruimte voor 600 koffiebekers. En de mogelijkheid van soep.");
var Crane_m675 			= new Product("crane_m675","NESCAF&Eacute; Crane M675",13,"nescafe_crane_m675.jpg","crane_m675_brochure.pdf","De full-operating koffiegigant. Doet bijna al het werk zelf, van handdouche tot afzuigsysteem en  automatisch spoelprogramma. Ruimte voor 1100 koffiebekers. Geschikt voor elk betaalsysteem.");
var Mini_cafe 			= new Product("mini_cafe","NESCAF&Eacute; Mini Caf&eacute;",14,"nescafe_mini_cafe.jpg","mini_cafe_brochure.pdf","Kleine wonder koffiemachine. Schenkt 10 heerlijke koffie- en chocovariaties. Met scroll-functie voor keuze koffievariatie en instructies via tekst in display. De meeste koffievariatie per vierkante cm.");
var Komo 				= new Product("komo","NESCAF&Eacute; Komo",15,"nescafe_komo.jpg","komo_brochure.pdf","De eerste echte small business koffiemachine. Vijf heerlijke koffievariaties voor gasten en medewerkers. Compact tafelmodel met grootse koffiesmaken voor een klein prijsje. En er is geen wateraansluiting noodzakelijk. Ideaal voor MKB.");
var Coffee_on_the_spot	= new Product("coffee_on_wheels","NESCAF&Eacute; Coffee on wheels",16,"nescafe_coffee_on_the_spot.jpg","coffee_on_the_spot_brochure.pdf","NESCAFÉ biedt u de oplossing om op elk gewenst moment en op iedere locatie de lekkerste koffievariaties aan te kunnen bieden. Dat kan nu met de nieuwe NESCAFÉ Coffee on Wheels, zonder snoer, dus overal een lekker kopje verse Cappuccino of toch liever Wiener Melange?");
var Vista_quick_koud_water		= new Product("vista_quick_koud_water","NESCAF&Eacute; Vista Quick Koud Water",19,"nescafe_vista_quick_koud_water.jpg","vista_quick_koud_water_brochure.pdf","De design koffiemachine. Lekkere looks met lekker veel koffievariatie en koud water. Geen aparte watertank meer nodig, alles in één machine. Schenkt tot 300 koppen koffie per uur. Met innovatief touchscreen.");


var allProductsArray	= new Array(Amazone,Amazone_l,Amazone_xl,Colombia,Colombia_s,Vista_quick,Cappuccino,Cappuccino_select,Compact_one,Crane_genesis,Crane_evolution,Crane_m675,Mini_cafe,Komo);

var productenArray 	= new Array();
productenArray[0]	= new Array(Amazone,Amazone_l,Colombia_s,Komo,Mini_cafe);
productenArray[1]	= new Array(Coffee_on_the_spot,Amazone,Amazone_l,Compact_one,Colombia_s,Komo,Mini_cafe);
productenArray[2]	= new Array(Vista_quick_koud_water,Coffee_on_the_spot,Amazone,Amazone_l,Amazone_xl,Vista_quick,Compact_one,Colombia_s,Cappuccino,Cappuccino_select,Crane_genesis);
productenArray[3]	= new Array(Vista_quick_koud_water,Coffee_on_the_spot,Vista_quick,Compact_one,Colombia,Colombia_s,Cappuccino,Cappuccino_select,Crane_genesis,Crane_evolution,Crane_m675);
productenArray[4]	= new Array(Vista_quick_koud_water,Coffee_on_the_spot,Compact_one,Colombia,Colombia_s,Vista_quick,Cappuccino,Cappuccino_select,Crane_genesis,Crane_evolution,Crane_m675);

var gebruikersGroupArr							= new Array();
gebruikersGroupArr[gebruikersGroupArr.length]	= new Group("1-10","option1",productenArray[0],new Array("1","2","3","4","7"),1);
gebruikersGroupArr[gebruikersGroupArr.length] 	= new Group("11-30","option2",productenArray[1],new Array("1","2","3","4","6","7"),1);
gebruikersGroupArr[gebruikersGroupArr.length] 	= new Group("31-50","option3",productenArray[2],new Array("1","2","3","4","5","6"),1);
gebruikersGroupArr[gebruikersGroupArr.length] 	= new Group("51-100","option4",productenArray[3],new Array("1","3","4","5","6"),1);
gebruikersGroupArr[gebruikersGroupArr.length] 	= new Group("100 of meer","option5",productenArray[4],new Array("1","3","4","5","6"),1);

var productenArray 	= new Array();
productenArray[0]	= new Array(Amazone,Colombia,Colombia_s,Compact_one,Komo);
productenArray[1]	= new Array(Amazone_l);
productenArray[2]	= new Array(Mini_cafe,Amazone_xl,Vista_quick,Cappuccino,Cappuccino_select,Crane_genesis,Crane_evolution,Crane_m675);
productenArray[3]	= new Array(Vista_quick_koud_water,Crane_evolution);
productenArray[4]	= new Array(Crane_genesis,Crane_evolution,Crane_m675);
productenArray[5]	= new Array(Coffee_on_the_spot);
productenArray[6]	= new Array(Komo);

var variatieGroupArr						= new Array();
variatieGroupArr[variatieGroupArr.length] 	= new Group("Alleen koffie en heet water","option1",productenArray[0],new Array("1","2","3","4"),1);
variatieGroupArr[variatieGroupArr.length] 	= new Group("Alleen koffie, hot chocolate en heet water","option2",productenArray[1],new Array("1","2","3"),1);
variatieGroupArr[variatieGroupArr.length] 	= new Group("Koffie, hot chocolate, heet water en meer koffievariaties (zoals cappuccino, espresso en meer)","option3",productenArray[2],new Array("1","2","3","4"),1);
variatieGroupArr[variatieGroupArr.length] 	= new Group("Koffievariaties, heet water en koud water","option4",productenArray[3],new Array("3","4"),1);
variatieGroupArr[variatieGroupArr.length] 	= new Group("Volautomaat (automatische bekeruitgifte)","option5",productenArray[4],new Array("3","4"),1);
variatieGroupArr[variatieGroupArr.length] 	= new Group("Mobiele koffievoorziening met koffievariaties","option6",productenArray[5],new Array(),1);
variatieGroupArr[variatieGroupArr.length] 	= new Group("Geen vaste wateraansluiting nodig (maar wel koffievariaties)","option7",productenArray[6],new Array("1","2"),1);

var selection1 				= '';
var selection2 				= '';
var gebruikersGroup 		= '';
var variatieGroup			= '';
var variatieGroupObj 		= '';
var gebruikersGroupObj	    = '';

function setFirstSelection(option){

    //set a cookie so selection is saved during site visit
    setCookie('userType',option.id,'');
	// if the option for show all (option6) has been selected then hide that layer and reset the selections
	if(option.id == 'option6'){
		reset();
	} else {
	
		//Turn off the 'show all/Toon alles' option.
		document.getElementById("option6").getElementsByTagName("IMG")[0].src = 'images/vis_producten_radio_off.gif';
		document.getElementById("option6").style.fontWeight = '';
		
		// retrieve the currently active object for the usersgroup. (this gets set global)
		for(i=0;i<gebruikersGroupArr.length;i++){
			if(option.id == gebruikersGroupArr[i].code){
				gebruikersGroupObj = gebruikersGroupArr[i];
			}
		}
		
		// Check if the currently clicked group has not been disabled because of a previously made selection.
		if(gebruikersGroupObj.active == 1){
			
			//document.getElementById('overlaydiv1').style.display = 'none';
			
			if(selection1 != ''){
				selection1.getElementsByTagName("IMG")[0].src = 'images/vis_producten_radio_off.gif';
				selection1.style.fontWeight = '';
				
			}
			
			var divElement 		= option;
			var imageElement 	= option.getElementsByTagName("IMG")[0];
			
			imageElement.src = 'images/vis_producten_radio_on.gif';
			divElement.style.fontWeight = 'bold';
			
			selection1 = divElement;
			
			if(selection1 && selection2){
				getActiveMachines();
			}
			
			// Enable/disable buttons in the second selection div element.
			var secondPanel = document.getElementById("secondSelectionDiv");
			var tdElements	= secondPanel.getElementsByTagName("TD");
			
			// Turn all variation group items off
			for(i=0;i<variatieGroupArr.length;i++){
				variatieGroupArr[i].active = 0;
			}
			
			for(i=0;i<tdElements.length;i++){
			
			
			
				if(tdElements[i].id != ""){
					// Make current object appear transparent (off)
					$("#"+tdElements[i].id).addClass("transparent50");
					
					for(j=0;j<gebruikersGroupObj.linkedGroups.length;j++){
						
						if(tdElements[i].id.indexOf("option"+gebruikersGroupObj.linkedGroups[j]) != "-1"){
							// Turn a single item on.
							arrIndex 				= gebruikersGroupObj.linkedGroups[j] - 1;
							variatieGroupObj 		= variatieGroupArr[arrIndex];
							variatieGroupObj.active	= 1;
							
							$("#"+tdElements[i].id).removeClass("transparent50");
						}
					}
				}
			}
		}
	}
	$('a[href$="mini_cafe"]').attr('href','javascript:getPDPTemplateVersion();');
}

function setSecondSelection(option){

	setCookie('productType',option,'');
	
	for(i=0;i<variatieGroupArr.length;i++){
		if(option == variatieGroupArr[i].code){
			variatieGroupObj = variatieGroupArr[i];
		}
		 
	}
	
	if(variatieGroupObj.active == 1){
	   
		if(selection2 != ''){
		    
			document.getElementById(selection2+"Img").getElementsByTagName("IMG")[0].src = 'images/vis_producten_radio_off.gif';
			document.getElementById(selection2+"Txt").style.fontWeight = '';
		}
		
		var imageElement	= document.getElementById(option+"Img").getElementsByTagName("IMG")[0];
		var textElement 	= document.getElementById(option+"Txt");
		
		imageElement.src = 'images/vis_producten_radio_on.gif';
		textElement.style.fontWeight = 'bold';
		
		selection2 = option;
		
		getActiveMachines();
		$('a[href$="mini_cafe"]').attr('href','javascript:getPDPTemplateVersion();');
		
	}
}

function getActiveMachines(){
	for(i=0;i<gebruikersGroupArr.length;i++){
		if(gebruikersGroupArr[i].code == selection1.id){
			gebruikersGroup = gebruikersGroupArr[i];
		}
	}
	
	for(i=0;i<variatieGroupArr.length;i++){
		if(variatieGroupArr[i].code == selection2){
			variatieGroup = variatieGroupArr[i];
		}
	}
	
	var variatieProductenArr 	= variatieGroup.products;
	var gebruikersProductenArr 	= gebruikersGroup.products
	var actieveProducten		= new Array();
	
	for(i=0;i<variatieProductenArr.length;i++){
		for(j=0;j<gebruikersProductenArr.length;j++){
			if(gebruikersProductenArr[j].name == variatieProductenArr[i].name){
				actieveProducten[actieveProducten.length] = variatieProductenArr[i];
			}
		}
	}

	$("#producten").children(".product").remove();
	var totalCounter = 1;
	for(i=0;i<actieveProducten.length;i++){
		// Add a style to the last product item per row to removed the right margin.
		if(totalCounter % 5 == 0){
			nomargin = "style='margin-right:0px;'";
		} else {
			nomargin = "";
		}
		var html = getMachineHtml(actieveProducten[i].URLname, actieveProducten[i].name,actieveProducten[i].id,actieveProducten[i].description,actieveProducten[i].image,actieveProducten[i].pdf,actieveProducten[i].height,false,nomargin);
		$("#producten").append(html);
		totalCounter++;
	}
	
	for(i=0;i<allProductsArray.length;i++){
		var productIsInSelection = false;
		for(j=0;j<actieveProducten.length;j++){
			if(actieveProducten[j].name == allProductsArray[i].name){
				productIsInSelection = true;
			}
		}
		if(productIsInSelection == false) {
			// Add a style to the last product item per row to removed the right margin.
			if(totalCounter % 5 == 0){
				nomargin = "style='margin-right:0px;'";
			} else {
				nomargin = "";
			}
			var html = getMachineHtml(allProductsArray[i].URLname, allProductsArray[i].name,allProductsArray[i].id,allProductsArray[i].description,allProductsArray[i].image,allProductsArray[i].pdf,allProductsArray[i].height,true,nomargin);
			$("#producten").append(html);
			totalCounter++;
		}
	}
	$("#producten").append("<div style='clear:both;'></div>");
}
function getMachineHtml(URLname, name,id,description,image,pdf,height,inActive,nomargin){
	var html = '';
	
	if(inActive){
		html += "<div class='product' id='product"+id+"'>";
		html += "	<div style='position:absolute;left:0px;top:0px;background-color:#FFFFFF;height:166px;width:178px;cursor:pointer;' class='transparent' onclick='document.location.href=\"koffiemachine.aspx?naam="+URLname+"\";'></div>";
	} else {
		html += "<div class='product' id='product"+id+"' "+nomargin+" onmouseover='showOverlay(this)' onmouseout='hideOverlay(this)'>";
		html += "	<div class='product_overlay'>";
		html += "		<div class='product_overlay_top'></div>";
		html += "		<div class='product_overlay_middle'>";
		html += "			<h3 class='producten_overlay'>"+name+"</h3>";
		html += "			<div>"+description+"</div>";
		html += "			<div style='padding-top:6px;'>";
		html += "				<a href='koffiemachine.aspx?naam="+URLname+"' id='product"+id+"ReadMore' class='overlay_link'>";
		html += "					<img src='images/ic_arrow_small_red.gif' border='0' alt='' />&nbsp;<b>Meer informatie</b>";
		html += "				</a>";
		html += "			</div>";
		html += "		</div>";
		html += "		<div class='product_overlay_bottom'></div>";
		html += "	</div>";
	}
	html += "	<div class='product_top'>";
	html += "		<a href='koffiemachine.aspx?naam="+URLname+"' id='product"+id+"Img'>";
	html += "			<img src='images/producten/"+image+"' border='0' alt='Nescafé "+name+"' />";
	html += "		</a>";
	html += "	</div>";
	html += "	<div class='product_bottom'>";
	html += "		<a href='koffiemachine.aspx?naam="+URLname+"' class='linkblack'>";
	html += "			<b>"+name+"</b>&nbsp;<img src='images/ic_arrow_right.gif' border='0' alt='' />";
	html += "		</a>";
	html += "	</div>";
	html += "</div>";
	
	$(".product_overlay").hide();
	
	return html;
}
function reset(){
	document.location.reload();
}
function showOverlay(obj){
	obj.style.zIndex = 2;
	obj.getElementsByTagName("DIV")[0].style.display = "block";
}
function hideOverlay(obj){
	obj.style.zIndex = 1;
	obj.getElementsByTagName("DIV")[0].style.display = "none";
}