function __loadSchedule(){

	$.each($('.tip'), function(){
		var $title = $(this).attr('title');
		var $date = $(this).attr('rel');
		var $desc = $(this).attr('desc');
		$(this).attr('title','');
		
		var xOffset = 10;
		var yOffset = 20;

		$(this)
			.mouseover(function(e){
				var $newTitle = $('<span>').addClass('tt_box').html($title+'&nbsp;&nbsp;&nbsp;&nbsp;<br />'+$date+'<br /><small>'+$desc+'</small>');
				$('body').append($newTitle);
				
				$(".tt_box").css({
					top : e.pageY - xOffset,
					left : 'auto',
					right : $(window).width() - 15,
					zIndex : 999,
					}).fadeIn("fast");						
			})
			
			.mouseout( function(e){
				$(this).attr('title', $title)
				$(".tt_box").remove();
			})
		
			.mousemove(function(e){
				$(".tt_box")
					.css({
						top : e.pageY - xOffset,
						left : 'auto',
						right : $(window).width() - 15
					})
			})	
			
			 // .click(function(e){
				
				// $id = $(this).attr('id');

				// $marginLeft = (e.pageX - 160) + 'px';			

				// $newEle = $('.details[id="'+$id+'"]').html();
				// $('body').append($newEle);
			
				// $('.eventbig[id!="'+$id+'"]').animate({opacity:'hide'}, 500).removeClass('active');
				
				// $('.eventbig[id="'+$id+'"]')
					// .css('left', $marginLeft)
					// .animate({opacity:'show'}, 500)
					// .addClass('active');	

				// $('.eventbig[id="'+$id+'"]').children('.event-close').click(function(){
					// $(this).parent('.eventbig').animate({opacity:'hide'}, 500, function(){
							// $(this).removeClass('active').remove();
						// });
				// });

				
			// });	
			
	});
}

function __loadMainNav(){
	$.each( $('#main-nav a'), function(){
		$(this)
	
			.click(function(){
				if( $(this).attr('class') == 'active' ) {
					return false;
				} else {
					var $id = $(this).attr('id');
					var $prev = $('#main-nav .active').attr('id');
					$prev = $prev.replace('_link','');
					$id = $id.replace('_link','');

					//pop the section derr
					popSection($id, $prev)

				}
			})
		
			.mouseover(function(){
				if( $(this).attr('class') != 'active' ){
					$(this).animate({opacity:'.90'});
				}
			})
		
			.mouseout(function(){
				$(this).animate({opacity:'1.00'});
			})
	});
}

function rgbhex(rgbval){
var s = rgbval.match(/rgb\s*\x28((?:25[0-5])|(?:2[0-4]\d)|(?:[01]?\d?\d))\s*,\s*((?:25[0-5])|(?:2[0-4]\d)|(?:[01]?\d?\d))\s*,\s*((?:25[0-5])|(?:2[0-4]\d)|(?:[01]?\d?\d))\s*\x29/);

var d='',e;
if(s){ s=s.splice(1); }
	if(s && s.length==3){
		d='';
		for(i in s){
			e=parseInt(s[i],10).toString(16);
			e == "0" ? d+="00":d+=e;
		} return '#'+d;
	}else{ return rgbval; }
}


//Function to convert hex format to a rgb color
function rgb2hex(rgb) {
	rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
		function hex(x) {
			hexDigits = new Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f");
			return isNaN(x) ? "00" : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16];
		}
	return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}



function popSection($id, $prev){
	//add url hash
	window.location.hash = '/'+$id;		
	
	//make selected state for button
	$('#main-nav #'+$id+'_link').addClass('active').siblings().removeClass('active');

	// a bunch of ifs
	if($prev == 'drawing'){
		$('div[id="media"] div[id="'+$prev+'"]').animate({opacity:'.5'}, 500, function(){
			doRest($id);
		});
	} 
	
	if($prev == 'schedule'){
		$('div[id="media"] div[id="'+$prev+'"]').animate({marginTop:'423px'}, 1000, 'easeInQuint', function(){
		
			doRest($id);
		});	
								
	}	
	
	if($prev == 'team'){
		$('div[id="media"] div[id="'+$prev+'"]').animate({marginTop:'423px'}, 1000, 'easeInQuint', function(){
		
			doRest($id);
			
		});	
								
	}			
	
	if($prev == 'questions'){
		$('div[id="media"] div[id="'+$prev+'"]').animate({marginTop:'423px'}, 1000, 'easeInQuint', function(){
			doRest($id);
		});	
								
	}
		
	if($prev == ''){
		doRest($id);
	}
	
			
}

function doRest($id){
	if($id == 'drawing'){
	
		$('div[id="media"] div[id="drawing"]').animate({opacity:'1.0'}, 500);
			
			
	}			
		
	if($id == 'schedule'){
		$('div[id="media"] div[id="drawing"]').animate({opacity:'.5'}, 500);
		
		var $timeBar = $('.time-bar').css('width');
		
		$('div[id="media"] div[id="'+$id+'"]')
			.addClass('above')
			.css({ marginTop:'423px'})
			.children('.event-container').children('.event').animate({ opacity:'hide' }, 0);
			
		$('.event-container .event').animate({ opacity:'hide' }, 0);
		$('.event-bars .event-bar').animate({ opacity:'hide' }, 0);
		$('.event-lines .event-line').animate({ opacity:'hide' }, 0);

			
		$('div[id="media"] div[id="'+$id+'"]').children('.time-container').children('.time-bar').css('width','0%');

		$('div[id="media"] div[id="'+$id+'"]').animate({marginTop:'0px'}, 1000, 'easeOutQuint', function(){
				$('.time-bar').animate({ width:$timeBar }, 1000, 'easeOutQuint', function(){
				
					$(function(){
						sequentFadeIn('.event-container .event', 0, $('.event-container .event').length, {opacity:'show'});
						sequentFadeIn('.event-bars .event-bar', 0, $('.event-bars .event-bar').length, {opacity:'show',  height:'show'});
						sequentFadeIn('.event-lines .event-line', 0, $('.event-lines .event-line').length, {opacity:'show', width:'show'});
					})
				
				});
				
			});
									
	} 	
	
	if($id == 'team'){
	
		$('div[id="media"] div[id="drawing"]').animate({opacity:'.2'}, 500);
	
		$('div[id="media"] div[id="'+$id+'"]')
			.addClass('above')
			.css({ marginTop:'423px'});
			
		$('#team a.otherteam').animate({opacity:'hide'}, 1);
		$('#team a.mainteam').css({ marginTop:'423px'});
		
		$('div[id="media"] div[id="team"]').animate({marginTop:'0px'}, 1000, 'easeOutQuint', function(){ 
		
			$('#team a.mainteam').animate({marginTop:'0px'}, 1000, 'easeOutQuint', function(){ 

				$(function(){
					sequentFadeIn('#team a.otherteam', 0, $('#team a.otherteam').length, {opacity:'show'} );
				})
			});
		});	
			
	}
	
	if($id == 'questions'){
		$('div[id="media"] div[id="drawing"]').animate({opacity:'.2'}, 500);

	
		$('div[id="media"] div[id="'+$id+'"]')
			.addClass('above')
			.css({ marginTop:'423px'});
			
		
		$('div[id="media"] div[id="questions"]').animate({marginTop:'0px'}, 1000, 'easeOutQuint');	
			
	} 	
	
}


function sequentFadeIn( $el, $i, $max, $params, $speed) {
	if( $speed == ''){
		$speed = 700;
	}
	if ($i <= $max) {
		$($el+':eq('+$i+')').animate($params, $speed, function() { 
			sequentFadeIn($el, ++$i, $max, $params, $speed ) 
		});
	}
	

}





