

// Set background
$(function(){
	$.fn.supersized.options = {  
		startwidth: 640,  
		startheight: 480,
		vertical_center: 1,
		slideshow: 0,
		navigation: 0,
		transition: 1, //0-None, 1-Fade, 2-slide top, 3-slide right, 4-slide bottom, 5-slide left
		pause_hover: 0,
		slide_counter: 1,
		slide_captions: 1,
		slide_interval: 3000  
	};
	$('#supersize').supersized(); 
	
	$("#accordion").tabs("#accordion div.pane", {
		effect: 'horizontal',
		onClick: function(e,i){
			var sel = this.getIndex();
			var idx = 0;
			this.getTabs().each(function(){
				if (idx < sel) {
					$('#accordion a.tab'+(idx+1)).css('background-position', '0 0');
				}else if (idx > sel) {
					$('#accordion a.tab'+(idx+1)).css('background-position', '-33px 0');
				}else{
					$('#accordion a.tab'+(idx+1)).css('background-position', '-66px 0');
				}
				idx++;
			});
		}
	}).history();
	
	$("#projectHistory").tabs("#projectHistory div.pane", {tabs: 'h4', effect: 'slide'});
	
	$(".menu div.fl").mouseenter(function(){
		if ($(this).hasClass('mouseover')) {
			subtopiaMenuScripted = 0;
		}else{
			$(this).toggleClass('mouseover');
			subtopiaMenuScripted = 1;
		}
	}).mouseleave(function(){
		if (subtopiaMenuScripted == 1) {
			$(this).toggleClass('mouseover');
			subtopiaMenuScripted = 0;
		}
	});
	
	$(".sub .contact .button").click(function(){
		$(".sub .contact .more").css('visibility', 'visible');
		$(".sub .contact").animate({top: 0},function(){
			$(".sub .contact .button").css('cursor', 'default');
			$(".sub .contact .button .show").remove();
		});
	});
});

var subtopiaMenuScripted = 0;
var googleMap; // = new GMap2(document.getElementById('mapView'));
var googleDirectionsPanel;
var googleDirections;
function getRoute() {
	if (googleDirections) {
		googleDirections.clear();
	}
	
	googleDirectionsPanel = document.getElementById("routeDetails");
	googleDirections = new GDirections(googleMap, googleDirectionsPanel);
	var destination = $("#googleDestination").val();
	var query = "from: "+destination+" to: Rotemannavagen 10, 14557 Norsborg";
	googleDirections.load(query);
	var status = googleDirections.getStatus();
	
	switch (status.code) {
		case G_GEO_BAD_REQUEST:
			/* 
			 * A directions request could not be successfully parsed. For example, the
			 * request may have been rejected if it contained more than the maximum
			 * number of waypoints allowed.
			 */
			alert("Ett fel uppstod, vad god försök igen.");
			break;
		case G_GEO_SERVER_ERROR:
			/*
			 * A geocoding, directions or maximum zoom level request could not be
			 * successfully processed, yet the exact reason for the failure is not known.
			 *
			 * Google seems to return this error for successful searches so you can't
			 * rely on this message.
			 */
			if (googleDirections.getNumRoutes() == 0) {
				alert("Ett okänt fel uppstod, försök igen.");
			}
			break;
		case G_GEO_MISSING_QUERY:
		case G_GEO_MISSING_ADDRESS:
			/*
			 * The HTTP q parameter was either missing or had no value. For geocoding
			 * requests, this means that an empty address was specified as input. For
			 * directions requests, this means that no query was specified in the input.
			 */
			alert("Du måste ange en adress att resa ifrån.");
			break;
		case G_GEO_UNKNOWN_ADDRESS:
			/*
			 * No corresponding geographic location could be found for the specified
			 * address. This may be due to the fact that the address is relatively new,
			 * or it may be incorrect.
			 */ 
			alert("Adressen du angav kunde inte hittas, kontrollera stavningen.\n\nOm adressen är ny kan du ange en adress i närheten.");
			break;
		case G_GEO_UNAVAILABLE_ADDRESS:
			/*
			 * The geocode for the given address or the route for the given directions
			 * query cannot be returned due to legal or contractual reasons. 
			 */
			alert("Adressen du angav kan inte visas pga juridiska skäl. Ange en annan adress.");
			break;
		case G_GEO_UNKNOWN_DIRECTIONS:
			/*
			 * The GDirections object could not compute directions between the points
			 * mentioned in the query. This is usually because there is no route
			 * available between the two points, or because we do not have data for
			 * routing in that region.
			 */
			alert("Kunde inte beräkna resvägen mellan adresserna, ange en annan adress.");
			break;
		case G_GEO_BAD_KEY:
			/*
			 * The given key is either invalid or does not match the domain for which it
			 * was given.
			 */
			alert("Ett tekniskt fel har uppstått, försök igen.");
			break;
		case G_GEO_TOO_MANY_QUERIES:
			/*
			 * The given key has gone over the requests limit in the 24 hour period or
			 * has submitted too many requests in too short a period of time. If you're
			 * sending multiple requests in parallel or in a tight loop, use a timer or
			 * pause in your code to make sure you don't send the requests too quickly.
			 */ 
			alert("För många förfrågningar. Försök igen om en stund.");
			break;
		case G_GEO_SUCCESS:
		default:
			/*
			 * No errors occurred; the address was successfully parsed and its geocode
			 * has been returned.
			 */
		
	}
}
function initMap() {
	googleMap = new GMap2(document.getElementById('mapView'));
	var subtopia = new GLatLng(59.23967,17.858051);
	googleMap.setCenter(subtopia, 16);
	googleMap.setMapType(G_HYBRID_MAP);
	googleMap.setUIToDefault();
	googleMap.addOverlay(new GMarker(subtopia));
}

