﻿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();
    
    updateContainersSize();    
    
    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("mapMoscow") != null)	{

    	if (GBrowserIsCompatible()) {
	       var mapMoscow = new GMap2(document.getElementById("mapMoscow"));
	        mapMoscow.addControl(new GSmallMapControl());
	        mapMoscow.addControl(new GMapTypeControl());        
	    
	        mapMoscow.setCenter(new GLatLng(55.703256,37.692053), 16);			    
		    var point = new GLatLng(55.703256,37.692053);
		
            var marker = new GMarker(point);
            GEvent.addListener(marker, "click", function() {
	            marker.openInfoWindowHtml('000 Вларок. Кровля и изоляция.<br/>г. Москва, 2-й Южнопортовый проезд, д. 16, стр. 2, 1 этаж.');
                });		
		
		    mapMoscow.addOverlay(marker);
		 }
    }

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

    	if (GBrowserIsCompatible()) {
	       var mapPiter = new GMap2(document.getElementById("mapPiter"));
	        mapPiter.addControl(new GSmallMapControl());
	        mapPiter.addControl(new GMapTypeControl());        
	    
	        mapPiter.setCenter(new GLatLng(59.981452,30.360207), 16);			    
		    var point = new GLatLng(59.9815,30.358207);
		
            var marker = new GMarker(point);
            GEvent.addListener(marker, "click", function() {
	            marker.openInfoWindowHtml('000 Вларок. Кровля и изоляция.<br/>г. Санкт - Петербург, ул. Новолитовская, д. 15. офис №63');
                });		
		
		    mapPiter.addOverlay(marker);
		 }
    }
}

function openLayer(movieID) 
{
    window.scrollTo(0, 0);
    document.getElementById('iFrame'+movieID).src='/flashvideo/'+movieID+'/';
    document.getElementById('flashBox'+movieID).style.left='26em';
    pageActiveSwitch('ON',movieID);
}

function closeMovie(movieID) 
{
     document.getElementById('iFrame'+movieID).src='/files/images/main/transparent.gif';
     document.getElementById('flashBox'+movieID).style.left='-99em';
     pageActiveSwitch('OFF', movieID);
}


var pageIsInactive;
function pageActiveSwitch(toggle, movieID, mode) 
{
    if (toggle=="ON") 
    {
        inActiveArea = document.getElementById("documentInactive");
        inActiveArea.innerHTML=
            "<a href='javascript:closeMovie(\""+movieID+"\");'><div style='height:"+(document.body.scrollHeight)+"px; width:"+(document.body.scrollWidth)+"px;' class='documentInactive'></div></a>";    
         pageIsInactive=1;
    }
    else {
        if (pageIsInactive==1) 
        {
            document.getElementById("documentInactive").innerHTML="";
            pageIsInactive=0;
        }
    }

}
