﻿function init() {

    div = document.createElement("div");     
    div.style.width = "1em";
    div.style.height = "1em";     
    document.body.appendChild(div);
    pxInEm = div.offsetWidth;
    document.body.removeChild(div);     

    var isIe = false;
    if (navigator.appName.indexOf('Microsoft Internet Explorer') != -1)
        isIe = true;  
    
    if (isIe == true)
        updateImagesPng();
        
    updateImagesSize();
    
    
    //if (document.URL != 'http://www.estetmedic.ru/');
	updateContainersSize();
    
    if (typeof HorizontalScroll != "undefined") {
        var horizontalScroll = new HorizontalScroll('scrollContainer', 'scrollControls', 'scrollItems');
        horizontalScroll.startScroll();
        horizontalScroll.startAutoScroll();
     }
    
    updateMap();
}

function updateImagesPng() {       
     
     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';
     }          
}

function updateContainersSize() {    
         
    var containers = document.getElementsByClassName("cContent");
    for (var containerIndex = 0; containerIndex < containers.length; containerIndex++) {
        var container = containers[containerIndex];
        container.style.height = (container.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.74100, 37.43820), 14);			    
		    var point = new GLatLng(55.740100, 37.43820);
		
            var marker = new GMarker(point);
            GEvent.addListener(marker, "click", function() {
	            marker.openInfoWindowHtml('Москва, Рублевское шоссе, д. 14, корпус 3');
                });		
		
		    map.addOverlay(marker);
		 }
    }
}