/*
 * Dropdown menu implementation with rollover images.
 * Use it for free wherever you want.
 * @Author: TomS <tom@enedue.com>
 */

var Rolls = new Class({
	
	initialize: function(name, n) {
		
		// preloading images
		var aImgs = new Array();
		$(name).getElements('img[class=roll]').each(function(id, i){
			var n = id.src.replace(/\D+/g, '');
			aImgs[n] = new Image();
			aImgs[n].src = id.src.replace('.jpg', '_rol.jpg');
		});
		
		// dropdown menu
		$(name).getElements('a[rel^=drop]').each(function(id, i){
			
			var n = id.getProperty('rel').substr(4);
			$('node'+n).setStyle('opacity', 0);
			
			if(window.ie) {
				$('node'+n).setStyle('margin-top', -2);
			}
			
			if($('node'+n).getText()==''){
				$('node'+n).setStyle('display', 'none');
			} else {
				id.addEvent('click', function(e){
					new Event(e).stop();
				});
			}
			
			// mouse events
			var fx = new Fx.Styles('node'+n, {duration:100, wait:false});
			$('cel'+n).addEvent('mouseover', function(){
				this.getElements('img[class=roll]').each(function(id, i){
					var n = id.src.replace(/\D+/g, '');
					id.src = aImgs[n].src;
				});
				fx.start({
					opacity: 0.9
				});
				//$('node'+n).setStyle('opacity', 0.9);
			});
			$('cel'+n).addEvent('mouseout', function(){
				this.getElements('img[class=roll]').each(function(id, i){
					var n = id.src.replace(/\D+/g, '');
					id.src = id.src.replace('_rol.jpg', '.jpg');
				});
				fx.start({
					opacity: 0
				});
				//$('node'+n).setStyle('opacity', 0);
			});
			
		});
		
	}

});

window.addEvent('domready', function(){
	
	new Rolls('menu');
	
	// anchors focus events
	$ES('a').each(function(id) {
		id.addEvent('focus', function(e){
			this.blur();
		});
	});
	
	// fixes ie margin problem
	if(window.ie) {
		$('btm_bg').setStyle('margin-top', -1);
	}
	
	swfobject.embedSWF("gfx/top.swf", "flash", "938", "308", "8.0.0", null, null, {wmode:"transparent"});
	
});

