﻿function $(id){return document.getElementById(id)};
ie=false;
safari=false;

mailText="Почтовый адрес: 65000, Украина, г. Одесса, ул. Рекордная, 25; Е-mail contact@kmdom.com";
telText="Телефоны: (0482) 37-23-27 и (0482) 375-308; тел./факс: (0482) 375-308";
infoText="Строительство Каркасно-модульных домов. Поставка комплектов для Каркасно-модульного строительства. Проект строительной компании «Торсион».";
selectedText=infoText;
//hintsArray=new Array("");

function getBounds(element)
{
  var left = element.offsetLeft;
  var top = element.offsetTop;
  for (var parent = element.offsetParent; parent; parent = parent.offsetParent)
  {
    left += parent.offsetLeft - parent.scrollLeft;
    top += parent.offsetTop - parent.scrollTop
  }
  return {left: left, top: top, width: element.offsetWidth, height: element.offsetHeight};
};


function getOpacityProperty()
{
	var p;
	if (typeof document.body.style.opacity == 'string') p = 'opacity';
	else if (typeof document.body.style.MozOpacity == 'string') p =  'MozOpacity';
	else if (typeof document.body.style.KhtmlOpacity == 'string') p =  'KhtmlOpacity';
	else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) p =  'filter';
	
	return (getOpacityProperty = new Function("return '"+p+"';"))();
}

function setElementOpacity(oElem, nOpacity)
{
	var p = getOpacityProperty();
	(setElementOpacity = p=="filter"?new Function('oElem', 'nOpacity', 'nOpacity *= 100;	var oAlpha = oElem.filters["DXImageTransform.Microsoft.alpha"] || oElem.filters.alpha;	if (oAlpha) oAlpha.opacity = nOpacity; else oElem.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")";'):p?new Function('oElem', 'nOpacity', 'oElem.style.'+p+' = nOpacity;'):new Function)(oElem, nOpacity);
}

function replaceText(onText)
{
    $("headTitle").removeChild($("headTitle").firstChild);
    $("headTitle").appendChild(document.createTextNode(onText))
}

function init()
{
   $("info").className="info-active";
   currentActive="info";
   $("mail").onmouseover=function(){replaceText(mailText);$(currentActive).className=""};
    $("tel").onmouseover=function(){replaceText(telText);$(currentActive).className=""};
    $("info").onmouseover=function(){replaceText(infoText);$(currentActive).className=""};
    
    $("mail").onmouseout=function(){replaceText(selectedText);$(currentActive).className=currentActive+"-active";};
    $("tel").onmouseout=function(){replaceText(selectedText);$(currentActive).className=currentActive+"-active";};
    $("info").onmouseout=function(){replaceText(selectedText);$(currentActive).className=currentActive+"-active";};
    
    $("mail").onclick=function(){selectedText=mailText;currentActive="mail";};
    $("tel").onclick=function(){selectedText=telText;currentActive="tel";};
    $("info").onclick=function(){selectedText=infoText;currentActive="info";};

   prev=undefined;
   fade=undefined;
   animID=undefined;
   currentOpacityValue=undefined;
   what=undefined;
   how=undefined;
   oldX=0;
   function anime()
   {
        newOpacityValue=currentOpacityValue+(how-currentOpacityValue)/4;
        setElementOpacity(what,newOpacityValue);
        currentOpacityValue=newOpacityValue;
        if(Math.abs(how-currentOpacityValue)<0.2)
        {
            setElementOpacity(what,how);
            clearInterval(animID);
        } ;
                
   };
   
   
   for(i=0;i<$("downNavigator").childNodes.length;i++)
    {      
       
       if(ie){object= $("downNavigator").childNodes[i].childNodes[0]}else{object=$("downNavigator").childNodes[i]}
       object.onmouseover=function()
        {
           objectThis=this;
           if(ie){obj=this.parentNode.childNodes[1]}else{obj=this.childNodes[1]}
            setElementOpacity(obj,0);
            currentOpacityValue=0;
            obj.style.display="block";
            if(animID)
            {
                clearInterval(animID)
                setElementOpacity(prev,0);
            };
            what=obj;
            how=1;
            animID=setInterval(anime,50)
            this.onmousemove=function(event)
            {
               var bounds=getBounds(this);
               /*if(ie)
               { 
                scrX=window.event.screenX;
                scrY=window.event.screenY;
               }
               else
               {
                scrX=event.screenX;
                scrY=event.screenY;
               };
               */
               if(opera){delta=120}else{delta=150};
               what.style.marginLeft=event.screenX-bounds.left+doc.scrollLeft+"px";
               what.style.marginTop=event.screenY-bounds.top+doc.scrollTop-delta+"px";
            };
        };
       object.onmouseout=function()
        {
            clearInterval(animID);
            if(ie){obj=this.parentNode.childNodes[1]}else{obj=this.childNodes[1]}
            what=obj;
            how=0;
            animID=setInterval(anime,50)
            prev=what;
        };
    }
    
    if($("plan-1"))
    {
        savedImgSrc=$("imgProject").src;
        $("plan-1").onmouseover=function(){$("imgProject").src=this.src}
        $("plan-1").onmouseout=function(){$("imgProject").src=savedImgSrc}
    }
    if($("plan-2"))
    {
        savedImgSrc=$("imgProject").src;
        $("plan-2").onmouseover=function(){$("imgProject").src=this.src}
        $("plan-2").onmouseout=function(){$("imgProject").src=savedImgSrc}
    }
};

opera=false;
switch(navigator.appName)
{
	case "Microsoft Internet Explorer":
		doc=document.documentElement;
		window.attachEvent("onload",init);
		ie=true;
		break    
	case "Netscape":
		if(navigator.vendor=="Apple Computer, Inc.") //SAFARI
		{
			window.onload=init;
			safari=true;
		}
		else                                         //FIREFOX
		{
			doc=document.documentElement;
			document.addEventListener("DOMContentLoaded", init, false);
		};
		break
	default:
		doc=document.documentElement;
		window.onload = init;	
        opera=true;
};