window.addEvent('load',function(){
	asc_init();
});

function navInit() {
	asc_init();
}
// prepares the regular version of the global navigation with full functionality
function asc_init() {
	
	var gonogo=true;
	var use_ishim=false;
	var active_ishim=null;
	
	if (navigator.appVersion.indexOf("MSIE")!=-1){
	try
	{
		document.execCommand("BackgroundImageCache", false, true); 
	}
	catch(err)
	{
	}
	var temp=navigator.appVersion.split("MSIE")
	var version=parseFloat(temp[1])
		if (version<=5.9)
		{
			gonogo=false;
		}
		if (version>=6 && version<7)
		{
			use_ishim=true;
			$('asc').insertAdjacentHTML('beforeEnd', '<iframe src="'+asc_iframe+'" id="asc_ishim" frameborder="0" scrolling="0" style="position:absolute;top:0;left:0;width:0;height:0;display:none;z-index:498;filter:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);"></iframe>');
			var asc = $('asc');
			var lis = $ES('li',asc);
			lis.each(function(li) {
				var lnk = li.getFirst();
				lnk.style.height='1%';
			});
		}
	}
	
	function asc_ishim(show,d_2)
	{
		var ishim = $('asc_ishim');
		if(show==true && use_ishim==true)
		{	
			ishim.style.display = 'block';
			var d_2_pos = d_2.getCoordinates();
			ishim.style.width = d_2_pos.width;
			ishim.style.height = d_2_pos.height;
			ishim.style.top = d_2_pos.top;
			ishim.style.left = d_2_pos.left;
		}
		
		if (active_ishim==d_2 && show==false && use_ishim==true)
		{
			ishim.style.display = 'none';
		}
		active_ishim=d_2;
	}

	var objects = document.getElementsByTagName('OBJECT');
	var embeds = document.getElementsByTagName('EMBED');
			
	if (((objects.length >= 1) || (embeds.length >= 1)) && (navigator.appVersion.indexOf('Mac')!=-1))
	{
		gonogo=false;
	}

	if (gonogo==true)
	{
		if (typeof ascCategory!='undefined')
		{
			var t = 0;
			var g = ascCategory*1;
			var headers = $$('#asc h2');
			headers.each(function(header) {
				if (g==t)
				{
					var a = $E('a',header);
					a.addClass('asc_selected');
				}
				t++;
			});
		}

		var headers = $$('#asc h2');
		headers.each(function(header) {
			
			var a_1 = $E('a',header);
			var d_2 = header.getNext();
			var u_2 = $E('ul',d_2);
			var l_2s = u_2.getChildren();
			var u_3s = $ES('ul',u_2);

			if (header.className=='asc_right')
			{
				var asc_right=true;
				u_2.setStyle('float', 'right');
			}
			else
			{
				var asc_right=false;
			}

			d_2.setStyle('opacity', '0.1');

			function d_2_show(a_1,d_2) {
				var a_1_pos = a_1.getCoordinates();
				var h = a_1_pos.height;
				var w = a_1_pos.width;
				var l = a_1_pos.left;
				var t = a_1_pos.top;

				var asc = $('asc');
				var d_2_cs = $ES('div.asc_dd',asc);
				d_2_cs.each(function(d_2_c) {
					if (d_2_c.style.zIndex='500')
					{
						var h_c = d_2_c.getPrevious();
						var a_1_c = $E('a',h_c);
						d_2_hide(a_1_c,d_2_c);
					}
				});

				d_2.setStyle('top', (t+h));
				if (asc_right==true)
				{
					d_2.setStyle('left', l+w-180);
				}
				else
				{
					d_2.setStyle('left', l);
				}
				d_2.setStyle('z-index', '500');
				a_1.addClass('asc_active');
				asc_ishim(true,d_2);
			}

			function d_2_hide(a_1,d_2) {
				d_2.setStyle('margin-left', '0');
				d_2.setStyle('width', '180px');
				d_2.setStyle('height', 'auto');
				d_2.setStyle('left', '-1000em');
				d_2.setStyle('z-index', '499');
				a_1.removeClass('asc_active');
				asc_ishim(false,d_2);
			}

			a_1.addEvents({
				
				'focus': function() {
					d_2_show(a_1,d_2);
					d_2.setStyle('opacity', '0.98');
				},
				
				'blur': function() {
					d_2_hide(a_1,d_2);
				},

				'keydown': function(event) {
					event = new Event(event);
					if (event.key=='down')
					{
						u_2.getFirst().getFirst().focus();
					}
					else if (event.key=='left' && header.getPrevious())
					{
						$E('a',header.getPrevious().getPrevious()).focus();
					}
					else if (event.key=='right' && header.getNext().getNext())
					{
						$E('a',header.getNext().getNext()).focus();
					}
				}
			});

			var reveal = new Fx.Styles(d_2, {
				duration: 300,
				transition: Fx.Transitions.Quad.easeIn,
				fps: 30
			});

			reveal.addEvent('onStart', function(){
				d_2_show(a_1,d_2);
			});
			
			var repeal = new Fx.Styles(d_2, {
				duration: 300,
				transition: Fx.Transitions.Quad.easeOut,
				fps: 30
			});
			
			repeal.addEvent('onStart', function(){
				d_2.setStyle('z-index', '499');
				a_1.removeClass('asc_active');
				asc_fo(a_1);
			});

			repeal.addEvent('onComplete', function(){
				d_2_hide(a_1,d_2);
			});

			a_1.addEvent('mouseenter', function(event){
				var rt = event.relatedTarget;
				while (rt && rt != d_2 && rt.nodeName != 'BODY')
				rt = rt.parentNode
				if (rt == d_2) return;
				
				repeal.stop();
				d_2.setStyle('opacity', '0.1');
				reveal.start({
					'opacity': [0.1,0.98]
				});
			});

			a_1.addEvent('mouseleave', function(event){
				var rt = event.relatedTarget;
				while (rt && rt != d_2 && rt.nodeName != 'BODY')
				rt = rt.parentNode
				if (rt == d_2) return;
				
				reveal.stop();
				repeal.start({
					'opacity': [0.98,0.1]
				});
			});

			d_2.addEvent('mouseleave', function(event){
				var rt = event.relatedTarget;
				while (rt && rt != a_1 && rt.nodeName != 'BODY')
				rt = rt.parentNode
				if (rt == a_1) return;
				
				reveal.stop();
				repeal.start({
					'opacity': [0.98,0.1]
				});
			});

			l_2s.each(function(l_2) {
				
				var a_2 = l_2.getFirst();

				var rollover = new Fx.Styles(a_2, {
					duration: 300,
					transition: Fx.Transitions.Quad.easeOut,
					fps: 30,
					wait: false
				});

				var rolloff = new Fx.Styles(a_2, {
					duration: 300,
					transition: Fx.Transitions.linear,
					fps: 30,
					wait: false
				});

				var asc_foto;

				a_2.addEvents({
					
					'mouseenter':  function() {
					asc_foto = asc_fo.delay(300,asc_fo,a_2);
						rollover.stop();
						rollover.start({
							'background-color': '#336699'
						});
					},

					'mouseleave': function(event) {
					$clear(asc_foto);
						if (!(a_2.hasClass('asc_out')))
						{
							rollover.stop();
							rolloff.start({
								'background-color': '#000'
							});
						}
					},

					'focus': function() {
						d_2_show(a_1,d_2);
						a_2.setStyle('background-color', '#336699');
						d_2.setStyle('opacity', '0.98');
					},

					'blur': function() {
						d_2_hide(a_1,d_2);
						a_2.setStyle('background-color', '#000');
					},

					'keydown': function(event) {
						event = new Event(event);
						if (event.key=='up' && l_2.getPrevious())
						{
							l_2.getPrevious().getFirst().focus();
						}
						else if (event.key=='up' && !(l_2.getPrevious()))
						{
							a_1.focus();
						}
						else if (event.key=='down' && l_2.getNext())
						{
							l_2.getNext().getFirst().focus();
						}
						else if (event.key=='left' && header.getPrevious())
						{
							$E('a',header.getPrevious().getPrevious()).focus();
						}
						else if (event.key=='right' && header.getNext().getNext())
						{
							$E('a',header.getNext().getNext()).focus();
						}
					}
				});
			});

			function asc_fo(a_2) { 
				
				var u_2_h = u_2.getCoordinates().height;

				u_3s.each(function(u_3) {
					
					if (u_3.style.left=='auto' && u_3!=a_2.getNext())
					{
						var flyin = new Fx.Styles(u_3, {
							duration: 300,
							transition: Fx.Transitions.linear,
							fps: 30
						});

						flyin.addEvent('onStart', function(){
							u_3.getPrevious().removeClass('asc_out');
						});

						flyin.addEvent('onComplete', function(){
							u_3.setStyle('left', '-1000em');
							u_3.setStyle('height', 'auto');
							if (!(a_2.getNext()))
							{
								d_2.setStyle('margin-left', '0');
								d_2.setStyle('width', '180px');
								d_2.setStyle('height', 'auto');
								asc_ishim(true,d_2);
							}
						});

						var u_3_h = u_3.getCoordinates().height;

						if (asc_right==true)
						{
							flyin.start({
								'width': [176,0],
								'height': [u_3_h,0],
								'opacity': [0.98,0],
								'margin-left': [-176,0]
							})
						}
						else
						{
							flyin.start({
								'width': [176,0],
								'height': [u_3_h,0],
								'opacity': [0.98,0]
							})
						}
						
						var rollover = new Fx.Styles(u_3.getPrevious(), {
							duration: 300,
							transition: Fx.Transitions.linear,
							fps: 30,
							wait: false
						});

						rollover.start({
							'background-color': '#000'
						});
					}

					if (u_3==a_2.getNext() && u_3.style.left!='auto')
					{
						var u_3_h = u_3.getCoordinates().height;

						var flyout = new Fx.Styles(u_3, {
							duration: 300,
							transition: Fx.Transitions.linear,
							fps: 30
						});

						flyout.addEvent('onStart', function(){
							a_2.addClass('asc_out');
							u_3.setStyle('left', 'auto');
							d_2.setStyle('width', '360px');
							if (asc_right==true)
							{
								d_2.setStyle('margin-left', '-180px');
							}
							if (u_3_h>u_2_h)
							{
								d_2.setStyle('height', u_3_h+30);
							}
							else 
							{
								d_2.setStyle('height', 'auto');
								var d_2_h = d_2.getCoordinates().height;
								d_2.setStyle('height', d_2_h+30);
							}
							asc_ishim(true,d_2);
						});

						if (asc_right==true)
						{
							flyout.start({
								'width': [0,176],
								'height': [0,u_3_h],
								'opacity': [0,0.98],
								'margin-left': [0,-176]
							})
						}
						else
						{
							flyout.start({
								'width': [0,176],
								'height': [0,u_3_h],
								'opacity': [0,0.98]
							})
						}
					}
				})
			}
		});
	}
}