$(document).ready(function() {
	
	// Scroll
	$("li#go-right a").click(function(){
		$("#scene").scrollTo( '#features', 1900 );
		$("#foot .treeline").animate({ 'left':'-25%' }, 1900);
		$("#content .info, #content h2").fadeOut(1100);
		$("#content .media, #content h3").delay(800).fadeIn(1100);
		$("li#go-right").fadeOut(400);
		$("li#go-left").delay(1000).fadeIn(700);
		$("#sky ul").animate({ 'left':'-10%' }, 1900)
		return false;
	});
	$("li#go-left a").click(function(){
		$("#scene").scrollTo( {top:'0px', left:'0px'}, 1900 );
		$("#foot .treeline").animate({ 'left':'-10%' }, 1900);
		$("#content .media, #content h3").fadeOut(1100);
		$("#content .info, #content h2").delay(800).fadeIn(1100);
		$("li#go-right").delay(1000).fadeIn(700);
		$("li#go-left").fadeOut(400);
		$("#sky ul").animate({ 'left':'0%' }, 1900)
		return false;
	});
	
	// Hover
	$("li#go-right a").hover(function(){
		$(this).animate({ 'margin-left':'6px' }, 100);
	}, function(){
		$(this).animate({ 'margin-left':'0px' }, 200);
	});
	$("li#go-left a").hover(function(){
		$(this).animate({ 'margin-left':'-6px' }, 100);
	}, function(){
		$(this).animate({ 'margin-left':'0px' }, 200);
	});
	
	// Gallery
	$("a#screenshots").fancybox({
		'frameWidth':		560,
		'frameHeight':		467,
		'padding':			0,
		'imageScale':		false,
		'overlayShow':		true,
		'hideOnContentClick':	false
	});
	
	// Media
	$("ul#tab li a").click(function(){
		$("ul#tab li a.active").removeClass("active");
		$(this).addClass("active");
	});
	$("ul#tab li.screenshots a").click(function(){
		$(".media div.videos").animate({ "top":"-205px" }, 500);
		$(".media div.screens").animate({ "top":"0px", "display":"block" }, 500);
	});
	$("ul#tab li.videos a").click(function(){
		$(".media div.videos").animate({ "top":"0px" }, 500);
		$(".media div.screens").animate({ "top":"205px", "display":"block" }, 500);
	});
	$(".videos li a, .screens li a, a.trailer").fancybox({
		'frameWidth':		560,
		'frameHeight':		340,
		'padding':			0,
		'imageScale':		false,
		'overlayShow':		true,
		'hideOnContentClick':	false
	});
	
	// Video Scroll
	$('.videos .carousel').serialScroll({
		items:'.video', // Selector to the items ( relative to the matched elements, '#sections' in this case )
		next:'a#scroll-video',// Selector to the 'next' button (absolute too)
		axis:'x',// The default is 'y' scroll on both ways
		navigation:'#navigation li a',
		duration:1200,// Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
		force:false,	
		start: 0, // On which element (index) to begin ( 0 is the default, redundant in this case )		
		cycle:true,// Cycle endlessly ( constant velocity, true is the default )
		//step:1, // How many items to scroll each time ( 1 is the default, no need to specify )
		//jump:false, // If true, items become clickable (or w/e 'event' is, and when activated, the pane scrolls to them)
		//lazy:false,// (default) if true, the plugin looks for the items on each event(allows AJAX or JS content, or reordering)
		//interval:1000, // It's the number of milliseconds to automatically go to the next
		//constant:true, // constant speed
		
		onBefore:function( e, elem, $pane, $items, pos ){
			/**
			 * 'this' is the triggered element 
			 * e is the event object
			 * elem is the element we'll be scrolling to
			 * $pane is the element being scrolled
			 * $items is the items collection at this moment
			 * pos is the position of elem in the collection
			 * if it returns false, the event will be ignored
			 */
			 //those arguments with a $ are jqueryfied, elem isn't.
			e.preventDefault();
			if( this.blur )
				this.blur();
		},
		onAfter:function( elem ){
			//'this' is the element being scrolled ($pane) not jqueryfied
		}
	});
	
	// Screenshots Scroll
	$('.screens .carousel').serialScroll({
		items:'.screen', // Selector to the items ( relative to the matched elements, '#sections' in this case )
		next:'a#scroll-screen',// Selector to the 'next' button (absolute too)
		axis:'x',// The default is 'y' scroll on both ways
		navigation:'#navigation li a',
		duration:1200,// Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
		force:false,	
		start: 0, // On which element (index) to begin ( 0 is the default, redundant in this case )		
		cycle:true,// Cycle endlessly ( constant velocity, true is the default )
		//step:1, // How many items to scroll each time ( 1 is the default, no need to specify )
		//jump:false, // If true, items become clickable (or w/e 'event' is, and when activated, the pane scrolls to them)
		//lazy:false,// (default) if true, the plugin looks for the items on each event(allows AJAX or JS content, or reordering)
		//interval:1000, // It's the number of milliseconds to automatically go to the next
		//constant:true, // constant speed
		
		onBefore:function( e, elem, $pane, $items, pos ){
			/**
			 * 'this' is the triggered element 
			 * e is the event object
			 * elem is the element we'll be scrolling to
			 * $pane is the element being scrolled
			 * $items is the items collection at this moment
			 * pos is the position of elem in the collection
			 * if it returns false, the event will be ignored
			 */
			 //those arguments with a $ are jqueryfied, elem isn't.
			e.preventDefault();
			if( this.blur )
				this.blur();
		},
		onAfter:function( elem ){
			//'this' is the element being scrolled ($pane) not jqueryfied
		}
	});
	
	/* Get Help Tab */
	$("#support-launch").hover(function(){
		$(this).stop(true, true);
    	$(this).animate({ left: '-3px' }, 200);
	},
	function(){
		$(this).animate({ left: '0px' }, 200);
	});
			
});
