var subnavGenerator = function(){
	var temp = $$('#subnav li a');
	var list = temp.filter(function(element,i) {
		return !element.getParent().hasClass('sub')
	});
	list.each(function(element, i) {
		var newwidth = element.offsetWidth - 35;
		if (browser.isOpera)
			element.style.width = newwidth; //this is for opera which goes crazy without a width
	//mouseenter part
		var parentelem = element.getParent();
		element.addEvent('mouseenter', function(){
			if (parentelem.hasClass('prelast')) { //prelast only
				//element.setStyles({
				//   backgroundPosition: 'right bottom',
				//   color: '#666'
				//});
			} else if ((!parentelem.hasClass('last')) && (!parentelem.hasClass('first')) && (!parentelem.hasClass('firstPreLast'))) { //any 'common' node (not first, prelast or last)
				//element.setStyles({
				//   backgroundPosition: 'right -84px',
				//   color: '#666'
				//});
			} else { //if it's first or last, although the only 'visible' change happens with last
				//element.setStyles({
				//   color: '#666'
				//});
			}
		});
		if ( (i+1) < list.length ) {
			list[i+1].addEvent('mouseenter', function(){
				if ((!parentelem.hasClass('first')) && (!parentelem.hasClass('firstPreLast'))) {
					//element.setStyles({
					//   backgroundPosition: 'right -56px'
					//});
				} else {
					//element.setStyles({
					//   backgroundPosition: 'right bottom'
					//});
				}
			});
		}
	//mouseleave part
		element.addEvent('mouseleave', function(){
			if (parentelem.hasClass('prelast')) {
				//element.setStyles({
				//   backgroundPosition: 'right center',
				//   color: '#333'
				//});
			} else if (!parentelem.hasClass('last')) {
				//element.setStyles({
				//   backgroundPosition: 'right top',
				//   color: '#333'
				//});
			} else {
				//element.setStyles({
				//   color: '#333'
				//});
			}
		});
		if ( (i+1) < list.length ) {
			list[i+1].addEvent('mouseleave', function(){
				if ((!parentelem.hasClass('prelast')) && (!parentelem.hasClass('firstPreLast'))) {
					//element.setStyles({
					//   backgroundPosition: 'right top',
					//   color: '#333'
					//});
				} else if(parentelem.hasClass('prelast')) {
					//element.setStyles({
					//   backgroundPosition: 'right center',
					//   color: '#333'
					//});
				}
			});
		}
	});
	//now the sub part
	var allsubs = $$('#subnav li ul');
	allsubs.each(function(element, i) {
		if (window.ie6) {
			//this is for ie6 which goes crazy without an actual width in each ul.
			var alinks = element.getElements('a');
			var maxlength = 0;
			alinks.each(function(atag, j) {
				var awidth = atag.offsetWidth;
				if (awidth > maxlength) {
					maxlength = awidth;
				}
				//alert('awidth: '+awidth+'     maxlength: '+maxlength);
			});
			element.setStyle('width', maxlength);
		}
		//it's time to put some nice effects
		var fx = new Fx.Styles(element, {duration:350, wait:false});
		
		var parentelem = element.getParent();
		element.setStyle('opacity', 0);
		element.setStyle('margin-top', 0);
		
		if (window.ie6) {
			var selects = $$('select');
		}
		parentelem.addEvent('mouseenter', function(){
			if(window.ie6){
				selects.each(function(selecttag) {
					selecttag.setStyle('visibility', 'hidden');
				});
			}
			fx.start({
				'opacity': 1,
				'margin-top': 10
			});
		});
		parentelem.addEvent('mouseleave', function(){
			fx.start({
				'opacity': 0,
				'margin-top': 5
			});
			if(window.ie6){
				selects.each(function(selecttag) {
					selecttag.setStyle('visibility', 'visible');
				});
			}
		});
	});
};
