﻿$(document).ready(function() {
	var accordeons = $('.accordeon');

	for (var i = 0; i < accordeons.length; i++) {
		$(accordeons[i]).children('h2')
			.hover(function() { //set hover
				$(this).css({ cursor: 'pointer' });
			})
			.css({ background: 'url(res/img/upDownArrow.png) right no-repeat #EDE5D1', color: '#C3A967' }) // set bg image
			.click(function() { //bind slide
				$(this).next().slideToggle(800);
			});
	}
});

var GoogleMap = null;
var GoogleMapSmall = null;
var Gmap_Markers = new Array();
var GmapSmall_Markers = new Array();
var infoWindows = new Array();
var markerImage = new google.maps.MarkerImage("res/img/map/marker.png", new google.maps.Size(20, 34), new google.maps.Point(0, 0), new google.maps.Point(10, 34));
var markerShadow = new google.maps.MarkerImage("res/img/map/markershadow.png", new google.maps.Size(37, 34), new google.maps.Point(0, 0), new google.maps.Point(10, 34));

function ToggleMap() {
	var visible = $("#mapContainer").is(":visible");
	$("#mapText").html(visible ? "Karte vergr&ouml;&szlig;ern" : "Vergr&ouml;&szlig;erung schlie&szlig;en");

	if (!visible) {
		$("#mapContainer").show();
		if (GoogleMap == null) {
			SetupMap();
		}
	} else {
		$("#mapContainer").hide();
	}
}

function ToggleDirections() {
	var visible = $("table.gadget").is(":visible");
	$("#directions").html(visible ? "Routenplaner anzeigen" : "Routenplaner ausblenden");
	$("table.gadget").toggle();
}

function SetupMap() {
	var myOptions = {
		zoom: 8,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};

	GoogleMap = new google.maps.Map(document.getElementById("maplarge"), myOptions);

	var bounds = new google.maps.LatLngBounds();

	if (Gmap_Markers.length > 0) {
		for (var m in Gmap_Markers) {
			bounds.extend(Gmap_Markers[m].getPosition());
			Gmap_Markers[m].setMap(GoogleMap);
		}
	}
	else {
		var gLatLng = new google.maps.LatLng(47.857040997, 13.120130816);
		bounds.extend(gLatLng);

		var marker = new google.maps.Marker({
			position: gLatLng,
			icon: markerImage,
			shadow: markerShadow
		});
		var contentString = "<p class='ZipExact'>Leider keine Treffer!</p>";
		var infowindow = new google.maps.InfoWindow({
			content: contentString
		});

		setTimeout(function() {
			infowindow.open(GoogleMap, marker);
		}, 350);

		marker.setMap(GoogleMap);
	}

	if (Gmap_Markers.length == 1) {
		GoogleMap.setCenter(bounds.getCenter());
		GoogleMap.setZoom(15);
	}
	else {
		GoogleMap.fitBounds(bounds);
	}
}

function SetupSmallMap() {
	if (GoogleMapSmall != null) {
		return;
	}

	var myOptions = {
		zoom: 8,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		disableDefaultUI: true
	};

	GoogleMapSmall = new google.maps.Map(document.getElementById("mapsmall"), myOptions);

	var bounds = new google.maps.LatLngBounds();

	if (GmapSmall_Markers.length > 0) {
		for (var m in GmapSmall_Markers) {
			bounds.extend(GmapSmall_Markers[m].getPosition());
			GmapSmall_Markers[m].setMap(GoogleMapSmall);
		}

		if (GmapSmall_Markers.length == 1) {
			GoogleMapSmall.panToBounds(bounds);
			GoogleMapSmall.setCenter(bounds.getCenter());
			GoogleMapSmall.setZoom(15);
		}
		else {
			GoogleMapSmall.fitBounds(bounds);
		}
	}
	else {
		/* FirmenABC Headquarters */
		var gLatLng = new google.maps.LatLng(47.857040997, 13.120130816);
		bounds.extend(gLatLng);
		GoogleMapSmall.setZoom(5);
		GoogleMapSmall.setCenter(bounds.getCenter());
	}
}

function AddPin(latitude, longitude, companyname, address, city, zipexact, link, isPremium) {
	if (latitude == 0 || longitude == 0) {
		return;
	}

	var text = "<p><strong>" + companyname + "</strong><br />" + address + "<br />" + city + "</p>";
	if (typeof (zipexact) == "boolean" && zipexact) {
		text += "<p>Achtung: Diese Position ist nur PLZ-genau!</p>"
	}
	if (link != null && link != '') {
		text += "<br /><p><a href=\"" + link + "\"><strong>&gt;Zum Profil</strong></a></p>"
	}

	if (typeof (isPremium) == "boolean" && isPremium) {
		markerImage = new google.maps.MarkerImage("res/img/map/marker.png", new google.maps.Size(20, 34), new google.maps.Point(0, 0), new google.maps.Point(10, 34));
		markerShadow = new google.maps.MarkerImage("res/img/map/markershadow.png", new google.maps.Size(37, 34), new google.maps.Point(0, 0), new google.maps.Point(10, 34));
	}
	else {
		markerImage = new google.maps.MarkerImage("res/img/map/marker.png", new google.maps.Size(20, 34), new google.maps.Point(0, 0), new google.maps.Point(10, 34));
		markerShadow = new google.maps.MarkerImage("res/img/map/markershadow.png", new google.maps.Size(37, 34), new google.maps.Point(0, 0), new google.maps.Point(10, 34));
	}

	var pos = new google.maps.LatLng(latitude, longitude);

	var marker = new google.maps.Marker({
		position: pos,
		icon: markerImage,
		shadow: markerShadow
	});

	var marker2 = new google.maps.Marker({
		position: pos,
		icon: markerImage,
		shadow: markerShadow
	});

	var infowindow = new google.maps.InfoWindow({
		content: text
	});

	infoWindows.push(infowindow);

	google.maps.event.addListener(marker2, 'mouseover', function() {
		for (m in infoWindows) {
			infoWindows[m].close();
		}
		infowindow.open(GoogleMap, marker2);
	});
	if (link != null && link != '') {
		google.maps.event.addListener(marker, 'click', function() {
			window.location.href = link;
		});
		google.maps.event.addListener(marker2, 'click', function() {
			window.location.href = link;
		});
	}

	GmapSmall_Markers.push(marker);
	Gmap_Markers.push(marker2);
}

//FABC Searchbox

function DoFabcSearch() {
	var werwas = $('#werwas').val();
	var wo = $('#wo').val();
	window.open("http://www.firmenabc.at/result.aspx?what=" + werwas + "&where=" + wo + "&exact=false&inTitleOnly=false&l=&si=0&iid=&sid=&did=&cc=");
}

function ToggleDirections() {
	var visible = $("table.gadget").is(":visible");
	$("#directions").html(visible ? "Routenplaner anzeigen" : "Routenplaner ausblenden");
	$("table.gadget").toggle();
}
