var s_dir = -1;
var s_currentTime = 0;
var s_totalTime = 3000;
var s_stepSize = 40;
var s_distance = 1024;
var s_xValues = [];
var s_ob_offset = false;
var s_moving = false;
var s_interval = false;
var s_page = false;

function initBike() {
    resizeScale();
    window.onresize = resizeScale;
    var ob_split = $('ob_split');
    var totalHeight = screen.height;
    var eachHeight = 47;
    var x = 420;
    var y = 113;
    var hit = 0;

    var ob_pageframe = $('ob_pageframe');
    ob_pageframe.style.display = "none";
	
    var pages = ['team', 'portfolio', 'services', 'contact'];
    for(var i=0; i<pages.length; i++) {
		var thispage = $(pages[i]);
		thispage.style.display = "none";
    }
    
    while(y < totalHeight) {
		var ob_ramp = IMG({'src':'img/ob_ramp.png'});
		ob_ramp.style.left = x + "px";
		ob_ramp.style.bottom = y + "px";
		
		var ob_ramp_white = DIV({'class':'ob_ramp_white'}, IMG({'src':'img/null.gif'}));
		ob_ramp_white.style.left = x + "px";
		ob_ramp_white.style.bottom = (y+264) + "px";
		
		x += 74;
		y += 47;
		
		appendChildNodes(ob_split, ob_ramp, ob_ramp_white);
    }
}

function resizeScale() {
    if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			winW = window.innerWidth;
			winH = window.innerHeight;
		} else if (navigator.appName.indexOf("Microsoft")!=-1) {
			winW = document.body.offsetWidth;
			winH = document.body.offsetHeight;
		} else {
			winH = document.body.clientHeight;
			winW = document.body.clientWidth;
		}
    }
    
    var ob_init = $('ob_init');
    ob_init.style.width = winW + "px";
    ob_init.style.height = winH + "px";
    var ob_universe = $('ob_universe');
    ob_universe.style.left = winW + "px";
    ob_universe.style.height = winH + "px";
    ob_universe.style.width = getStyle( 'ob_offset', 'width' ) - winW + "px";
    var ob_split_white = $('ob_split_white');
    ob_split_white.style.height = winH + "px";
    
	var ob_page = $('ob_page');
	ob_page.style.width = winW + "px";
	ob_page.style.height = winH + "px";
	x = parseInt( ( winH + getStyle( 'ob_split', 'bottom' ) ) * ( 74 / 47 ) );
	ob_page.style.left = x + "px";
	
 	var ob_pageframe = $( 'ob_pageframe' );
 	ob_pageframe.style.height = winH - 126 + "px";
	
	if ( getStyle( 'ob_offset', 'left' ) < -winW ) {
		var ob_offset = $('ob_offset');
		ob_offset.style.left = -winW -x + "px";
	}
}

// this function is need to obtain style properties (primarily for compatibility with safari)
function getStyle(oElm, strCssRule){
	oElm = document.getElementById( oElm );
    var strValue = "";
    if(document.defaultView && document.defaultView.getComputedStyle){
        strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
    }
    else if(oElm.currentStyle){
        strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
            return p1.toUpperCase();
        });
        strValue = oElm.currentStyle[strCssRule];
    }
    strValue = parseInt( strValue );
    return strValue;
}

function rideTheRainbow( page ) {
	if ( s_moving == false ) {
		if ( !page ) {
			s_page = false;
			var ob_pageframe = $('ob_pageframe');
			ob_pageframe.style.display = "none";
		} else {
			s_page = page;
		}
		if ( getStyle( 'ob_offset', 'left' ) < 0 ) {
			s_dir = 1;
		} else {
			s_dir = -1;
		}
		s_currentTime = 0;
		s_distance = getStyle( 'ob_init', 'width' ) + getStyle( 'ob_page', 'left' );
		s_ob_offset = $( 'ob_offset' );
		// pre-calc of cosine function.
		for ( i = 0; i <= s_totalTime; i = i + s_stepSize ) {
			x = ( -Math.cos( s_currentTime * ( Math.PI / s_totalTime ) ) + 1 ) / 2;
			x = parseInt( x * s_distance * s_dir );
			if ( s_dir > 0 ) {
				x = x - s_distance;
			}
			s_currentTime = s_currentTime + s_stepSize;
			s_xValues[ i ] = x;
		}
		s_currentTime = 0;
		s_interval = setInterval( "moveScreen();", s_stepSize );
		s_moving = true;
    }
}

function moveScreen() {
	s_ob_offset.style.left = s_xValues[ s_currentTime ] + "px";
	s_currentTime = s_currentTime + s_stepSize;
	if ( !( s_currentTime <= s_totalTime ) ) {
		clearInterval( s_interval );
		s_moving = false;
		if ( s_page != false ) {
			var ob_pageframe = $('ob_pageframe');
			ob_pageframe.style.display = "block";
			teleportPage( s_page );
		}
    }
}

function teleportPage( page ) {
    var pages = ['team', 'portfolio', 'services', 'contact'];
    for(var i=0; i<pages.length; i++) {
		var thispage = $(pages[i]);
		thispage.style.display = "none";
    }

    var thispage = $(page);
	thispage.style.zIndex = "500";
    thispage.style.display = "block";
}
