var areamap = {
		
	/** Das Kartenobjekt */
	map: null,
	
	/** Pushpin */
	pin: null,
		
	/** Die default Kartenansicht */
	mapStyle: "r",
	
	/** Default-Zoom */
	zoomLevel: 4,
	
	/** Location */
	loc: null,
	
	/** IconUrl */
	iconUrl: "/img/icons/ico_haus_karte.gif",
	
	/** Map initialisieren */
	getMap: function(lati,longi) {
		this.loc = new Microsoft.Maps.Location(lati,longi);
		map = new Microsoft.Maps.Map(document.getElementById("myMap"), {credentials:"Al0RrObRrrnGKp2AniIEzro8aQrvp_4w1RbsOu1c0NZChTvrO1G95rI8QOFlnjAB",
			mapTypeId: Microsoft.Maps.MapTypeId.road,
			center: this.loc,
			zoom: this.zoomLevel
			});
	},
	
	/** PushPin darstellen */
	pushPin: function() {
		 pin = new Microsoft.Maps.Pushpin(this.loc,{icon: this.iconUrl});
		map.entities.push(pin);
	},
	
	/** Infobox darstellen */
	infoBox: function(title,text,sticky) {
        if(sticky == 1){
        	var infoboxOptions = {showCloseButton: true, zIndex: 0, offset:new Microsoft.Maps.Point(8,150), showPointer: true}; 
            pinInfobox = new Microsoft.Maps.Infobox(pin.getLocation(),infoboxOptions);
        	
            // Infobox beim hovern anzeigen
            Microsoft.Maps.Events.addHandler(pin, 'mouseover', this.displayInfobox);
            
	        // Infobox beim Map bewegen verstecken
	        Microsoft.Maps.Events.addHandler(map, 'viewchange', this.hideInfobox);
        } else {
        	var infoboxOptions = {showCloseButton: true, zIndex: 0, offset:new Microsoft.Maps.Point(-50,50), showPointer: true}; 
        	pinInfobox = new Microsoft.Maps.Infobox(map.getCenter(),infoboxOptions);

        	// Infobox beim klicken verstecken
            Microsoft.Maps.Events.addHandler(pinInfobox, 'click', this.hideInfobox);

        }
        map.entities.push(pinInfobox);
        pinInfobox.setHtmlContent('<div id="infoBox"><div class="title">' + title + '</div><div class="content">'+text+'</div></div>');
		
	},
	displayInfobox: function() {
		pinInfobox.setOptions({ visible:true });
	},
	hideInfobox: function() {
		pinInfobox.setOptions({ visible:false });
	}
};

var image = {
		switchImage: function(container, url) {
			$j(container).find("span").css('opacity',1);
			$j(container).find("img").css('opacity',0.5);
			var src = url;
			var imgObject = $j('#changeboxImage');
			   if (src != imgObject.attr('src')) {
				   		imgObject.stop().animate({opacity:'0'},100,function(){
			            $j(this).attr('src',src);
			        }).load(function(){
			            $j(this).stop().animate({opacity:'1'},100);
			        });
			    }
		},
		fadeBack: function(container){
			$j(container).find("img").css('opacity',1);
			$j(container).find("span").css('opacity',0);
            $j(this).addClass("active");
		},
		posFix: function(object,container) {
			var imgHeight = object.height();
			if(imgHeight < container && imgHeight > 0) {
	           difHeight = Math.round((container - imgHeight)/2);
	           object.parent("a").prepend('<img src="/img/trans.gif" height="'+difHeight+'" />');
			}	
		}
};

var site = {
	scroller: function(magicBorder, myPos, myBox, myStop) {
		var myBoxSize = myBox.height();
		if((myPos + myBoxSize) > myStop)
		{
			myBox.css("position", "absolute");
			myBox.css("top",(myStop-myBoxSize)+"px");	
		} else {
			if( myPos > magicBorder) {
				if(myBox.css("position") != "fixed"){
					myBox.css("position", "fixed");
					myBox.css("top","0px");	
				}
			} else {
				if(myBox.css("position") != "static"){
					myBox.css("position", "static");
				}
			}	
			
			
		}
		

	},
	globals: function() {
		$j("a[rel='cbox']").colorbox({previous:"zurück",next:"weiter",close:"schließen",transition:"none"});
		$j("a[rel='cboxText']").colorbox({previous:"zurück",next:"weiter",close:"schließen",transition:"none",width:"600px"});
		$j('.showhidden').click(function(){
				$j('.hidden').slideToggle("slow");
				$j('.showhidden').hide();
		});
		$j("#parentcatCombined").change( function(){
		var combinedVal = $j(this).val().split("_");
		var parentcat = combinedVal[0];
		var marketingtype = combinedVal[1];
		if(parentcat != null && marketingtype != null){
			$j("#parentcat").val(parentcat);
			$j("#marketingtype").val(marketingtype);
		}
		if(parentcat != null && marketingtype == null){
			$j("#parentcat").val(parentcat);
			$j("#marketingtype").val("-1");
		}
	})  	
	}
};
