/**
 * Nestle Professional Product Filter.
 * Using XSLT, process and manage the filtering and display of products
 * Developed by David Shanley <david.shanley@europe.mccann.com>
 *  
 *  depends on mootools.
 * @author David Shanley
 */
var END_USER = 1;
var VENDING_OPERATOR = 1;
var USER_TYPE;

/* product data */
var productData = 'data.xml';
var DATA_XML;
var XML_DOM;
var XSL_DOM;


var Products = {
	initialize: function(){	
		this.mainfilter = $('firstfilter');
		
		//this.generateFirstFilter();
		this.generateSecondFilter();
		
		this.productarea = $('productarea');
		/* effects */
		this.effects = {
			mainfilter: new Fx.Tween(this.mainfilter)
		} 
		this.userType = null;
		this.businessSizeValue = null;
		this.machineType = null;
		this.loading = false;
		this.firstslide = true;
		
		this.effects.mainfilter.start('opacity','1');
		this.enableSecondFilter();
		
	},
	fadeInSecondFilter: function() {
		this.mainfilter.empty();
		this.generateSecondFilter();
		
		this.effects.mainfilter.start('opacity','1');
		this.enableSecondFilter();
	},
	fadeInThirdFilter: function(type) {
		this.mainfilter.empty();
		this.generateThirdFilter(type);
		this.initializeMachineTypeButtons();
		this.effects.mainfilter.start('opacity',1);
	},
	fadeInFourthFilter: function(type) {
		this.mainfilter.empty();
		this.generateFourthFilter(type);
		this.initializeSubTypeButtons(type);
		this.effects.mainfilter.start('opacity',1);
	},
	slideOutFirstFilter: function(user) {
		USER_TYPE=user;
		var fadeIn = this.fadeInSecondFilter.bind(this);
		this.effects.mainfilter.start('opacity',0).chain(fadeIn);
	},
	slideOutSecondFilter: function(type) {
		var fadeIn = this.fadeInThirdFilter.bind(this);
		this.effects.mainfilter.start('opacity',0).chain(function(){
			fadeIn(type)
		});
	},
	slideOutThirdFilter: function(type) {
		var fadeIn = this.fadeInFourthFilter.bind(this);
		this.effects.mainfilter.start('opacity',0).chain(function(){
			fadeIn(type)
		});
	},
	generateFirstFilter: function() {
		
		var userType = new Element('h4').set('text','Who Are you?');
		var enduserButton = new Element('div', { 'id' : 'enduser', 'class':'buttoncontent'}).set('text','End User');
		var operatorButton = new Element('div', { 'id' : 'vendingoperator', 'class':'buttoncontent'}).set('text','Operator');
		var endUserInfo = new Element('div', { 'id' : 'endUserInfo', 'class':'tipz','title':'End User :: You are the ultimate decision maker - responsible for coffee provision within a single or multi-site organisation. Let us give you a better understanding of what we can offer. '});
		var operatorInfo = new Element('div', { 'id' : 'operatorInfo', 'class':'tipz','title':'Operator :: Your business sells to the End User. You need specific information or advice about our brands and solutions to grow your business and better engage with customers. '});
		userType.injectInside(this.mainfilter);
		enduserButton.injectInside(this.mainfilter);
		endUserInfo.injectInside(this.mainfilter);
		operatorButton.injectInside(this.mainfilter);
		operatorInfo.injectInside(this.mainfilter);
		
		/* attach fx to the first filter */
		var slideFirstFilter = this.slideOutFirstFilter.bind(this);
		enduserButton.addEvent('click', function(){
			slideFirstFilter('enduser')
		});
		operatorButton.addEvent('click', function() { 
			slideFirstFilter('vendor')
		});
				
	},
	generateSecondFilter: function() {
		
		/* set up elements */
		this.businessSizeValues = new Element('p',{'style':'word-spacing:8px;'}).set('text','');
		this.bslider = new Element('div', { 'id' : 'bsize_slider', 'class' : 'slider'});
		this.bsliderKnob = new Element('div', { 'id' : 'bsize_slider_knob', 'class' : 'knob'});
		var numCupsValues = new Element('p',{'style':'word-spacing:px;'}).set('text','');
		this.cslider = new Element('div', { 'id' : 'csize_slider', 'class' : 'slider'});
		this.csliderKnob = new Element('div', { 'id' : 'csize_slider_knob', 'class' : 'knob'});
		
		var capacityHeader = new Element('h4').set('text','Capacity (choose one)');
		this.numEmployees = new Element('div', { 'id' : 'num_employees','class':'numemployees_button'}).set('text','Number of employees');
		this.numCups = new Element('div', { 'id' : 'num_employees','class':'numcups_button'}).set('text','Number of cups per day');
		
		/* dim slider until activation */
		this.bslider.setStyle('opacity','0.2');
	
		/* inject elements into DOM */
		capacityHeader.injectInside(this.mainfilter);
		this.numEmployees.injectInside(this.mainfilter);
		this.numCups.injectInside(this.mainfilter);
		this.bsliderKnob.injectInside(this.bslider);
		this.businessSizeValues.injectInside(this.mainfilter);
		this.bslider.injectInside(this.mainfilter);
		
		
	},
	generateThirdFilter: function(category) {
		var machineType = new Element('h4').set('text','Machine Type');
		this.incupButton = new Element('div', { 'id' : 'incup_button', 'class':'machinetypebutton'}).set('text','In-Cup');
		this.tabletopButton = new Element('div', { 'id' : 'tabletop_button', 'class':'machinetypebutton'}).set('text','Tabletop');
		this.vendingButton = new Element('div', { 'id' : 'tabletop_button', 'class':'machinetypebutton'}).set('text','Vending');
		this.tinSpoonButton = new Element('div', { 'id' : 'tinspoon_button', 'class':'machinetypebutton'}).set('text','Tin/Spoon');
		
		this.mainfilter.empty();
		
		/* inject */
		machineType.injectInside(this.mainfilter);
		
		if(category == 0) {
			this.tinSpoonButton.injectInside(this.mainfilter);
			this.incupButton.injectInside(this.mainfilter);
				
		}
		if(category == 1) {
			this.tinSpoonButton.injectInside(this.mainfilter);
			this.incupButton.injectInside(this.mainfilter);
			this.tabletopButton.injectInside(this.mainfilter);
			this.vendingButton.injectInside(this.mainfilter);
		}
		if(category == 2) {
			this.tinSpoonButton.injectInside(this.mainfilter);
			this.incupButton.injectInside(this.mainfilter);
			this.tabletopButton.injectInside(this.mainfilter);
			this.vendingButton.injectInside(this.mainfilter);
		}
		if(category == 3) {
			this.incupButton.injectInside(this.mainfilter);
			this.tabletopButton.injectInside(this.mainfilter);
			this.vendingButton.injectInside(this.mainfilter);
		}
		if(category == 4) {
			this.incupButton.injectInside(this.mainfilter);
			this.tabletopButton.injectInside(this.mainfilter);
			this.vendingButton.injectInside(this.mainfilter);
		}
	},
	generateFourthFilter: function(category) {
		var subCategory = new Element('h4').set('text','Product Type?');
		this.coffeeButton = new Element('div', { 'id' : 'coffee_button', 'class':'machinetypebutton'}).set('text','Coffee');
		this.hotchocButton = new Element('div', { 'id' : 'hotchoc_button', 'class':'machinetypebutton'}).set('text','Hot Chocolate');
		this.cappucinoButton = new Element('div', { 'id' : 'cappucino_button', 'class':'machinetypebutton'}).set('text','Cappucino');
		this.latteButton = new Element('div', { 'id' : 'latte_button', 'class':'machinetypebutton'}).set('text','Latte');
		this.mochaButton = new Element('div', { 'id' : 'mocha_button', 'class':'machinetypebutton'}).set('text','Mocha');
		this.espressoButton = new Element('div', { 'id' : 'espresso_button', 'class':'machinetypebutton'}).set('text','Espresso');
		this.solubleButton = new Element('div', { 'id' : 'soluble_button', 'class':'machinetypebutton'}).set('text','Soluble');
		this.beantocupButton = new Element('div', { 'id' : 'beantocup_button', 'class':'machinetypebutton'}).set('text','Bean to Cup');
		this.tradespressoButton = new Element('div', { 'id' : 'tradexpresso_button', 'class':'machinetypebutton'}).set('text','Traditional Expresso');
		this.bulkbrewpourButton = new Element('div', { 'id' : 'bulkbrewpour_button', 'class':'machinetypebutton'}).set('text','Bulk Brew');
		this.fairtrade_ttButton = new Element('div', { 'id' : 'fairtrade_ttbutton', 'class':'machinetypebutton'}).set('text','Fairtrade');
		this.premiummainButton = new Element('div', { 'id' : 'prmiummain_button', 'class':'machinetypebutton'}).set('text','Premium Main Stream');
		this.fairtrade_vendButton = new Element('div', { 'id' : 'fairtrade_vendbutton', 'class':'machinetypebutton'}).set('text','Fair Trade');
		this.premiumButton = new Element('div', { 'id' : 'premiumdbutton', 'class':'machinetypebutton'}).set('text','Premium');
		
		
		this.mainfilter.empty();
		
		/* inject */
		subCategory.injectInside(this.mainfilter);
		
		if(category == 'incup') {
			this.coffeeButton.injectInside(this.mainfilter);
			this.hotchocButton.injectInside(this.mainfilter);
			this.cappucinoButton.injectInside(this.mainfilter);
			this.latteButton.injectInside(this.mainfilter);
			this.mochaButton.injectInside(this.mainfilter);
			this.espressoButton.injectInside(this.mainfilter);
		}
		if(category == 'tabletop') {
			this.solubleButton.injectInside(this.mainfilter);
			this.beantocupButton.injectInside(this.mainfilter);
			this.tradespressoButton.injectInside(this.mainfilter);
			this.bulkbrewpourButton.injectInside(this.mainfilter);
			this.fairtrade_ttButton.injectInside(this.mainfilter);
		}
		if(category == 'vending') {
			this.premiummainButton.injectInside(this.mainfilter);
			this.premiumButton.injectInside(this.mainfilter);
			this.fairtrade_vendButton.injectInside(this.mainfilter);
		}
	},
	initializeSubTypeButtons: function() {
		var filterSubType = this.filterSubType.bind(this);
		
		this.coffeeButton.addEvent('click',function() { 
			filterSubType('coffee');
		 });
		this.hotchocButton.addEvent('click',function() { 
			filterSubType('hotchoc');
		});
		this.cappucinoButton.addEvent('click',function() { 
			filterSubType('cappucino');
		});
		this.latteButton.addEvent('click',function() { 
			filterSubType('latte');
		});
		this.mochaButton.addEvent('click',function() { 
			filterSubType('mocha');
		});
		this.espressoButton.addEvent('click',function() { 
			filterSubType('espresso');
		});
		this.solubleButton.addEvent('click',function() { 
			filterSubType('soluble');
		});
		this.beantocupButton.addEvent('click',function() { 
			filterSubType('beantocup');
		});
		this.tradespressoButton.addEvent('click',function() { 
			filterSubType('tradespresso');
		});
		this.bulkbrewpourButton.addEvent('click',function() { 
			filterSubType('bulkbrewpour');
		});
		this.fairtrade_ttButton.addEvent('click',function() { 
			filterSubType('fairtrade_tt');
		});
		this.premiummainButton.addEvent('click',function() { 
			filterSubType('premiummain');
		});
		this.premiumButton.addEvent('click',function() { 
			filterSubType('premium');
		});
		this.fairtrade_vendButton.addEvent('click',function() { 
			filterSubType('fairtrade_vend');
		});
	},
	enableSecondFilter: function() {
		
		var initializeBusinessSlider = this.initializeBusinessSlider.bind(this);
		
		
		/* set up buttons for second filter */
		this.numEmployees.addEvent('click',function() { 
			initializeBusinessSlider('employees');
		 });
		 this.numCups.addEvent('click',function() { 
			initializeBusinessSlider('cups');
		 });
		
	},
	initializeMachineTypeButtons: function() {
		var filterMachineTypeInCup = this.filterMachineTypeInCup.bind(this);
		var filterMachineTypeTabletop = this.filterMachineTypeTabletop.bind(this);
		var filterMachineTypeVending = this.filterMachineTypeVending.bind(this);
		var filterMachineTypeTinSpoon = this.filterMachineTypeTinSpoon.bind(this);
		
		var slideOutThird = this.slideOutThirdFilter.bind(this);
		
		this.incupButton.addEvent('click',function() { 
			filterMachineTypeInCup();
			slideOutThird('incup');
		 });
		this.tabletopButton.addEvent('click',function() { 
			filterMachineTypeTabletop();
			slideOutThird('tabletop');
		
		});
		this.vendingButton.addEvent('click',function() { 
			filterMachineTypeVending();
			slideOutThird('vending');
		});
		this.tinSpoonButton.addEvent('click',function() { 
			filterMachineTypeTinSpoon();
			//slideOutThird('tinspoon'); // no subcategories
		});
	},
	initializeBusinessSlider: function(type) {
		
		/* light up the slider */
		this.bslider.setStyle('opacity','1');
	
		
		if(type=='cups') {
			this.businessSizeValues.setStyle('word-spacing','3px');
			this.businessSizeValues.set('text','3-30 31-90 91-150 151-300 300+'); // cups
		} else {
			this.businessSizeValues.setStyle('word-spacing','8px');
			this.businessSizeValues.set('text','1-10 11-30 31-50 51-100 100+'); // employees
		}
		
		/* create a slider */
		var updateSlider = this.updateSlider.bind(this);
		var slideComplete = this.filterBusinessCupSize.bind(this);
		this.businessSizeSlider = new Slider(this.bslider, this.bsliderKnob, {
			range: [0, 4],
    		wheel: true,
    		snap: true,
			steps: 4,
			onChange: function(pos){
				/* update slider position */
				updateSlider(pos);
			},
			onComplete: function(step) { 
				slideComplete(step);
			}	

		});
		this.businessSizeSlider.set(2);
		slideComplete(2);
		this.createSliderNextButton();
				
	},
	createSliderNextButton: function() {
		if (!$defined(this.nextStageButton)) {
			this.nextStageButton = new Element('div', {
				'id': 'nextstep_button',
				'class': 'nextstepbutton'
			}).set('text', 'Next Step');
			var slideOutSecondFilter = this.slideOutSecondFilter.bind(this);
			var currentPosition = this.getCurrentPosition.bind(this);
			this.nextStageButton.addEvent('click', function(){
				slideOutSecondFilter(currentPosition());
			})
			this.nextStageButton.injectInside(this.mainfilter);
		}
	},
	getCurrentPosition: function() {
		return this.currentPosition;
	},
	updateSlider: function(pos) {
		this.currentPosition = pos;
	},
	
	filterMachineTypeInCup: function(subtype) {
		if (!this.loading) {
			this.createLoadingScreen();
			this.loading = true;
			var freeLoader = this.freeLoader.bind(this);
				(function(){
					parseXSLT('xslt/in_cup.xsl', 'productarea');
					freeLoader();
				}).delay(1500);
			
		}
	},
	filterMachineTypeTabletop: function(subtype) {
		if (!this.loading) {
			this.createLoadingScreen();
			this.loading = true;
			var freeLoader = this.freeLoader.bind(this);
				(function(){
					parseXSLT('xslt/systems.xsl', 'productarea');
					freeLoader();
				}).delay(1500);
			
		}
	},
	
	filterMachineTypeVending: function(subtype) {
		if (!this.loading) {
			this.createLoadingScreen();
			this.loading = true;
			var freeLoader = this.freeLoader.bind(this);
				(function(){
					parseXSLT('xslt/vending.xsl', 'productarea');
					freeLoader();
				}).delay(1500);
			
		}
	},
	
	filterMachineTypeTinSpoon: function(subtype) {
		if (!this.loading) {
			this.createLoadingScreen();
			this.loading = true;
			var freeLoader = this.freeLoader.bind(this);
				(function(){
					parseXSLT('xslt/tinspoon.xsl', 'productarea');
					freeLoader();
				}).delay(1500);
			
		}
	},
	
	filterBusinessCupSize: function(pos) {
		if (!this.loading && !this.firstslide) {
			this.createLoadingScreen();
			this.loading = true;
			var freeLoader = this.freeLoader.bind(this);
			if (pos == 0) {
				(function(){
					parseXSLT('xslt/1_10.xsl', 'productarea');
					freeLoader();
				}).delay(1500);
			}
			if (pos == 1) {
				(function(){
					parseXSLT('xslt/11_30.xsl', 'productarea');
					freeLoader();
				}).delay(1500);
			}
			if (pos == 2) {
				(function(){
					parseXSLT('xslt/31_50.xsl', 'productarea');
					freeLoader();
				}).delay(1500);
			}
			if (pos == 3) {
				(function(){
					parseXSLT('xslt/51_100.xsl', 'productarea');
					freeLoader();
				}).delay(1500);
			}
			if (pos == 4) {
				(function(){
					parseXSLT('xslt/100.xsl', 'productarea');
					freeLoader();
				}).delay(1500);
			}
			
	
		}
		this.currentPosition = pos;
		this.firstslide = false;
	},
	filterSubType: function(subtype) {
		if (!this.loading) {
			this.createLoadingScreen();
			this.loading = true;
		
			/* determine the xsl file */
			var xslfile;
			if(subtype == 'coffee') {
				xslfile = "xslt/in_cup.xsl";
			}
			if(subtype == 'hotchoc') {
				xslfile = "xslt/in_cup.xsl";
			}
			if(subtype == 'cappucino') {
				xslfile = "xslt/in_cup.xsl";
			}
			if(subtype == 'latte') {
				xslfile = "xslt/in_cup_restricted.xsl";
			}
			if(subtype == 'mocha') {
				xslfile = "xslt/in_cup_restricted.xsl";
			}
			if(subtype == 'espresso') {
				xslfile = "xslt/in_cup_restricted.xsl";
			}
			if(subtype == 'soluble') {
				xslfile = "xslt/soluble.xsl";
			}
			if(subtype == 'beantocup') {
				xslfile = "xslt/beantocup.xsl";
			}
			if(subtype == 'tradespresso') {
				xslfile = "xslt/tradespresso.xsl";
			}
			if(subtype == 'bulkbrewpour') {
				xslfile = "xslt/bulkbrew.xsl";
			}
			if(subtype == 'fairtrade_tt') {
				xslfile = "xslt/fairtrade_tt.xsl";
			}
			if(subtype == 'premiummain') {
				xslfile = "xslt/premiummain.xsl";
			}
			if(subtype == 'premium') {
				xslfile = "xslt/premium.xsl";
			}
			if(subtype == 'fairtrade_vend') {
				xslfile = "xslt/fairtrade_vend.xsl";
			}
			var freeLoader = this.freeLoader.bind(this);
			(function(){
				parseXSLT(xslfile, 'productarea');
				freeLoader();
			}).delay(1500);
			
		}
	},
	createLoadingScreen: function() {
		
		var text = new Element('h3').set('text','Please wait whilst we look for products...');
		var loader = new Element('img', { 'src': 'img/loading.gif','class':'loading'});
		/* clear out dom */
		this.productarea.empty();
		text.injectInside(this.productarea);
		loader.injectInside(this.productarea);
	},
	freeLoader: function() {
		this.loading = false;
	},
	
	loadProduct: function(id) {
		
		Lightbox.open(id);
			
	}
}

window.addEvent('domready', function() {
	Products.initialize();
    parseXSLT('xslt/all_products.xsl','productarea');
	
	var scrollCheck = function() {
		Lightbox.scroll();
	}
	
	var sizeCheck = function() {
		Lightbox.resize();
	}
    window.onscroll = scrollCheck; 
	window.onresize = sizeCheck;
	
	/* notepad */
	Notepad.init();
	
	/* quicklinks */
	generateQuicklinks();
});


/* parse specific XSLT file */
function parseXSLT(xsltfile,dataArea) {
	
	grabXML();
	grabXSL(xsltfile);
	
	var data = XML_DOM;
	var xsl = XSL_DOM;
	var parsed;
	
	if (window.ActiveXObject) { // ie
		parsed = data.transformNode(xsl);
		$(dataArea).set('html',parsed);
	} 
	
	if(document.implementation && document.implementation.createDocument) { // everything else
		xsltProcessor=new XSLTProcessor();
		xsltProcessor.importStylesheet(xsl);
		parsed = xsltProcessor.transformToFragment(data,document);
		$(dataArea).empty();
		$(dataArea).appendChild(parsed);
	}
	
	Notepad.enableProducts();
}

/* FF 3 has a real problem reading in XML files for some reason. so an AJAX call is required. */
function grabXML() {
		
		/* create xml*/
		var xmlobject;
		
		/* parse xml after ajax requet */
		var parseXML = function(){
			if (window.ActiveXObject) {
			
				/* convert the string to an xml object */
				xmlobject = new ActiveXObject("Microsoft.XMLDOM");
				xmlobject.async = "false";
				xmlobject.loadXML(DATA_XML);
				XML_DOM = xmlobject;
			
			} else {
				/* convert the string to an xml object */
				xmlobject = (new DOMParser()).parseFromString(DATA_XML, "text/xml");
				XML_DOM =  xmlobject;
				
			}
			
		}
		
		/* request xml data, make synchronous! */
		var req = new Request({async:false,url:productData, 
			onSuccess: function(txt) {
				DATA_XML = txt;
				parseXML();
				
			}
		}).send();
}

/* same as above, just use different variables */
function grabXSL(xslfile) {
		
		/* create xml*/
		var xslobject;
		
		/* parse xml after ajax requet */
		var parseXSL = function(){
			if (window.ActiveXObject) {
			
				/* convert the string to an xml object */
				xslobject = new ActiveXObject("Microsoft.XMLDOM");
				xslobject.async = "false";
				xslobject.loadXML(DATA_XSL);
				XSL_DOM = xslobject;
			
			} else {
				/* convert the string to an xml object */
				xslobject = (new DOMParser()).parseFromString(DATA_XSL, "text/xml");
				XSL_DOM =  xslobject;
				
			}
			
		}
		
		/* request xml data, make synchronous! */
		var req = new Request({async:false,url:xslfile, 
			onSuccess: function(txt) {
				DATA_XSL = txt;
				parseXSL();
				
			}
		}).send();
}


/* clear out quicklinks */
function clearQuicklinks() {
	
	$('quicklinks').empty();
	
}

/* generate quicklinks */
function generateQuicklinks() {
	
	$('quicklinks').empty();
	
	/* title */
	var qlTitle = new Element('h4').set('text','Quicklinks');
	var menuSelect = new Element('div', {'name' : 'jumpmenu','id' : 'quicklinks_menu'});
	var optionSelect = new Element('div', {'id': 'Select'}).set('text', 'Select a product...').injectInside(menuSelect);
	var optionChoice = new Element('div', {'id': 'quicklinks_options'}).injectInside(optionSelect);
	var containerDiv = new Element('div', {'id': 'containerDiv'}).injectInside(document.body);
	optionSelect.addEvent('click', function() { optionChoice.setStyle('display','block'); });
	optionSelect.addEvent('click', function() { containerDiv.setStyle('display','block'); });
	optionChoice.addEvent('click', function() { optionChoice.setStyle('display','none'); });
	containerDiv.addEvent('click', function() { optionChoice.setStyle('display','none'); });
	containerDiv.addEvent('click', function() { containerDiv.setStyle('display','none'); });
	
	var selectedProduct = null;
	
	/* quicklinks load */
	var quickLinksLoad = function(productId) {
		Products.loadProduct(productId);
	}
	
	var loadLinkOverlay = quickLinksLoad.bind(this);
		
	/* create xml */
	grabXML();
	
	var xmlobj = XML_DOM;
		
	/* grab the root (products) */
	var root = xmlobj.getElementsByTagName('products')[0]; //root 
	
	if (Browser.Engine.trident) { // IE
		for (j = 0; j < root.childNodes.length; j++) {
		
			/* each product */
			if (root.childNodes[j].nodeType != 1) 
				continue;
			/* inject inside! */
			var injectedOption = new Element('div', {'class': 'option',
				'id': root.childNodes[j].attributes[0].nodeValue
			});
			
		
			injectedOption.set('text', root.childNodes[j].childNodes[2].firstChild.nodeValue.toString().trim());
			injectedOption.injectInside(optionChoice);
		}
	} else {
		/* everything else */
		
		for (j = 0; j < root.childNodes.length; j++) {
		
			/* each product */
			if (root.childNodes[j].nodeType != 1) 
				continue;
			/* inject inside! */
			var injectedOption = new Element('div', {'class': 'option',
				'id': root.childNodes[j].attributes[0].nodeValue
			});
				
			injectedOption.set('text', root.childNodes[j].childNodes[5].firstChild.nodeValue.toString().trim());
			injectedOption.injectInside(optionChoice);		
		}
	}
	
	qlTitle.injectInside($('quicklinks'));
	menuSelect.injectInside($('quicklinks'));
	
	/* add events */
	$$('#quicklinks_options .option').each(function(item){
		
		item.addEvent('click',function() { loadLinkOverlay(item.getAttribute('id')) });
		
		/* IE highlighting */
		//if (Browser.Engine.trident) {
			item.addEvent('mouseover',function() { item.addClass('option_over') });
			item.addEvent('mouseout', function() { item.removeClass('option_over') });
		//}
		
	});
			
}
