﻿/// <reference path="animator.js"/>
_sm1 = new Animator({duration: 400});
_sm2 = new Animator({duration: 200});
_sm3 = new Animator({duration: 200});
_sm4 = new Animator({duration: 200});
_sm5 = new Animator({duration: 200});

try 
{
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

// JScript File
// JavaScript Document
function getMousePos(e){
	var posx = 0;
    var posy = 0;
    if (!e) e = window.event;
    if (e.pageX || e.pageY) {
		posx = e.pageX;
		posy = e.pageY;
    }
    else if (e.clientX || e.clientY) {
		posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
    }
	return posy;
}
//crolling arrows
function setAnimScroll(){
    var menuDiv=document.getElementById('menucont');
	var menuDivH=menuDiv.offsetHeight;
	var clipDiv=document.getElementById('clip');
	var top=-1*(menuDivH-299)+'px';
	var handle=getElementsByClassName(document,'div','handle')[0];
	
	scrElanim=new Animator({transition:Animator.makeLinear()});
	scrElanim.addSubject(new NumericalStyleSubject(menuDiv, 'top', 0, top));
	scrElanim.addSubject(new NumericalStyleSubject(handle, 'top', 0, 219));	
}
function scrollup(){
    scrElanim.options.duration=1800;
    scrElanim.seekFromTo(scrElanim.state, 0);
}
function scrolldown(){
    scrElanim.options.duration=1800;
	scrElanim.seekFromTo(scrElanim.state, 1);
}
function stopScroll(){
  scrElanim.jumpTo(scrElanim.state)
}
//press on track
function iniTrackMove(srcEvent){
    attachEventListener(srcEvent,"mouseup", trackMove, false);
}
function trackMove(et){
    var currPos=(getMousePos(et)-110)/220;
    var speed=Math.abs(1-(Math.abs(currPos-scrElanim.state)))*1800;
    if(speed<200){
        speed=200;
    }
    scrElanim.options.duration=speed;
    scrElanim.seekTo(currPos);
}
addLoadListener(setAnimScroll);

//scrolling bar
function iniMoveBar(){
	mouseIsDown='true';
	attachEventListener(document,"mousemove", moveBar, false);
	attachEventListener(document,"mouseup", iniStopMove, true);
}
function moveBar(e){
	if(mouseIsDown=='true'){
	    var menuDiv=document.getElementById('menucont');
		var handle=getElementsByClassName(document,'div','handle')[0];
		var track=getElementsByClassName(document,'div','scrollTrack')[0];
		var currPosition=handle.offsetTop;
		var menuDivH=menuDiv.offsetHeight;
		var currPos=getMousePos(e)-110;
		var newTop = currPos/220;
		scrElanim.options.duration=1800;
		scrElanim.jumpTo(newTop);
	}
	 return false;
}
function iniStopMove(){
	mouseIsDown='false';
	attachEventListener(document,"mouseup",moveBar, false);
}


//disable scrollbar if content is short
function checkScroll(){    
    var trckSrcEvent=getElementsByClassName(document,'div','scrollTrack')[0];
    attachEventListener(trckSrcEvent,"mousedown", trackMove, false);
    mouseIsDown="false";
    attachEventListener(document,"mouseup", iniStopMove, true);
    var menuDiv=document.getElementById('menucont');
	var menuDivH=menuDiv.offsetHeight;
	if(menuDivH<299){
	    var overControl=getElementsByClassName(document,'div','scrollControlOver')[0];
	    overControl.style.display='block';
	}else{
	    var overControl=getElementsByClassName(document,'div','scrollControlOver')[0];
	    overControl.style.display='none';
	}
}
function overHandleAnim(){
    var handle=getElementsByClassName(document,'div','handleover')[0];
    _sm1.addSubject(new NumericalStyleSubject(handle, 'opacity', 1, 0));
    var filterDiv=getElementsByClassName(document,'div','filter')[0];
	var filterCont=getElementsByClassName(document,'div','filterCont')[0];
    _sm2.addSubject(new NumericalStyleSubject(filterCont, 'opacity', 0, 0.92));
    _sm2.addSubject(new NumericalStyleSubject(filterDiv, 'left', -230, -5));
    _sm2.addSubject(new NumericalStyleSubject(filterCont, 'width', 0, 231));
    var primaryNavCont=getElementsByClassName(document,'div','primaryNavCont')[0];
	var primaryNavAnimator=getElementsByClassName(document,'div','primaryNavAnimator')[0];
    _sm3.addSubject(new NumericalStyleSubject(primaryNavAnimator, 'opacity', 0, 1));
    _sm3.addSubject(new NumericalStyleSubject(primaryNavAnimator, 'height', 0, 327));
    var homelink=getElementsByClassName(document,'div','homelink')[0];
	var homelinkimg=homelink.getElementsByTagName('img')[0];
    _sm4.addSubject(new NumericalStyleSubject(homelinkimg, 'opacity', 0, 1));
    var dropscroll=getElementsByClassName(document,'div','dropscroll')[0];
	var dropscrollimg=dropscroll.getElementsByTagName('img')[0];
    _sm5.addSubject(new NumericalStyleSubject(dropscrollimg, 'opacity', 0, 1));
    _overlay=document.getElementById('overlay');
    
    
    var homelinka=homelink.getElementsByTagName('a')[0];
    attachEventListener(homelinka,"mouseover", overHomelink, false);
    attachEventListener(homelinka,"mouseout", outHomelink, false);
    
    var dropscrolla=dropscroll.getElementsByTagName('img')[0];
    attachEventListener(dropscrolla,"mouseover", overDropscroll, false);
    attachEventListener(dropscrolla,"mouseout", outDropscroll, false);
    
    attachEventListener(_overlay,"mousedown", dropMenu, false);
}
//filter
function filterAnim(){
    _sm2.options.onComplete=function(){chainedf(0);};
    if(_sm2.state==0){
        _sm2.seekTo(1);
    }else{
        _sm2.seekTo(0);
    }
}
//drop scroll menu{
function getScreenHeight(){
    scrHeight=0;
    if(typeof( window.innerWidth ) == 'number') {
        scrHeight = window.innerHeight;
    }else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        scrHeight = document.documentElement.clientHeight;
    }else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        scrHeight = document.body.clientHeight;
    }
    return scrHeight;
}
function emptyf(){
}
function chainedf(ind){
    if(ind==1){
        if(_sm2.state==0){
            _sm3.seekTo(0);
        }
    }
}
function dropMenu(){
    var scrH=getScreenHeight()-40;
    var contentContDiv=getElementsByClassName(document, 'div', 'contentContainer')[0];
    contentContDivHeight=contentContDiv.offsetHeight+240;
    if(scrH>contentContDivHeight){
        contentContDivHeight=scrH;
    }
    contentContDivWidth=contentContDiv.offsetWidth;
    
    if ( _overlay == null )
    {   
        overHandleAnim();
    }
    
    _overlay.style.height=contentContDivHeight+'px';
    _overlay.style.width=contentContDivWidth+'px';
    _overlay.style.marginLeft=-(contentContDivWidth/2)+'px';
    if(_sm3.state==0){
        _sm3.seekTo(1);
        _overlay.style.display='block';
    }
    else{
        _sm2.seekTo(0);
        _sm2.options.onComplete=function(){chainedf(1);};
        _overlay.style.display='none';
    }
}

//filter homelink
function overHomelink(){
    if(_sm4){    
        if((_sm5.state!=0) && (_sm3.state==0)){
            _sm5.seekTo(0)
        };       
        _sm4.seekTo(1);
    }
}
function outHomelink(){
   if(_sm4){
       if((_sm5.state!=0) && (_sm3.state==0)){
            _sm5.seekTo(0)
        };     
        _sm4.seekTo(0);
    }
}

//fade filter comapny menu
function overDropscroll(){ 
    if(_sm5){    
        _sm5.seekTo(1);
    }
}
function outDropscroll(){   
    if(_sm5){ 
	    if(_sm3.state==0){
	        _sm5.seekTo(0);
	    }
	}
}
addLoadListener(overHandleAnim);
addLoadListener(checkScroll);

function openListWithin(srcLink, listType){
    var containingLi = srcLink.parentNode;
    var innerList = getElementsByClassName(containingLi, 'ul', listType)[0];
        
    if(innerList && innerList.style.display == 'none' || innerList && !innerList.style.display){ 
        innerList.style.display = 'block';
        if(listType == 'regionList') srcLink.style.color = '#ffffff';
    }else if(innerList){ 
        innerList.style.display = 'none';
        if(listType == 'regionList') srcLink.style.color = '#cccccc';
    }
    
    srcLink.blur();
    
    setAnimScroll();
    checkScroll();
}
