// JavaScript Document
/*if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
		window.location = "iphone.html";
}

if ( ((screen.width<1024)&&(screen.width>200)) || ((screen.height<768)&&(screen.height>200)) )
{
	window.location="iphone.html";
}
*/
$(document).ready(function(){
	if (screen.height>800)
	{
		document.body.style.minHeight = "800px";
	}
	$.preloadCssImages();
	var ideas = {
		divid: '#nav1',
		state: 0,
		openTop: '0px',
		closeTop: '-275px'
	};
	var exp = {
		divid: '#nav2',
		state: 0,
		openTop: '0px',
		closeTop: '-275px'
	};
	var contact = {
		divid: '#nav3',
		state: 0,
		openTop: '0px',
		closeTop: '-275px'
	};
	var textideas = {
		divid: 'text-idea',
		openTop: '20px',
		closeTop: '-225px'
	};
	var textexp = {
		divid: 'text-exp',
		openTop: '-180px',
		closeTop: '-325px'
	};
	var textcontact = {
		divid: 'text-contact',
		openTop: '-150px',
		closeTop: '-475px'
	};
	var divs = [];
	var texts = [];
	divs.push(ideas, exp, contact);
	texts.push(textideas, textexp, textcontact);
	
	function showNav(divTar, openTar)
	{
		$(divTar).animate({left: '0px',top:openTar},{queue:false,duration:300});
	}
	function hideNav(divTar, closeTar)
	{
		$(divTar).stop().animate({left:'64%',top:closeTar},{queue:false,duration:300});
	}
	function hideText(divTar, closeTar)
	{
		$(divTar).stop().animate({left:'115%',top:closeTar},{queue:false,duration:150});
	}
	function underNav(divTar){
		$(divTar).stop().animate({left:'64%',top:'0px'},{queue:false,duration:300});
	}
	function bump(divTar, state)
	{
		if (state != 1){
			$(divTar).animate({left:'63%'},{queue:false,duration:160});
		}
	}
	function bumpBack(divTar, state)
	{
		if (state != 1){
			$(divTar).animate({left:'64%'},{queue:false,duration:160});
		}
	}
	
	jQuery.each(divs, function(i){
		var item = divs[i];
		$(item.divid).mouseover(function(){
			bump(item.divid, Number(item.state));
		}).mouseout(function() {
			bumpBack(item.divid, Number(item.state))
		});
	});
	
	jQuery.each(divs, function(i){
		var item = divs[i];
		var text = texts[i];
		$(item.divid).mouseup(function(){
			if (Number(item.state)==0){
				var string = '#'+String(text.divid);
				showNav(String(item.divid), String(item.openTop));
				showNav(string, String(text.openTop));
				for (var j=0; j<3; j++){
					if (j != i){
						var string = '#'+String(texts[j].divid);
						underNav(String(divs[j].divid));
						hideText(string, String(texts[j].openTop));
						divs[j].state = 0;
					}
				}
				item.state = 1;
			}
			else {
				jQuery.each(divs, function(i){
					var item = divs[i];
					hideNav(String(item.divid), String(item.closeTop));
					item.state = 0;
				});
				jQuery.each(texts, function(i){
					var item = texts[i];
					string = '#'+String(item.divid);
					hideText(string, String(item.closeTop));
				});
		}
		})
	});
});