window.addEvent('domready', function() {

	var typelegend = $('typelegend');
	if (typelegend != null) {
		var legendpop = $('legendpop');
		typelegend.getElements('div.typelegenditem').each(function(item, index){
		
			var aTag = item.getElement('a');
			var imgSrc = aTag.getElement('img').getProperty('src');
			var imgTag = '<img border="0" width="27" height="27" alt="" src="' + imgSrc + '"/>';
			var position = aTag.getPosition(typelegend);
			var rel = aTag.getProperty('rel');
			
			aTag.addEvent('mouseover', function(evt){
				evt.stop();
				legendpop.set({
					'html': imgTag + '<p>' + rel + '</p>',
					'styles': {
						'display': 'block',
						'left':position['x']-118
					}
				});
			});
			
			aTag.addEvent('mouseout', function(evt){
				legendpop.setStyle('display', 'none');
			});
			
		});
	}

	var parkingList = $('parking-list');
	if (parkingList != null) {
		parkingList.getElements('div.list-item-content').each(function(item, index){
		
			item.getElement('a.list-item-link').addEvents({
				'mouseover': function(evt){
					item.addClass('act');
				},
				'mouseout': function(evt){
					item.removeClass('act');
				}
			});
	
		});
	}
	
	var tabscontainer  = $('tabscontainer');
	if (tabscontainer != null) {
		var panelcontainer = $('panelcontainer');
		tabscontainer.getElements('a.tablink').each(function(aTag, index){
			
			aTag.addEvent('click', function(evt){
			
				evt.stop();		//Prevents the browser from following the link.
				
				panelcontainer.getElements('div.tabpanel').each(function(item, index){
					item.setStyle('display','none');
				});
				panelcontainer.getElement('div.' + this.getProperty('rel')).setStyles({
					'display':'block',
					'position':'relative',
					'left':'0px',
					'top':'0px'
				});
				if (this.getProperty('rel') == 'tab_e') {
					load('detailcanvas');
				}
				
				tabscontainer.getElements('div.tab').each(function(item, index){
					item.removeClass('selectedtab');
				});
				this.getParent('div.tab').addClass('selectedtab');
			});
		});
	}
	
	
	var routeformcontainer = $('routeformcontainer');
	if (routeformcontainer != null) {
		
		var routeformcontaineropen = false;
		
		routeformcontainer.getElement('a').addEvent('click', function (evt){
			evt.stop();
			$('routeform').setStyle('display', routeformcontaineropen ? 'none' : 'block');
			//$('saddr').selectRange(2, 4);
			routeformcontaineropen = ! routeformcontaineropen;
		});
		
		var route_url = 'http://maps.google.nl/maps?f=d&source=s_d&hl=nl&mra=ls&daddr=';
		route_url += parkings.address.replace('/', ', ') + ', ' + parkings.zip + ' ' + parkings.city/* + ' (' + parkings.name + ')'*/;
		route_url += '&saddr=';

		$('saddr').addEvent('focus', function(evt){
			this.value = '';
		});
		$('saddr').addEvent('blur', function(evt){
			$('routeformlink').setProperty('href', route_url + this.value);
		});
		
		
	}
	

});