var animate = {
	zLine: -999,
	
	//
	// Line color change.
	//
	line: function(i, f) {
		if (!f) f = function() { };
		
		nf = function() {
			var p = $(this).parent()[0];
			if (p.id && p.id == 'oz') f();
		};
		
		$('.robe_' + i.newId)
			.css({ 'opacity': 0, 'z-index': animate.zLine++ })
			.stop().animate({
				'opacity': 1
			}, n.anim.line.time(), n.anim.line.easing, nf);
	},
	
	//
	// Animate teh blip!!1 	//	assumes i.coeff: speed coefficient
	// 
	navBlip: function(i, f) {
		if (!f) f = function() { };

		// Animate the blip width
		$('#blip').stop().animate({
			'width': n.sects[i.newId].blipWidth + 'px',
			marginLeft: -1 * ((n.sects[i.newId].blipWidth - 100) / 2)
		}, n.anim.nav.blip.time() * i.coeff, n.anim.nav.blip.easing, f);
		
		// Animate the blip position
		$('#track-wrap').stop().animate({
			'left': ((n.sects[i.newId].index - 1) * 100) + 'px'
		}, n.anim.nav.blip.time() * i.coeff, n.anim.nav.blip.easing);
		
		// Animate the gradient
		$('#navigation ul').stop().animate({
			backgroundPosition: ((n.sects[i.newId].index - 1) * 100 - 200) + 'px 0'
		}, n.anim.nav.gradient.time() * i.coeff, n.anim.nav.gradient.easing);

		// Animate the map
		$('#top_map').stop().animate({
			//'top': (mapInfo['sectionHeight'] * (-selectedInfo[0]) - mapInfo['topOffset']) + 'px'/*,
			backgroundPosition: -n.sectWidth *  (n.sects[i.newId].index - 1) + 'px 60px'
		}, n.anim.nav.blip.time() * i.coeff, n.anim.nav.blip.easing);
//			backgroundPosition: -n.sectWidth * newInfo[0] + 'px 10px'
//		}, n.anim.navBlip[0] * i.coeff, n.anim.navBlip[1]);



	},

	openSesame: function(f) {
		if (!f) f = function() { };

		$('.sesame').css({ 'display': 'block', 'opacity': 0 }).stop().animate({
			'opacity': 1
		}, 500, 'easeOutExpo', f);
	},
	
	closeSesame: function(f) {
		if (!f) f = function() { };

		$('.sesame').stop().animate({
			'opacity': 0
		}, 1000, 'easeOutExpo', function() {
			$(this).css('display', 'none');
			f();
		});
	},
	
	//
	// Note: For 3A functions, easing is also a function.
	//
	
	
	//
	// 3a open animation
	//
	open: function(i, f) {
		if (!f) f = function() { };
		var introCoeff = 0.5;

//alert(n.anim.aaa.co[0] * (i.intro ? 0.5 : n.anim.aaa.coeff));
		$('.curtain').stop().animate({ 'width': '2.5%' }, n.anim.aaa.co.time(i.intro), n.anim.aaa.co.easing(i.intro));

		$('.shutter').stop().animate({ 'height': '100px' }, n.anim.aaa.so.time(i.intro), n.anim.aaa.so.easing(i.intro), 
			function() {
				if (this.id && this.id == 'omgcurtain') setTimeout(f, 30);
			});
			
	},
	
	// 
	// 3a close animation
	//
	close: function(i, f) {
		if (!f) f = function() { };
		$('.shutter').stop().animate({ 'height': '50%' }, n.anim.aaa.sc.time(i.intro), n.anim.aaa.sc.easing(i.intro), function() {
			if (this.id && this.id == 'top') setTimeout(f, 1500);
		});
		
		$('.curtain').stop().animate({	'width': '55%' }, n.anim.aaa.cc.time(i.intro), n.anim.aaa.cc.easing(i.intro));
	
	},
	
	// 
	// Zoom the headers 'round
	//
	heading: function(i, f) {
		if (!f) f = function() { };
		
	//	var key = function(sect) { for (k in n.headings) if (n.headings[k] == sect) return k; };


		var key = function(sect) { for (name in n.sects) if (n.sects[name].index == sect) return name; };

		var ct = '#title_' + i.curId;
		var cs = '#title_' + key(n.sects[i.curId].index + 1);
		var nt = '#title_' + key(n.sects[i.newId].index);
		var ns = '#title_' + key(n.sects[i.newId].index + 1);
			
		$('#thor .title')
			.css('margin-top', '0%');
			
	//	alert(ns);
		
		/* get top of current NS and animate to top: currenttop % - 10% or something */
		/* then when you go again in that direction, animate from newtop back to current top and then continue transition like this oncomplete */
		var sizeSub = function() {
			$(ns).stop().animate({ 'width': '50%' }, n.anim.thor.size.time() * settings[0], n.anim.thor.size.easing);
		};
		
		var sizeTitle = function() {
			$(nt).stop().animate({ 'width': '65%' }, n.anim.thor.size.time() * settings[0], n.anim.thor.size[1]);		
		};

		var settings = n.anim.thor.settings[n.sects[i.newId].index - n.sects[i.curId].index];
	//	alert();
	//	alert(settings[0] + ' ' + settings[1] + ' ' + settings[2]);
			
		if (n.sects[i.newId].index - n.sects[i.curId].index < 0)
			$(nt).css('width', '65%');	
		else
			setTimeout(sizeTitle, settings[1]);
		
		if (ct == ns)
			setTimeout(sizeSub, settings[2]);
				
//		var singleHeight = $(ns).height();
		var destHeight = (-50 * (n.sects[i.newId].index - 1)) + '%';
//		var destHeight = -$(nt).position()['top'];
		

		$('#odin').stop().animate({ 'top': destHeight }, n.anim.thor.position.time() * settings[0], n.anim.thor.position.easing, function() {
		
				// animate the one that's above a bit more to the top.
				if (n.sects[i.newId].index > 1)
					$('#title_' + key(n.sects[i.newId].index - 1)).css('margin-top', '-3%');
				
				$('#thor .title').not(nt).not(ns).css('width', '50%');
				f();
		});
	}
};
