var fsize_step		= 0.1;
var fsize			= 1;
var geocoder;
var geocoder_inited	= false;

function unloadGoogleMaps() {
	window.addEvent('unload', function() { GUnload(); } );
}

function setFontSize(fs) {
	switch(fs) {
		case 'smaller':
			if(fsize <= 0.6) break;
			fsize -= fsize_step;
			$('content').setStyle('font-size', fsize+'em');
			Cookie.set('megasunFontSize', fsize, {duration: 365, path: '/'});
			break;
		
		case 'larger':
			if(fsize >= 3) break;
			fsize += fsize_step;
			$('content').setStyle('font-size', fsize+'em');
			Cookie.set('megasunFontSize', fsize, {duration: 365, path: '/'});
			break;
		
		case 'cookie':
			$('content').setStyle('font-size', fsize+'em');
			break;
		
		case 'normal':
		default:
			$('content').setStyles('');
			fsize = 1;
			Cookie.remove('megasunFontSize', {path: '/'});
			document.location.href = document.location.href;
	}
}


var layerDisplayStatus = new Array;
// switch layer visibility
function toggleLayerDisplay(whichLayer, status) {
	// store current layer status
	layerDisplayStatus[whichLayer] = status;
	// status: 'none', 'block'	
	if (document.getElementById) {
		// this is the way the standards work
		document.getElementById(whichLayer).style.display = status;
	}
	else if (document.all) {
		// this is the way old msie versions work
		document.all[whichLayer].style.display = status;
	}
	else if (document.layers) {
		// this is the way nn4 works
		document.layers[whichLayer].display = status;
	}
}

window.addEvent('domready', function() {
									 
	var sendafriend = $('sendafriend');
	
	if(sendafriend) {
		
		//var safSlide = new Fx.Slide('sendafriend', {duration: 400, wait: false});
		
		// do not hide send-a-friend form
		if( $('safsuccess') || $('saferror') ) {
			
			var sendafriend_status = true;
			
		} else {
		
			var sendafriend_status = false;
			sendafriend.setStyle('display', 'none');
		
		}
		
		$('safbutton').addEvent('click', function(r) {
												  
			r = new Event(r);
			//safSlide.toggle();
			if(sendafriend_status == true) {
				sendafriend_status = false;
				sendafriend.setStyle('display', 'none');
			} else {
				sendafriend_status = true;
				sendafriend.setStyle('display', '');
			}
			
			r.stop();
													  
		});
	}
									 
	var search_value = 'Suchen';
								 
	// Suche Submit Button ausblenden
	if($('search_left_input')) {

		$('search_left_input').addEvent('focus', function(el) {	
					if(this.value == 'Suchen' || this.value == 'Search' || this.value == 'Ricerca' || this.value == 'Search') { 
						search_value = this.value;
						this.value = '';
					} else { this.select(); }
				}
			).addEvent('blur', function(el) { 
								if(this.value == '') { 
									this.value = search_value; 
								} 
		} );
	
	}


	/* Schriftresizing */
	if( $('content') ) {
		
		var trlang		= {	de: {smaller: 'Schrift verkleinern', normal: 'Schrift zurücksetzen', larger: 'Schrift vergößern'},
							en: {smaller: 'Decrease font size', normal: 'Reset font size', larger: 'Increase font size'},
							it: {smaller: 'Rimpicciolisci i caratteri', normal: 'Resetta i caratteri', larger: 'Ingrandisci i caratteri'},
							us: {smaller: 'Decrease font size', normal: 'Reset font size', larger: 'Increase font size'} };
		
		var fsizeSelect		= new Element('ul', {'class': 'fontsize'}).injectInside( $('shadow') );
		var fsizeSmaller	= new Element('li', {'class': 'smaller', 'title': trlang[current_lang].smaller}).setHTML('<span>A-</span>').injectInside( fsizeSelect );
		var fsizeNormal		= new Element('li', {'class': 'normal', 'title': trlang[current_lang].normal}).setHTML('<span>A=</span>').injectAfter( fsizeSmaller );
		var fsizeLarger		= new Element('li', {'class': 'larger', 'title': trlang[current_lang].larger}).setHTML('<span>A+</span>').injectAfter( fsizeNormal );
		
		fsizeSmaller.addEvent('click', function() { 
				setFontSize('smaller'); 
			} );
		fsizeNormal.addEvent('click', function() { 
				setFontSize('normal');
			} );
		fsizeLarger.addEvent('click', function() {
				setFontSize('larger');
			} );
		
		var fsizecookie = Cookie.get('megasunFontSize');
		if(fsizecookie !== false) {
			fsize = fsizecookie * 1;
			setFontSize('cookie');
		}
	}

	if($$('div.simpletabs')) {
		$$('div.simpletabs').each(function(el) {
			new SimpleTabs(el, {
				entrySelector: 'h3', 
				prefix: '<span>', 
				suffix: '</span>', 
				cookieUsage: false,
				onShow: function(toggle, container, index) {
							toggle.addClass('tab-selected');
							container.setStyle('display', '');
						}
			});
		});
	}
	
	if($('flashheaderswf')) {
		$('headerlogo').remove();
		$('header').setStyle('background-image', 'none');
	}
	
	if($('google_map')) {		
		onLoad();
		unloadGoogleMaps();
	}

	if($('dealer-results')) {
	
		window.location.href = '#dealer-results';

	}
	
});

