// JavaScript Document

// final set of larger images to load, once page is up and runnin
function stageTwo() {
	var myimages = new Array();
	function preloading(){
		for (x=0; x<preloading.arguments.length; x++){
			//alert(preloading.arguments[x]);
			myimages[x] = new Image();
			myimages[x].src = "/wp-content/themes/twentyten/images/"+preloading.arguments[x];
		}
		
	}
	preloading("work-rollover-box.png",
			   "timeline-textbox.png",
			   "footer-bikerscout.gif",
			   "hello-bg.jpg",
			   "work-bg.jpg",
			   "skillset-bg.jpg",
			   "timeline-bg.jpg",
			   "connect-bg.jpg",
			   "about-bg.jpg",
			   "footer-bg.jpg"
			   );
//,"","","","","","","","","","","","","","","","","","",""
}

// page is ready, get GIR some tacos
$(document).ready(function() {	
						   
	/*scrolling nav*/
	$('#main-nav').localScroll({
		//target: '#content',  could be a selector or a jQuery object too.
		queue:true,
		duration:1000,
		hash:true,
		onBefore:function( e, anchor, $target ){
			// The 'this' is the settings object, can be modified
		},
		onAfter:function( anchor, settings ){
			// The 'this' contains the scrolled element (#content)
		}
	});
	
	
	/*Twitter*/
	getTwitters('twert', { 
	  id: '_Cruzat', 
	  count: 16, 
	  enableLinks: true, 
	  ignoreReplies: true, 
	  clearContents: true,
	  callback: wrapTweet,
	  template: '<span class="top"></span><span class="mid"><p>"%text%" <br><a href="http://twitter.com/%user_screen_name%/statuses/%id_str%/" class="stamp">twittered %time%</a></p></span><span class="bot"></span>'
	});
	function wrapTweet() {
		$('#twert ul').cycle({ 
			fx:    'scrollHorz', 
			speed: 1000,
			timeout: 6000,
			pause:  1 
		});
	}

	/*Work samples*/
	var faydIn = 400;
	var faydOut = 400;
	$('#work ul.worklist li a').css("opacity", 0.6);
	$('#work ul.worklist li a').hover(
		function() {
			var handL;
			if($(this).parent().parent().parent().hasClass('recently')) {
				handL = recentWorkShelf;
			}
			if($(this).parent().parent().parent().hasClass('still')) {
				handL = stillWorkShelf;
			}
			$('span.showcontent').stop().hide();
			$(this).parent().stop().animate({ width: "280px", height: "220px", marginTop: "-40px" } , faydIn );
			$(this).stop().animate({ width: "280px", height: "220px", opacity: 1 } , faydIn , function() {
				var posLeff = $(this).offset().left - $("#wrapper").offset().left;
				$('div#floater').html(handL[$(this).parent().index()]);
				$('div#floater').css('left',( posLeff - ($('div#floater').width()/2) + ($(this).width()/2) )).stop().fadeTo(faydIn,1);	//($(this).width()/2)-(/2))).stop().fadeTo(faydIn,1);
			});
		},
		function() {
			$('div#floater').stop().hide();
			$(this).parent().stop().animate({ width: "40px", height: "120px", marginTop: "0px" } , faydOut );
			$(this).stop().animate({ width: "40px", height: "120px", opacity: 0.6 } , faydOut, function() { 
				
			});
		}
	);

	/*Timeline*/

	$('ul.dates li a').click(function() {
		$('.t2011').removeClass('sel');							  
		$('ul.dates li a').removeClass('sel');
		$(this).addClass('sel');
		var itemNo = $(this).parent().index();
		if($(this).parent().parent().hasClass('two')) {
			itemNo += 9;								  
		};
		//alert(itemNo);
		timeFlip(itemNo);
	});
	$('a.t2011').click(function() {				  
		$('ul.dates li a').removeClass('sel');
		$('.t2011').addClass('sel');	
		timeFlip(0-1);
	});
	function timeFlip(x) {
		x+=1;
		var maxHeight = 361; //$('div.block').height();
		var totHeight = 0;
		var blocOne;
		var blocTwo;
		$('div.block div.prof p').html(profitems[x]);
		$('div.block div.triv p').html(trivitems[x]);
		if(profitems[x]=="") { 
			$('div.prof').hide(); 
		} else { 
			$('div.prof').show();
		};
		if(trivitems[x]=="") { 
			$('div.triv').hide(); 
		} else { 
			$('div.triv').show();
		};
		$('div.block div.prof').css('height', $('div.block div.prof p').height());
		totHeight += $('div.block div.prof p').height();
		totHeight += $('div.block div.triv p').height();
		var diffy = (maxHeight-totHeight)/2;
		$('div#timeline div.block').css('paddingTop',diffy);
		$('div#timeline div.block').hide();
		$('div#timeline div.block').stop().fadeTo(200,1);
	};	
	timeFlip(0-1);



	/*RobotBody*/
	var robobods = new Array('one','two','three','four','five','six');

	var bodscoun = robobods.length;
	var robocoun = Math.floor(Math.random()*bodscoun);

	$('div.robobod').fadeOut( 100, function() {
		$('div.robobod').removeClass(robobods[robocoun]);
		robocoun ++;
		if(robocoun==bodscoun) {
			robocoun = 0;	
		}
		$('div.robobod').addClass(robobods[robocoun]);
		$('div.robobod').fadeIn(250);
	});
		
	$('a.bod-rot').click(function() {
		$('div.robobod').fadeOut( 100, function() {
			$('div.robobod').removeClass(robobods[robocoun]);
			robocoun ++;
			if(robocoun==bodscoun) {
				robocoun = 0;	
			}
			$('div.robobod').addClass(robobods[robocoun]);
			$('div.robobod').fadeIn(250);
		});
	});

	//arm nav
	James();
	
	//finish load cascade
	stageTwo();
	
});

