﻿pxInEm = 12;
isIe = false;
isFf = false;
    
if (navigator.appName.indexOf('Microsoft Internet Explorer') != -1)
    isIe = true; 
if (navigator.appName.indexOf('Netscape') != -1)
    isFf = true;    

verticalScroll = null;

function load() {     

    $('container').style.visibility = 'visible';
    
    document.body.onkeyup = 'onkeyup';

   new TransparentNavi('siteNavi');
      
   if (isIe)
     updatePngImages();
      
   updateContainerContent();
    
   updateImagesSize();
   
   if (typeof VerticalScroll != "undefined") {
    
    verticalScroll = new VerticalScroll('scrollItems', 'item', 'control', 'alt');
    verticalScroll.startAutoScroll();
   }
   
   if (typeof HideSelector != "undefined") {
    
        hideSelector = new HideSelector('summary', 'content');        
   }
   
   updateMap();
}

function onkeyup() {
    if (verticalScroll != null) {
        verticalScroll.invalidateContainer();        
    }
}

function updateContainerContent() {         
       
    var containers = document.getElementsByClassName("cc");    
    for (var containerIndex = 0; containerIndex < containers.length; containerIndex++) {        
    
        var container = containers[containerIndex];        
        
        container.style.height = (container.offsetHeight / pxInEm) + 'em';    
    }
}

function updatePngImages() {       
     
     var blankSrc = "/themes/main/images/pixel.gif";
     var images = document.getElementsByTagName("img");
     for (var imageIndex = 0; imageIndex < images.length; imageIndex++) {        
        var image = images[imageIndex];
        var src = image.src;
        if ( /\.png$/.test(src.toLowerCase())) {
      
            image.src = blankSrc;      
            image.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "')";
        }
     }
}

function updateImagesSize() {     
     
     var images = document.getElementsByTagName("img");
     
     for (var imageIndex = 0; imageIndex < images.length; imageIndex++) {
        var image = images[imageIndex];       
                
        /*image.style.width = ((image.offsetWidth) / pxInEm) + 'em';        
        image.style.height = ((image.offsetHeight) / pxInEm) + 'em';        */
     }          
}

function updateMap() {

    if (document.getElementById("map") != null)	{

    	if (GBrowserIsCompatible()) {
	       var map = new GMap2(document.getElementById("map"));
	        map.addControl(new GSmallMapControl());
	        map.addControl(new GMapTypeControl());        
	    
	        map.setCenter(new GLatLng(55.8166, 37.5845), 15);			    
		    var point = new GLatLng(55.8166, 37.5845);
		
            var marker = new GMarker(point);
            GEvent.addListener(marker, "click", function() {
	            marker.openInfoWindowHtml('г. Москва ул. Гончарова 9а');
                });		
		
		    map.addOverlay(marker);
		    
		    		    var polyline = new GPolyline([
  		        new GLatLng(55.8192, 37.5760),
  		        new GLatLng(55.8192, 37.5810),
  		        new GLatLng(55.8160, 37.58185),
  		        new GLatLng(55.8162, 37.5841),
  		        new GLatLng(55.8166, 37.58395),
  		        new GLatLng(55.81665, 37.5843)
		        ], "#ff0000", 5);
		        
		    map.addOverlay(polyline);
		    		    
		    var polyline = new GPolyline([
  		        new GLatLng(55.8122, 37.5832),
  		        new GLatLng(55.81478, 37.58225),
  		        new GLatLng(55.8152, 37.5858),
  		        new GLatLng(55.8164, 37.58535),
  		        new GLatLng(55.81625, 37.5842)
		        ], "#0000ff", 5);
		        
		    map.addOverlay(polyline);
		 }
   }
   }