﻿// Mapy google

var map;
var directionDisplay;
var directionsService;
var stepDisplay;
var markerArray = [];
var infowindow2;
  
function initialize() 
{
	    // Instantiate a directions service.
    directionsService = new google.maps.DirectionsService();
	
	// Create a map and center it on Oborniki Śląskie.
	var myLatlng = new google.maps.LatLng(51.302246,16.928194);
	var myOptions = 
	{
		zoom: 16,
		mapTypeId: google.maps.MapTypeId.ROADMAP,
		center: myLatlng
    }

	map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	
	
	var contentString = '<div id="content">'+
		'<div id="bodyContent">'+
		'<p><b>Carjar</b> - balkony, ogrodzenia, bramy, <br>balustrady, poręcze, metaloplastyka </p>' +
		'Jarosław Paleń <br>'+
		'ul. Górna 42<br>'+
		'55-120 Oborniki Śląskie <br>'+
		'woj. dolnośląskie <br>'+
		'</div>'+
		'</div>';
			
		infowindow2 = new google.maps.InfoWindow({
		content: contentString
	});
	
	var marker2 = new google.maps.Marker({
		position: myLatlng,
		map: map,
		title: 'Carjar - balkony i ogrodzenia'
	});
infowindow2.open(map,marker2);
	
	        // Create a renderer for directions and bind it to the map.
    var rendererOptions = {
      map: map
    }
    directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions)
    
    // Instantiate an info window to hold step text.
    stepDisplay = new google.maps.InfoWindow();
  }

  function calcRoute() {
infowindow2.close();
  
    // First, remove any existing markers from the map.
    for (i = 0; i < markerArray.length; i++) {
      markerArray[i].setMap(null);
    }

    // Now, clear the array itself.
    markerArray = [];

    // Retrieve the start and end locations and create
    // a DirectionsRequest using WALKING directions.
	var skladanka_1 = document.getElementById("ulica").value;
	var skladanka_2 = document.getElementById("miasto").value;
    var start = skladanka_1+","+skladanka_2+", PL";
    var end = 'Górna 42, Oborniki Śląskie, PL';
    var request = {
        origin: start,
        destination: end,
        travelMode: google.maps.DirectionsTravelMode.WALKING
    };

    // Route the directions and pass the response to a
    // function to create markers for each step.
    directionsService.route(request, function(response, status) {
      if (status == google.maps.DirectionsStatus.OK) {
        var warnings = document.getElementById("warnings_panel");
	    warnings.innerHTML = "<b>" + response.routes[0].warnings + "</b>";
        directionsDisplay.setDirections(response);
		if (document.forms[0].czeker.checked){
        showSteps(response);
		}
      }
    });
  }

  function showSteps(directionResult) {
    // For each step, place a marker, and add the text to the marker's
    // info window. Also attach the marker to an array so we
    // can keep track of it and remove it when calculating new
    // routes.
    var myRoute = directionResult.routes[0].legs[0];

    for (var i = 0; i < myRoute.steps.length; i++) {
      var marker = new google.maps.Marker({
        position: myRoute.steps[i].start_point, 
        map: map
      });
      attachInstructionText(marker, myRoute.steps[i].instructions);
      markerArray[i] = marker;
    }
  }

  function attachInstructionText(marker, text) {
    google.maps.event.addListener(marker, 'click', function() {
      // Open an info window when the marker is clicked on,
      // containing the text of the step.
      stepDisplay.setContent(text);
      stepDisplay.open(map, marker);
    });
}

/*--------------------------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------------------------*/



//<body onLoad="preloadImages('images/balkony_click.jpg','images/ogrodzenia_click.jpg','images/kontakt_click.jpg')">
function preloadImages() 
{
	var doc = document;
	if(doc.images)
	{
		if(!doc.array_to_handle) 
		{
			doc.array_to_handle = new Array();
		}
		var i;
		var j = doc.array_to_handle.length;
		var array_of_arguments = preloadImages.arguments; 
		
		for(i = 0; i < array_of_arguments.length; i++)
		{
			if (array_of_arguments[i].indexOf("#")!=0)
			{
				doc.array_to_handle[j] = new Image; 
				doc.array_to_handle[j++].src = array_of_arguments[i]; 
				//JS najpierw odczyta sobie wartość j (użyje jej), a następnie zmieni wartość zmiennej dla następnego loopa
			}
		}
	}
}

function swapImgRestore() 
{
	var i;
	var x;
	var a = document.sr;
	for(i = 0; a && i<a.length && (x = a[i]) && x.oSrc; i++) 
	{
		x.src = x.oSrc;
	}
}

function findObj(n, doc) 
{ 
	var p,i,x;  
	if(!doc) doc = document; 
	if((p = n.indexOf("?"))>0 && parent.frames.length) 
	{
		doc = parent.frames[n.substring(p+1)].document; n = n.substring(0,p);
	}
	if(!(x = doc[n]) && doc.all) x = doc.all[n]; 
	for (i=0; !x && i<doc.forms.length; i++) x = doc.forms[i][n];
	for(i=0; !x && doc.layers && i<doc.layers.length; i++) x = findObj(n,doc.layers[i].document);
	if(!x && doc.getElementById) x = doc.getElementById(n); 
	return x;
}
//onMouseOver="swapImage('balkony_button','','images/balkony_click.jpg',1)"
function swapImage() 
{
	var i;
	var j = 0;
	var x;
	var a = swapImage.arguments; 
	document.sr = new Array; 
	for(i = 0; i < (a.length - 2); i += 3)
	if ((x = findObj(a[i])) != null)
	{
		document.sr[j++] = x; 
		if(!x.oSrc) 
		{
			x.oSrc = x.src;
		}
		x.src = a[i+2];
	}
}
function divVisibility(name, on_off)
{
	if(on_off == 1)
	{
		document.getElementById(name).style.visibility = 'visible';
	}
	else if(on_off == 0)
	{
		document.getElementById(name).style.visibility = 'hidden';
	}
}


function changeDivProperties(name, Left, Top, Width, Height, mxWidth, mxHeight, overf)
{
	var handler = document.getElementById(name).style;
	if(Left) handler.left = Left;
	if (Top) handler.top = Top;
	if (Width) handler.width = Width;
	if (Height) handler.height = Height;
	if (mxWidth) handler.maxWidth = mxWidth;
	if (mxHeight) handler.maxHeight = mxHeight;
	if  (overf) handler.overflowY = overf;
//	else
//	{
		//handler.removeAttribute('overflowY');
//		handler.setAttribute("overflowY","hidden");
//	}
}

function changeClass(div, klasa)
{
	document.getElementById(div).className = klasa;
}

function changeContent(objectID, content)
{
	var data = content;
	var handler = document.getElementById(objectID).innerHTML = data;
}
function changeBackground(background)
{
	document.getElementById('tabela_docelowa').style.backgroundImage = "url(images/"+background+")";
}

function complicatedString ()
{
	var data = 'CARJAR Jarosław Paleń<br>'+
'ul. Górna 42<br>'+
'55-120 Oborniki Śląskie<br>'+
'woj. dolnośląskie<br>'+
'<br>'+
'Jarosław Paleń 667-265-014<br>'+
'Eugeniusz Paleń 663-943-957<br><br>'+
'\n'+
'biuro@carjar.pl'+
'<br><br>'+
'\n'+
'<a href'+"\="+'\"#\"'+
' onClick=\"initialize(); divVisibility(\'map_canvas\', 1); divVisibility(\'guziki_mapy\', 1) \">Kliknij, aby zobaczyć mapę</a>';

changeContent('divIntro', data);
}

function resolution()
{
	var data = screen.availHeight + "px";
	document.getElementById('divAlbum').style.height = data;
	data = screen.availWidth + 'px';
	document.getElementById('divAlbum').style.width = data;
}
