var toggle = {
	init: function() {
		if($$('a.close')){
			$$('a.close').invoke("observe", "click", function(){
				this.up('.wrapper').toggle();
			});
		}
				
		if($('goButton')){
			var goButton = $('goButton');
			
			goButton.observe("mouseover", function(){
				if(navigator.appVersion && navigator.appVersion.match(/MSIE 6/)){
					this.togglePng(goButton, '/images/goOn.png');
				}else {
					goButton.addClassName('on');
				} 
			}.bind(this));
		
			goButton.observe("mouseout", function(){
				if(navigator.appVersion && navigator.appVersion.match(/MSIE 6/)){
					this.togglePng(goButton, '/images/goOff.png');
				}else{
					goButton.removeClassName('on');
				}
			}.bind(this));
		}
		
		if($('resetButtonPlace')){
			var resetButtonPlace = $('resetButtonPlace');
			
			resetButtonPlace.observe("mouseover", function(){
				resetButtonPlace.addClassName('on');
			}.bind(this));
		
			resetButtonPlace.observe("mouseout", function(){
				resetButtonPlace.removeClassName('on');
			}.bind(this));
		}
		
		if($('resetButtonCategory')){
			var resetButtonCategory = $('resetButtonCategory');
			
			resetButtonCategory.observe("mouseover", function(){
				resetButtonCategory.addClassName('on');
			}.bind(this));
		
			resetButtonCategory.observe("mouseout", function(){
				resetButtonCategory.removeClassName('on');
			}.bind(this));
		}
			
		if($('legendButton')){
			var legendButton = $('legendButton');
			
			legendButton.observe("click", function(event){
				event.stop();
				$('legendDropDown').toggle();
				legendButton.toggleClassName('active');
				if(navigator.appVersion && navigator.appVersion.match(/MSIE 6/)){
					if(!legendButton.hasClassName('active')){
						this.togglePng(legendButton, '/images/map/legendOff.png');
					}else{
						this.togglePng(legendButton, '/images/map/legendOn.png');
					}
				
					$$('img.legendimg').each(function(e){
						this.el_fnFixPng(e);
					}.bind(this));
				}
			}.bind(this));
		}
		
		if($('bt_go_lottery')){
			$('bt_go_lottery').observe("mouseover", function(){
				this.src = '/images/map/teaser/lottery/bt_go_active.gif';
			});
			
			$('bt_go_lottery').observe("mouseout", function(){
				this.src = '/images/map/teaser/lottery/bt_go_inactive.gif';
			});
		}
		
		if($('bt_comments') && $('bt_events')){
			$('bt_comments').observe('click', this.showComments);
			$('bt_events').observe('click', this.showEvents);
		}
	},
	
	togglePng: function(obj, src) {
		var mode = 'scale';
		if (obj.currentStyle.backgroundRepeat == 'no-repeat') {
			mode = 'crop';
		}		
		obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')";
		obj.style.background = "transparent";
	},
	
	el_fnFixPng: function(img) {
		img.style.width = "213px";
		img.style.height = "51px";
	},
	
	showEvents: function(){
		$('bt_comments').removeClassName('active');
		$('bt_events').addClassName('active');
		$('events_Location').show();
		$('events_Location_add').show();
		$('comments_Location').hide();
		$('comments_Location_add').hide();
	},
	
	showComments: function(){
		$('bt_comments').addClassName('active');
		$('bt_events').removeClassName('active');
		$('events_Location').hide();
		$('events_Location_add').hide();
		$('comments_Location').show();
		$('comments_Location_add').show();
	}
};

document.observe("dom:loaded", function(){toggle.init();});