$(function() {
	var timeRoll;
	var theI;
	$('#navi img').mouseover( function() {
		if(theI != this.src.charAt(this.src.length - 5)) {
			clearTimeout(timeRoll);
			$('#header > div').fadeOut(200);
		}
		theI = this.src.charAt(this.src.length - 5);
		$('#nav'+theI).fadeIn(200);
	});

	$('#header *').mouseout ( function() {
		clearTimeout(timeRoll);
		timeRoll = setTimeout(function(){ $('#header > div').fadeOut(200); }, 4000);
	});

	$('#navi a:eq(1)').click ( function(){
		return false;
	});

	$('#header *').mouseover ( function() {
		clearTimeout(timeRoll);
	});

	$('a[rel*=external]').click( function() {
		window.open(this.href);
		return false;
	});

	$('#emailField').focus( function() {
		$(this).val('');
		$(this).css('color','#cccccc');
	});

	$('#toolSubNav a').click( function(e) {
	  e.preventDefault();
		var theIndex = $("#toolSubNav a").index(this);
		subNavGo(theIndex);
	});
  
	$('#imgrot').hover(
		function (){ if ($('#photoGallery img').size() > 0) $('body').css('cursor', 'pointer', 'cursor', 'hand'); },
		function (){ if ($('#photoGallery img').size() > 0) $('body').css('cursor', ''); }
	);

	$('#imgrot').click( function() {
		if ($('#photoGallery img').size() > 0) subNavGo(2);
	});
});

var divInd = 0;

function subNavGo(gotoIndex) {
	$('#smain .content > div').hide();
	$('#toolSubNav a').removeClass('snhigh');
	$("#toolSubNav a:eq(" + gotoIndex + ")").addClass('snhigh');
	$("#smain .content > div:eq(" + gotoIndex + ")").show();
}


function buildPhotos(dir, numOfTech){
    for (var i = 0; i < picArr.length; i++) {
		if (i < numOfTech) {
			var link = $("<a title='" + picArr[i].pic + " -- " + picArr[i].caption + "' href='photos/" + dir + "/first/" + picArr[i].pic + ".jpg' rel='lightbox-" + dir + "'><img src='photos/" + dir + "/thumbs/" + picArr[i].pic + ".jpg' alt='' /></a>");
			$('#thumbs > span').after(link);
		}
		else {
			var link = $("<a title='" + picArr[i].pic + " -- " + picArr[i].caption + "' href='photos/" + dir + "/" + picArr[i].pic + ".jpg' rel='lightbox-" + dir + "'><img src='photos/" + dir + "/thumbs/" + picArr[i].pic + ".jpg' alt='' /></a>");
			$('#photoGallery').append(link);
		}
    }

	$('#imgrot').innerfade({ speed: 1000, timeout: 3500, type: 'sequence', containerheight: 352 });
	$('#smain .content > div').hide();
	$('#smain .content > div:eq(0)').show();
	$('.techList div:odd').css('background-color','#1c1c1c');
	$('.techList div > span:even').addClass('techListFirst');
	$('.techList div > span:odd').addClass('techListLast');
}
