
function mapsearch()
	{
	var Map, tmp, poi=[], togglers=[], icon = "./files/assets/poi.png";
	if($('#mapcontainer').length)
		{
		
		var preId = (garage!="") ? parseInt(garage) : '';

		Map = new SearchChMap({ center:[665778,256499], zoom:16, circle:false, autoresize:true, disable:"clickzoom", controls:""});
		
		$(locations).each(function()
			{
			if(this.id!="undefined")
				{
				if(typeof(this.id)!="undefined")
					{
					poi[this.id] = new SearchChPOI({ center:this.center, title:this.title, html:this.html, icon:icon });
					Map.addPOI(poi[this.id]);
					}
				}
			});

		var garagenDivs = $('.garage');
		var margin = $('.garage:nth-child(4n+3)').css({'margin-right':0});
		garagenDivs.each(function()
			{
			var id = $(this).attr('id').substr(6,$(this).attr('id').length)
			var el = $(this);
			var h1 = el.find('h1');
			$(h1).wrapInner('<a href="javascript:;"></a>').bind('click',function()
				{
				if(el!=tmp)
					{
					var showEl = locations[id];
					Map.go(showEl); poi[id].open(); 
					}
				tmp=el;
				});
			togglers[id] = $(this).find('a');
			});

		if(preId)
			{
			var isIE6 = false;
			if($.browser.msie && parseInt($.browser.version,0)<7)isIE6=true;
			if(!isIE6){
				$("#garage"+preId).find('a').trigger('click').focus();
				}
			}
		}
	}

function intro() 
	{	
	if($('#intro').length)
		{
		var marken = $('#automarken a').css({opacity:.8});
		
		
		var opacityVisible = 0;
		var opacityInvisible = 0.8;
		
		var intro = $('#intro');
		intro.css({left:'-1000px',opacity:opacityVisible}).animate({opacity:opacityVisible}).animate({left:'0',opacity:1},1200,'backinout');

		var marken = $('#automarken a').css({opacity:opacityVisible,background:'#fff'});
		marken.bind('mouseover',
			function()
				{
				marken.css({opacity:opacityInvisible});
				$(this).css({opacity:opacityVisible});
				var marke = $(this).parent().attr('class');
				$("#teilnehmer area[value*='"+marke+"']").each(function(){
					var showId = $(this).attr('class');
					var rectcoords = $(this).attr('coords');
					var coords = rectcoords.split(',');
					$('#'+showId).css({left:coords[0]-20+'px'}).show();
					if(showId=='akaya' || showId=='dschulter')
						$('#'+showId).addClass('special');
					});
				}
			);
		marken.bind('mouseout',
			function()
				{
				intro.find('.legend:visible').hide().removeClass('special');
				marken.css({opacity:opacityVisible});
				}
			);

		var teilnehmer = $("#teilnehmer area");
		teilnehmer.hover(
			function(e){
				var rectcoords = $(this).attr('coords');
				var coords = rectcoords.split(',');
				var marke = $(this).attr('value');
				var chunks = marke.split(",");
				marken.css({opacity:opacityInvisible});
				var showId = $(this).attr('class');
				$('#'+showId).css({left:coords[0]-20+'px'}).show();
				$(chunks).each(function(){
					$('#automarken .'+this+' a').css({opacity:opacityVisible});
					});
				},
			function(){
				marken.css({opacity:opacityVisible});
				intro.find('.legend:visible').hide();
				}
			);
		}
	} 

function externalLinks() 
	{	
	if (!document.getElementsByTagName) return; 
 	var anchors = document.getElementsByTagName("a"); 
 	for (var i=0; i<anchors.length; i++)
		{ 
   		var anchor = anchors[i]; 
   		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "blank")anchor.target = "_blank"; 
		} 
	} 
	

function handleIE6()
	{
	if($.browser.msie && parseInt($.browser.version,0)<7)
		{
		$(":text").addClass("ie6textinput");
		$("textarea").addClass("ie6textinput");
		$("input[type='password']").addClass("ie6textinput");
		}
	}


$(document).ready(function(){
	mapsearch();
	intro();
	externalLinks();
	handleIE6();
	$('#content h1:first').addClass('firsth1');
});

