scrollStep=1;
infoStep=4;

timerLeft="";
timerRight="";
timerUp="";
timerBg="";
timerInfoLin="";
timerInfoLout="";
timerInfoLin2="";
timerInfoLout2="";
timerInfoLin3="";
timerInfoLout3="";
timerInfoLout4="";
timerLogo = "";
timerPngSpin = "";
timerScrollUpDown = "";

initialLoadBool = 1;

initPosition=0;
logoInitPosition=0;
pxToMove=0;

waitAround = "";
onOrOff = 3;

bioEndPos = "";

bioActive = 0;
contactActive = 0;
servicesActive = 0;

timerSwitchMode1 = "";
timerSwitchMode2 = "";
timerSwitchMode3 = "";
timerSwitchMode4 = "";
timerSwitchMode5 = "";
timerSwitchMode6 = "";

var pos1L = -152;
var pos1R = 152;
var pos2L = -4;
var pos2R = 1;

function initialLoad(id, pos1, pos2){

if (initialLoadBool == 1){
switch ( getAnchor() ) {
	case 'contact':

		waitForIt(id, pos1, pos2, 'contact');
		break;
	case 'bio':
			waitForIt(id, pos1, pos2, 'bio');
		break;
	case 'services':
		waitForIt(id, pos1, pos2, 'services');
		break;
	default:

		waitForIt(id, pos1, pos2, 'contact');

}
initialLoadBool = 0;
}
}




function hideLoader(){
document.getElementById('loadSpinner').src = '../images/spacer.gif';
document.getElementById('loadSpinner').style.visibility = 'hidden';
document.getElementById('loadSpinner').style.display = 'none';


}




function getAnchor(){
theAnchor = self.document.location.hash.substring(1);
return theAnchor;

}


function setNavHilite(id,hiliteBool){
if (hiliteBool == 1){
document.getElementById(id).className = "highlighted";
}
if (hiliteBool == 0){
document.getElementById(id).className = "hilite";
}

}

function toLeft(id){
  document.getElementById(id).scrollLeft=0;
}

function scrollDivLeft(id){
  clearTimeout(timerRight) 
  lastStepL = document.getElementById(id).scrollLeft;
  document.getElementById(id).scrollLeft+=(scrollStep);
  if(lastStepL < document.getElementById(id).scrollLeft || lastStepL==0){
  timerRight=setTimeout("scrollDivLeft('"+id+"')",40);
  } else scrollDivRight(id);
 
}

function scrollDivRight(id){
  clearTimeout(timerLeft);
  lastStepR = document.getElementById(id).scrollRight;
  document.getElementById(id).scrollLeft-=scrollStep;
  if(document.getElementById(id).scrollLeft > 0){
  timerLeft=setTimeout("scrollDivRight('"+id+"')",40);
} else scrollDivLeft(id);
}

function scrollDivUp(id){
clearTimeout(timerUp);
document.getElementById(id).scrollTop+=(scrollStep);
timerUp=setTimeout("scrollDivUp('"+id+"')",40);
}

// check that contact/index.html is not the refferer

// parse the #anchor and load up that function

// oliophoto.com/comtact/index.html#contact

//make a bool that gets set on page load.




// inforscroll -passed- elementID,initialposition, delta.endposition
// default hidden div, need to set to initial position, unhide, then move
// method to hide any other in progress scrolls, all links use rel="infoscroll"
// pos1 = initial postion, pos2 = destination position

function waitForIt(id, pos1, pos2, initLink) {
if (onOrOff > 1){
    onOrOff -= 1;
    waitAround = setTimeout ("waitForIt('"+id+"',"+pos1+","+pos2+",'"+initLink+"')", 1200);

 } else {clearTimeout(waitAround);}
 if (onOrOff == 1){
 switch ( initLink ) {
	case 'contact':
			hideLoader();

		 contactScroll(id, pos1, pos2);
         onOrOff -= 1;
        break;
	case 'bio':
				hideLoader();

        bioScroll();
         onOrOff -= 1;
		break;
	case 'services':
				hideLoader();
servicesScroll();
         onOrOff -= 1;		
         break;
	default:
alert('Oh boy, this should never happen');
}
 


 
}
}


function switchModes(id, pos1, pos2, mode){

switch ( mode ) {
	case 'contact':
  if (bioActive == 1){
  bioScroll();
  timerSwitchMode1=setTimeout("switchModes('"+id+"',"+pos1+","+pos2+",'"+mode+"')",15);
} else  if (servicesActive == 1){
 servicesScroll();
  timerSwitchMode1=setTimeout("switchModes('"+id+"',"+pos1+","+pos2+",'"+mode+"')",15);
} else if (bioActive == 0 && servicesActive == 0) {
    clearTimeout(timerSwitchMode1);
    contactScroll(id,pos1,pos2);
    } else {timerSwitchMode1=setTimeout("switchModes('"+id+"',"+pos1+","+pos2+",'"+mode+"')",15);}
	break;	
	
	case 'bio':
  if (contactActive == 1){
  contactScroll(id,pos1,pos2);
  timerSwitchMode1=setTimeout("switchModes('"+id+"',"+pos1+","+pos2+",'"+mode+"')",15);
} else  if (servicesActive == 1){
 servicesScroll();
  timerSwitchMode1=setTimeout("switchModes('"+id+"',"+pos1+","+pos2+",'"+mode+"')",15);
} else if (contactActive == 0 && servicesActive == 0) {
    clearTimeout(timerSwitchMode1);
    bioScroll(id,pos1,pos2);
    } else {timerSwitchMode1=setTimeout("switchModes('"+id+"',"+pos1+","+pos2+",'"+mode+"')",15);}
	
	break;
	
	case 'services':
	
	if (contactActive == 1){
  contactScroll(id,pos1,pos2);
  timerSwitchMode1=setTimeout("switchModes('"+id+"',"+pos1+","+pos2+",'"+mode+"')",15);
} else  if (bioActive == 1){
 bioScroll();
  timerSwitchMode1=setTimeout("switchModes('"+id+"',"+pos1+","+pos2+",'"+mode+"')",15);
} else if (contactActive == 0 && bioActive == 0) {
    clearTimeout(timerSwitchMode1);
    servicesScroll();
    } else {timerSwitchMode1=setTimeout("switchModes('"+id+"',"+pos1+","+pos2+",'"+mode+"')",15);}
	
	break;
	default:
}



}



function servicesScroll(){
if (servicesActive == 0){
document.getElementById('s_top').style.visibility = 'visible';
document.getElementById('s_bottom').style.visibility = 'visible';
scrollUpDown();
setNavHilite('navServices',1);

} else {setNavHilite('navServices',0); scrollDownUp();}

}




function contactScroll(id, pos1, pos2){


var idVis = $style(id,'visibility');


if(idVis=='hidden'){
initPosition = pos1;
logoInitPosition = parseInt($style('logo','left').replace(/px/,""));
document.getElementById(id).style.left = pos1 + 'px';
document.getElementById(id).style.visibility = 'visible';
scrollInMove(id,pos1,pos2);
setNavHilite('navContact',1);
}

if(idVis=='visible' && $style(id,'left') == (pos2 - (pos2%infoStep))+'px'){
curLeft = parseInt($style(id,'left').replace(/px/,""));
scrollOutMove(id,curLeft,pos2);
setNavHilite('navContact',0);

}

if(idVis=='visible' && $style(id,'left') == pos1+'px'){
document.getElementById(id).style.visibility = 'hidden';
contactScroll(id,pos1,pos2);
}

}


function bioScroll(){


var idVis1 = $style('bio_left','visibility');
var idVis2 = $style('bio_right','visibility');


if(idVis1=='hidden' && idVis2 == 'hidden' && bioActive == 0){
document.getElementById('bio_left').style.left = pos1L + 'px';
document.getElementById('bio_right').style.left = pos1R + 'px';

document.getElementById('bio_left').style.visibility = 'visible';
//document.getElementById('bio_right').style.visibility = 'visible';

scrollInMoveBio('bio_left',pos1L,pos2L,pos1L);
//scrollOutMoveBio('bio_right',pos1R,pos2R,pos1R);
setNavHilite('navBio',1);
}

if(idVis1 =='visible' && bioActive == 1){
curLeft1 = parseInt($style('bio_left','left').replace(/px/,""));
curLeft2 = parseInt($style('bio_right','left').replace(/px/,""));
// scrollOutMoveBioL('bio_left',curLeft1,pos1L,curLeft1);
scrollInMoveBioR('bio_right',curLeft2,pos1R,curLeft2);

setNavHilite('navBio',0);

}

if(idVis1=='visible' && $style('bio_left','left') == pos1L+'px'){
document.getElementById('bio_left').style.visibility = 'hidden';
document.getElementById('bio_right').style.visibility = 'hidden';
bioScroll();
}

}

function moveInSync(id,deltaP,movePerc){

pxToMove = (deltaP * (movePerc));

document.getElementById(id).style.left = logoInitPosition + pxToMove + 'px';

}


    function scrollOutMove(id,pos1,pos2){
        if(initPosition < pos1){
        contactActive = 2;
            curLeft = parseInt($style(id,'left').replace(/px/,""));
            curLeft -= infoStep;
            var thePercentage = ((Math.abs(initPosition - curLeft)) / Math.abs(initPosition - pos2));
    moveInSync('logo',120,thePercentage);
           setFade(id,thePercentage);
            document.getElementById(id).style.left = curLeft + 'px';
            timerInfoLout=setTimeout("scrollOutMove('"+id+"',"+curLeft+","+pos2+")",1);
           } else {clearTimeout(timerInfoLout);contactActive = 0;}
           }




    function scrollInMove(id,pos1,pos2){
        if(pos1 <= pos2){
            curLeft = parseInt($style(id,'left').replace(/px/,""));
            curLeft += infoStep;
            var thePercentage = ((Math.abs(initPosition - curLeft)) / Math.abs(initPosition - pos2));
            moveInSync('logo',120,thePercentage);
           setFade(id,thePercentage);
           
            document.getElementById(id).style.left = curLeft + 'px';
            timerInfoLin=setTimeout("scrollInMove('"+id+"',"+curLeft+","+pos2+")",1);
           } else {clearTimeout(timerInfoLin);contactActive = 1;}
           }


    function scrollOutMoveBio(id,pos1,pos2, initPos){
        if(pos1 > pos2){
            curLeft = parseInt($style(id,'left').replace(/px/,""));
            curLeft -= infoStep;
            var thePercentage = ((Math.abs(initPos - curLeft)) / Math.abs(initPos - pos2));
           setFade(id,thePercentage);
    
           
            document.getElementById(id).style.left = curLeft + 'px';
            timerInfoLout2=setTimeout("scrollOutMoveBio('"+id+"',"+curLeft+","+pos2+","+initPos+")",1);
           } else {clearTimeout(timerInfoLout2);fadeBioImage('in');}
           }




    function scrollInMoveBio(id,pos1,pos2, initPos){
        if(pos1 <= pos2){
 
            curLeft = parseInt($style(id,'left').replace(/px/,""));
            curLeft += infoStep;
            var thePercentage = ((Math.abs(initPos - curLeft)) / Math.abs(initPos - pos2));
           setFade(id,thePercentage);
           
            document.getElementById(id).style.left = curLeft + 'px';
            timerInfoLin2=setTimeout("scrollInMoveBio('"+id+"',"+curLeft+","+pos2+","+initPos+")",1);
           } else {clearTimeout(timerInfoLin2);
          // bioActive = 1;
           bioEndPos = curLeft;
           scrollOutMoveBio('bio_right',pos1R,pos2R,pos1R);
           document.getElementById('bio_right').style.visibility = 'visible';}
           }


    function scrollInMoveBioR(id,pos1,pos2,initPos){
        if(pos1 <= pos2){
                bioActive = 2;

            curLeft = parseInt($style(id,'left').replace(/px/,""));
            curLeft += infoStep *2;
            var thePercentage2 = ((Math.abs(Math.abs(curLeft) - Math.abs(pos2))) / Math.abs(initPos - pos2));
            setFade('bio_right',thePercentage2);
            document.getElementById(id).style.left = curLeft + 'px';
            timerInfoLin3=setTimeout("scrollInMoveBioR('"+id+"',"+curLeft+","+pos2+","+initPos+")",1);
           } else {clearTimeout(timerInfoLin3);
           curLeft1 = parseInt($style('bio_left','left').replace(/px/,""));
           scrollOutMoveBioL('bio_left',curLeft1,pos1L,curLeft1);
           
           }
           }

   function scrollOutMoveBioL(id,pos1,pos2, initPos){
        if(pos1 > pos2){
        bioActive = 2;
            curLeft = parseInt($style(id,'left').replace(/px/,""));
            curLeft -= infoStep * 2;
                   var thePercentage2 = ((Math.abs(Math.abs(curLeft) - Math.abs(pos2))) / Math.abs(initPos - pos2));
           setFade('bio_left',thePercentage2);
          
          // setFade('bio_self', thePercentage2);
           if(thePercentage2 < .02){
           document.getElementById('bio_left').style.visibility = 'hidden';
           document.getElementById('bio_right').style.visibility = 'hidden';
           }
            document.getElementById(id).style.left = curLeft + 'px';
            timerInfoLout4=setTimeout("scrollOutMoveBioL('"+id+"',"+curLeft+","+pos2+","+initPos+")",1);
           } else {clearTimeout(timerInfoLout4);fadeBioImage('out');}
           }


timerBioImage = "";
curFadePerc = "";
curFadeActive = 0;

function fadeBioImage(bioBool){
switch ( bioBool ) {
	case 'in':
	if (curFadeActive == 0) {
	curFadeActive = 1; 
	curFadePerc = 0;
	setFade('bio_self',curFadePerc);
document.getElementById('bio_self').style.visibility = 'visible';
	}
	if (curFadeActive == 1 && curFadePerc < 1) {
	        setFade('bio_self',curFadePerc);

	    curFadePerc+=.02;
        timerBioImage=setTimeout("fadeBioImage('"+bioBool+"')",15);
    } else { clearTimeout(timerBioImage);curFadeActive = 2; bioActive = 1; }

		break;
	
	case 'out':
	if (curFadeActive == 2) {curFadeActive = 1; curFadePerc = 1.0;}
	if (curFadeActive == 1 && curFadePerc > 0.0) {
	    curFadePerc-=.04;
        setFade('bio_self',curFadePerc);
        timerBioImage=setTimeout("fadeBioImage('"+bioBool+"')",5);
    } else {clearTimeout(timerBioImage); curFadeActive = 0; bioActive = 0;}
    
    break;
	
	default:
		
}


}

function scrollUpDown(){
//move in
if (servicesActive == 0 || servicesActive == 2) {
servicesActive = 2;
curTop1 = parseInt($style('s_top','top').replace(/px/,""));
curTop2 = parseInt($style('s_bottom','top').replace(/px/,""));
if (curTop1 < 0){
curTop1 += infoStep;
curTop2 -= infoStep;
var thePercentage3 = (Math.abs(200 - Math.abs(curTop1)) / 200);
            moveInSync('logo',-120,thePercentage3);

           setFade('s_top',thePercentage3);
           setFade('s_bottom',thePercentage3);
    if (thePercentage3 > .5){
    durka = ((thePercentage3 -.5) * 2);
    setFade('s_txt', durka);
    if ($style('s_txt', 'visibility') == 'hidden'){
    document.getElementById('s_txt').style.visibility = 'visible';
    }
    }
document.getElementById('s_top').style.top = curTop1 + 'px';
document.getElementById('s_bottom').style.top = curTop2 + 'px';
timerScrollUpDown=setTimeout("scrollUpDown()",1);
} else  {clearTimeout(timerScrollUpDown); servicesActive = 1;}
}
}

function scrollDownUp() {
//move out
if (servicesActive == 1 || servicesActive == 4) {
servicesActive = 4;
curTop1 = parseInt($style('s_top','top').replace(/px/,""));
curTop2 = parseInt($style('s_bottom','top').replace(/px/,""));
if (curTop1 > -200){
curTop1 -= infoStep * 2;
curTop2 += infoStep * 2;
var thePercentage3 = (Math.abs(200 - Math.abs(curTop1)) / 200);
            moveInSync('logo',-120,thePercentage3);

           setFade('s_top',thePercentage3);
           setFade('s_bottom',thePercentage3);
           
               if (thePercentage3 > .5){
    durka = ((thePercentage3 -.5) * 2);
    setFade('s_txt', durka);
    if (durka < .02){
    document.getElementById('s_txt').style.visibility = 'hidden';
    }
    }
document.getElementById('s_top').style.top = curTop1 + 'px';
document.getElementById('s_bottom').style.top = curTop2 + 'px';
timerScrollUpDown=setTimeout("scrollDownUp()",1);
} else  {clearTimeout(timerScrollUpDown); 
servicesActive = 0;
document.getElementById('s_top').style.visibility = 'hidden';
document.getElementById('s_bottom').style.visibility = 'hidden';
document.getElementById('s_txt').style.visibility = 'hidden';


}
}

}



function setFade(id,fadeP){

document.getElementById(id).style.MozOpacity = fadeP;
document.getElementById(id).style.filter = 'alpha(opacity=' + fadeP * 100 + ')';

document.getElementById(id).style.opacity = fadeP;

}





function scrollBg(id){
clearTimeout(timerBg);
document.getElementById(id).scrollLeft+=(scrollStep);
if(document.getElementById(id).scrollLeft < 750){
timerBg=setTimeout("scrollBg('"+id+"')",15);
} else { document.getElementById(id).scrollLeft=0; scrollBg(id); }

}

function toRight(id){
  document.getElementById(id).scrollLeft=document.getElementById(id).scrollWidth
}

function stopMe(){
  clearTimeout(timerRight) 
  clearTimeout(timerLeft)
}


