

$(document).ready(function() {
	$('#wrap').hide();	
	setTimeout("showBody()", 1000);
});

function showBody() {
	$('#wrap').show("slow");	
}





//Load function into queue
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
		oldonload();
		func();
		}
	}
}

//set variables
var numOfItems 	= 7;


//Use JS to add absolute positioning to page
function contentHolder() {
	var content = 	document.getElementById("content");
	content.style.position = "absolute";
	content.style.top ="75px";
}

function gotoSection(number,section) {
	//check dom
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	
	prepareAllNavs();
	
	//convert to number
	activeIndex = parseInt(number);	

	counter = 0;


	// move menu items to right
	for (i=activeIndex+1; i<numOfItems; i++) {
		var page = 	document.getElementById("page"+i); 
		page.className = "inactive";
		var xPos = (100+(counter*100))+'px';
		$(page).animate({ left: xPos },750 );			
		var content = document.getElementById("content"+i); 
		$(content).animate({ opacity: 0 },500, bringBackIn );			
		counter++;
	}	
	
	//move items on left side into place
	for (i=0; i<activeIndex; i++) {
		var page = 	document.getElementById("page"+i);
		page.className = "inactive";
		page.style.position = "absolute";
		var xPos = (100+(counter*100))+'px';
		$(page).animate({ left: xPos } );			
		var content = document.getElementById("content"+i);
		$(content).animate({ opacity: 0 },500);			
		counter++;
	}
	
	//set active item into position
	var page = 	document.getElementById("page"+activeIndex); 
	page.className = "active";
	var xPos = '700px';
	page.style.position = "absolute";
	$(page).animate({ left: xPos },750,showContent );

	//adjustHeight(section);	


}

function showContent() {
	var content = document.getElementById("content"+activeIndex); 
	$(content).animate({ opacity: 1 }, 500);			
}

function bringBackIn(page) {
	var xPos = this.xPos;
	var page = this.element;			
}

//Hide specified section
function showSection(id) {
	var divs = document.getElementsByTagName("div");
	for (var i=0; i<divs.length; i++) {
		if (divs[i].className.indexOf("subcontent") == -1) continue;
		if (divs[i].getAttribute("id") != id) {
			divs[i].style.display = "none";
		} else {
			divs[i].style.display = "block";
		}
	}
}
	
//find id on click and send to showSection function
function prepareInternalnav(subnav) {
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById(subnav)) return false;
	var nav = document.getElementById(subnav);
	var links = nav.getElementsByTagName("a");
	for (var i=0; i<links.length; i++) {
		links[i].className="subNavOut";			
		var sectionId = links[i].getAttribute("href").split("#")[1];
		if (!document.getElementById(sectionId)) continue;
		document.getElementById(sectionId).style.display = "none";
		links[i].destination = sectionId;
		links[i].onclick = function() {
			deactivate(subnav);
			this.className = "subNavDown"; 			
			showSection(this.destination);
			return false;
		}
		links[i].onmousedown = function() {
			this.className = "subNavDown";
		}
	}
}

//remove active button
function deactivate(subnav) {
	//alert("deactivate!");
	var nav = document.getElementById(subnav);
	var links = nav.getElementsByTagName("a");
	for (var i=0; i<links.length; i++) {
		links[i].className="subNavOut";
	}
}
	
	
//On load show the one specified section
function showStartSection(firstItem) {
	var divShow = document.getElementById(firstItem);
	divShow.style.display = "block";	
}

/*Set up content on load*/
function prepareAllNavs() {		
	prepareInternalnav("historyNav");
	showStartSection("history")		
	prepareInternalnav("technologyNav");
	showStartSection("technology")		
	prepareInternalnav("commercialNav");
	showStartSection("commercial")		
	showStartSection("home")
	prepareInternalnav("partnerNav");
	showStartSection("partner")
	showStartSection("product")
	showStartSection("contactus")		
}
	
//Open up section and page	
function gotoPage(number, section, id) {
	gotoSection(number,section);
	showSection(id);
}

/*resize function*/
( function( $ )  { 
    $.fn.wresize = function( f )  { 
        version = '1.1'; 
        wresize = {fired: false, width: 0}; 
 
        function resizeOnce() { 
            if ( $.browser.msie ) { 
                if ( ! wresize.fired ) { 
                    wresize.fired = true; 
                } else { 
                    var version = parseInt( $.browser.version, 10 ); 
                    wresize.fired = false; 
                    if ( version < 7 ) { 
                        return false; 
                    } else if ( version == 7 ) { 
                        //a vertical resize is fired once, an horizontal resize twice 
                        var width = $( window ).width(); 
                        if ( width != wresize.width ) { 
                            wresize.width = width; 
                            return false; 
                        } 
                    } 
                } 
            } 
 
            return true; 
        } 
 
        function handleWResize( e ) { 
            if ( resizeOnce() ) { 
                return f.apply(this, [e]); 
            } 
        } 
 
        this.each( function()  { 
            if ( this == window ) { 
                $( this ).resize( handleWResize ); 
            } else { 
                $( this ).resize( f ); 
            } 
        } ); 
 
        return this; 
    }; 
 
} ) ( jQuery );




jQuery( function( $ ) { 
    function content_resize() { 
        var w = $( window ); 
        var H = w.height();
		counter = 0;	
		for (i=0; i<numOfItems; i++) {
			if(!(H>400)) return false;
       	 		$( '#page'+i ).css( {height: H} ); 
       	 		//$( '#content'+i ).css( {height: H-180} ); 
				counter++;
		}
       	//$( '.subcontent' ).css( {height: H-180} ); 
    } 
 
    $( window ).wresize( content_resize ); 
 
    content_resize(); 
} ); 




//On Load set up the page
function setup() {
	//check dom
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	
	contentHolder()
	
	var home_text = document.getElementById("fadein");
	home_text.style.display = "none";
	
	//position pages
	for (i=0; i<numOfItems; i++) {
		var page = 	document.getElementById("page"+i);
		//var xPos = this["pos"+counter]+'px';
		page.className = "container";
		var content = document.getElementById("content"+i); 
		content.className = "section";		
	}
	//insert h2 styles and onclick function
	var headings = document.getElementsByTagName("h2");
	for (var i=0; i<headings.length; i++) {
		//headings[i].className = "headings";
		headings[i].onmouseover = function() {
			this.className = "over"; 
		}
		headings[i].onmouseout = function() {
			this.className = "out"; 
		}
		headings[i].onmousedown = function() {
			this.className = "click";
		}
	}
	
	//Position Pages
	for (i=1; i<numOfItems; i++) {
	var page = 	document.getElementById("page"+i); 
	page.className = "inactive";
	var xPos = (i*100)+'px';
	page.style.position = 'absolute';
	page.style.left = xPos;		
	}
	
	//Position Home Page
	var page = 	document.getElementById("page0"); 
	page.className = "active";
	var xPos = '700px';
	page.style.position = 'absolute';
	page.style.left = xPos;	
	
	//Position Home Image
	//var homeImage = document.getElementById("imageStart");
	//homeImage.style.position = 'absolute';
	//homeImage.style.left = '-530px';
	
	setTimeout("showText()", 3000);	

	
	//Adjust Height
	//content_resize("home");
	
	//Prepare Navs
	prepareAllNavs()
	
}
addLoadEvent(setup);

function showText() {
	var home_intro = document.getElementById("fadein"); 
	$(home_intro).show("slow");	
}
