function init(){
//    return
    helloBrowser();
    initTop(500);
    rightDate();
    if(NoScroll)scroll();
    photoSwitcher();
}
function rightDate(){
    var right=document.getElementById("rightReserved");
    if(right!=null){
        var text=document.getElementById("rightReserved").innerHTML;
        text=text.substr(0,text.length-4)+new Date().getFullYear().toString();
        right.innerHTML=text
    }
}
var device={browser:"",os:"",browserVersion:-1},NoScroll=true;
function helloBrowser(){
    device.browser=navigator.userAgent;
    device.os=navigator.platform;
    if(device.os.indexOf("Mac")!=-1)device.mac=true;
    if(device.os.indexOf("iPhone")!=-1)device.iphone=true;
    if(device.os.indexOf("iPad")!=-1){device.ipad=true;}
    if(device.os.indexOf("Win")!=-1)device.windows=true;
    if(device.browser.indexOf("Firefox")!=-1){
        device.browserVersion=parseFloat(device.browser.substr(device.browser.lastIndexOf("/")+1,4));
        device.fx=true;
        if(device.browserVersion<3.5)document.body.className+=" oldBrowser"
    }
    else if(device.browser.indexOf("Chrome")!=-1){
        device.browserVersion=parseFloat(device.browser.substr(device.browser.indexOf("Chrome/")+7,4));
        device.chrome=true;
        if(device.browserVersion<4)document.body.className+=" oldBrowser";
        document.body.className+=" Chrome";
    }
    else if(device.browser.indexOf("Safari")!=-1){
        device.browserVersion=parseFloat(device.browser.substr(device.browser.indexOf("Version/")+8,4));
        device.safari=true;
        if(device.browserVersion<4)document.body.className+=" oldBrowser"
    }
    else if(device.browser.indexOf("MSIE")!=-1){
        device.browserVersion=parseFloat(device.browser.substr(device.browser.indexOf("MSIE")+5),3);
        device.ie=true;
    }
    else if(device.browser.indexOf("Opera")!=-1){
        device.browserVersion=parseFloat(device.browser.substr(device.browser.indexOf("Version/")+8,4));
        device.opera=this;
        if(device.browserVersion<11)document.body.className+=" oldBrowser"
    }
    else document.body.className+=" oldBrowser"
}
function scroll(){
    var fixedPart={object:[]};
    fixedPart.object=getElementsByClassName("mobile-text-part",document.body);
    if(fixedPart.object[0]==null||(device.ie&&device.browserVersion<7)||device.iphone||device.ipad)return;
    var i=-1,pageY=-1,alphaInterval=-1;
    fixedPart.oParent=[];
    fixedPart.osMap=[];
    fixedPart.oHeight=[];
    fixedPart.oParentHeight=[];
    fixedPart.param=[];
    fixedPart.param2=[];
    for(i=0;i<fixedPart.object.length;i++){
        fixedPart.oParent[i]=fixedPart.object[i].parentNode;
        fixedPart.osMap[i]=getAbsolutePositionY(fixedPart.object[i]);
        fixedPart.oHeight[i]=fixedPart.object[i].offsetHeight;
        fixedPart.object[i].style.height=fixedPart.oHeight[i]+"px";
        fixedPart.oParentHeight[i]=fixedPart.oParent[i].offsetHeight;
        fixedPart.param[i]=0;
        fixedPart.param2[i]=0;
    }
    alphaInterval=window.setInterval(function(){
        device.ie&&device.browserVersion<9?pageY=document.documentElement.scrollTop:pageY=window.pageYOffset;
        for(i=0;i<fixedPart.object.length;i++){
            (function(i){
                fixedPart.param[i]=pageY-fixedPart.osMap[i];
                fixedPart.param2[i]=fixedPart.param[i]+fixedPart.oHeight[i]+60;
                if(fixedPart.param[i]>0&&fixedPart.param2[i]<fixedPart.oParentHeight[i]){
                    if(fixedPart.object[i].className.indexOf("bottomFix")!=-1)fixedPart.object[i].className=fixedPart.object[i].className.replace("bottomFix","");
                    if(fixedPart.object[i].className.indexOf("fixed")==-1)fixedPart.object[i].className+=" fixed"
                }
                if(fixedPart.param2[i]>fixedPart.oParentHeight[i]){
                    if(fixedPart.object[i].className.indexOf("fixed")!=-1)fixedPart.object[i].className=fixedPart.object[i].className.replace("fixed","bottomFix");
                    if(fixedPart.object[i].className.indexOf("bottomFix")==-1)fixedPart.object[i].className+=" bottomFix"
                }
                if(pageY<fixedPart.osMap[i]){
                    if(fixedPart.object[i].className.indexOf("fixed")!=-1)fixedPart.object[i].className=fixedPart.object[i].className.replace("fixed","");
                    if(fixedPart.object[i].className.indexOf("bottomFix")!=-1)fixedPart.object[i].className=fixedPart.object[i].className.replace("bottomFix","")
                }
            })(i)
        }
    },1)
}
function photoSwitcher(){
    if(document.getElementById("aboutPhotoBlock")==null)return;
    var switcher=document.getElementById("aboutPhotoBlock"),photos,timer=-1,size=-1,state=1,i=-1;
    device.fx&&device.browserVersion<3?photos=switcher.childNodes[1].childNodes:photos=switcher.children[0].children;
    state=size=photos.length;
    timer=window.setInterval(function(){
        fadeOut(photos[state-1],500);
        (function(state){window.setTimeout(function(){fadeIn(photos[state==1?size-1:state-2],500)})})(state);
        state==1?state=size:state-=1
    },5000);
}
function fadeIn(object,time,doingFunction,noie){
    var fade,opacity=0,coefficient=0.04;
    if(!device.ie){
        object.style.opacity=0;
        object.style.display="block";
        object.style.visibility="visible";
        if(time==null)time=1;
        else if(time<=500){time=1}
        else{time=time/500}
        fade=setInterval(function(){
            opacity+=coefficient;
            if(opacity>=1-coefficient&&opacity<=1+coefficient){
                window.clearInterval(fade);
                fade=-1;
                object.style.opacity=1;
                if(doingFunction!=null)doingFunction();
                return false
            }
            object.style.opacity=opacity
        },time)
    }
    else{
        if(noie){
            object.style.visibility="visible";
            object.style.display="block";
            if(doingFunction!=null)doingFunction()
        }
        else{
            object.style.filter="blendTrans(duration=1)";
            if(object.filters.blendTrans.status!=1){
                object.filters.blendTrans.apply();
                object.style.visibility="visible";
                object.filters.blendTrans.play();
                if(doingFunction!=null)doingFunction()
            }
        }
    }
}
function fadeOut(object,time,doingFunction,noie){
    var fade,opacity=1,coefficient=0.04;
    if(!device.ie){
        object.style.opacity=1;
        object.style.visibility="visible";
        object.style.display="block";
        if(time==null)time=1;
        else if(time<=500){time=1}
        else{time=time/500}
        fade=setInterval(function(){
            opacity-=coefficient;
            if(opacity>=0-coefficient&&opacity<=0+coefficient){
                window.clearInterval(fade);
                fade=-1;
                object.style.opacity=0;
                object.style.display="none";
                if(doingFunction!=null)doingFunction();
                return false
            }
            object.style.opacity=opacity
        },time)
    }
    else{
        if(noie){
            object.style.visibility="hidden";
            object.style.display="none";
            if(doingFunction!=null)doingFunction()
        }
        else{
            object.style.filter="blendTrans(duration=1)";
            if(object.filters.blendTrans.status!=1){
                object.filters.blendTrans.apply();
                object.style.visibility="hidden";
                object.filters.blendTrans.play();
                if(doingFunction!=null)doingFunction()
            }
        }    
    }
}
function initTop(time){
    var elements=document.getElementsByName("scrollLink");
    if(elements[0]!=null&&device.ipad==null&&device.iphone==null){
        var elementClick, destination,scrolling=-1,i=-1,cof=-1,inDoing=false,cache="",step=200,timeCof=18;
        if(device.fx)timeCof=20;
        if(time!=null)step=document.body.offsetHeight/time*timeCof;
        for(i=0;i<elements.length;i++){
            (function(i){
                elements[i].onclick=function(e){
                    if(inDoing)return;
                    inDoing=true;
                    if(!e)e=window.event;if(!device.ie)e.preventDefault();else e.returnValue=false;
                    elementClick=this.getAttribute("href");
                    elementClick=elementClick.substr(elementClick.lastIndexOf("#")+1,elementClick.length-1);
                    elementClick=document.getElementsByName(elementClick)[0];
                    destination=getAbsolutePositionY(this)-getAbsolutePositionY(elementClick);
                    destination>=0?cof=-1:cof=1;
                    scrolling=setInterval(function(){
                        destination+=cof*step;
                        if(-cof*destination-step<=0){
                            window.clearInterval(scrolling);
                            inDoing=false;
                            window.scrollBy(0,-destination);
                            if(elements[i].getAttribute("accessKey")){
                                cache=elements[i].getAttribute("accessKey");
                                eval(cache);
                            }
                        }
                        else window.scrollBy(0,cof*step);
                    },30);
                    if(!device.ie)document.body.addEventListener('DOMMouseScroll',stopOnTop,false);
                    document.body.onmousewheel=function(){stopOnTop()};
                    if(device.iphone||device.ipad)document.body.addEventListener("touchstart",stopOnTop,false);
                }
            })(i)
        }
    }
    function stopOnTop(){
        if(inDoing){
            window.clearInterval(scrolling);
            if(!device.ie)document.body.removeEventListener('DOMMouseScroll',stopOnTop,false);
            if(device.iphone||device.ipad)document.body.removeEventListener("touchstart",stopOnTop,false);
            document.body.onmousewheel=null;
            inDoing=false;
        }
    }
}
function addressArrow(){
    if(document.getElementById("addressArrow")==null)return;
    var object=document.getElementById("addressArrow"),fade=false,from=70,to=-25,duration=1000,start,now,progress,result,ani,elements=document.getElementsByName("scrollLink"),i;
    function startAnimation(){
        fade=true;
        start=new Date().getTime();
        ani=setInterval(function() {
            now=(new Date().getTime())-start;
            progress=now/duration;
            result=(to-from)*delta(progress)+from;
            object.style.bottom=result + "px";
            if(progress>=1)window.clearInterval(ani);
        },10);
    }
    fadeIn(object,500,startAnimation,true);
    if(!device.ie)document.body.addEventListener('DOMMouseScroll',hide,false);
    document.body.onmousewheel=function(){hide()};
    if(device.iphone||device.ipad)document.body.addEventListener("touchstart",hide,false);
    if(elements[0]!=null){for(i=0;i<elements.length;i++){elements[i].onmouseup=function(){hide()}}}
    function hide(){if(fade){
        window.clearTimeout(ani);
        ani=0;
        fadeOut(object,500,endPosition,true);
        if(!device.ie)document.body.removeEventListener('DOMMouseScroll',hide,false);
        if(device.iphone||device.ipad)document.body.removeEventListener("touchstart",hide,false);
        document.body.onmousewheel=null;
        fade=false}
    }
    function endPosition(){object.style.bottom="70px"}
}
function getElementsByClassName(className,node){
    if(!node)node=document.body;
    var a=[],els=node.getElementsByTagName("*");
    for(var i=0,j=els.length;i<j;i++)if(els[i].className.indexOf(className)!=-1)a.push(els[i]);
    return a
}
function delta(progress){
    function d(progress){for(var a=0,b=1,result;1;a+=b,b/= 2){if(progress>=(7- 4 * a)/11)return-Math.pow((11-6*a-11*progress)/4,2)+Math.pow(b,2)}}
    return 1-d(1-progress)
}
function getAbsolutePositionY(elem){
    var y;
    if(device.fx){
        y=elem.offsetTop;
        var parentNode=elem.parentNode, offsetParent=elem.offsetParent;
        while(offsetParent!=null){
            y+=offsetParent.offsetTop;
            if (offsetParent!=document.body&&offsetParent!=document.documentElement){
                y-=offsetParent.scrollTop
            }
            while(offsetParent!=parentNode&&parentNode!=null){
                y+=parentNode.scrollTop;
                parentNode=parentNode.parentNode;
            }
            parentNode=offsetParent.parentNode;
            offsetParent=offsetParent.offsetParent;
        }
    }
    else{y=0;while(elem){y+=elem.offsetTop+elem.clientTop;elem=elem.offsetParent}}
    return y
}
