var project_data = {
	nav : [
		{}],
	images : {
		location : typeof IMAGE_LOCATION == 'undefined' ? '/' : IMAGE_LOCATION,
		files : []
	}
};

$(document).ready(function(){
	
	project_data.wrapper = $('#wrapper');
	var preload = new Preloader(project_data['images']['files'], project_data['images']['location']);
	$(window).resize( function(e) {setSize(project_data.wrapper);});

	
	$('.fancy').fancybox({
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'elastic',
			'width'			: 	800,
			'height'		: 600,
			'autoDimensions' : false,
			'speedIn'		:	600, 
			'speedOut'		:	200, 
			'overlayShow'	:	true,
			'type' : 'iframe'
		});
	
		$('.topnav').bind('mouseover', function(){
				if (typeof timeout != 'undefined') clearTimeout(timeout);
				$('.topnav').removeClass('hover');
				$('.subnav').hide();
				$(this).find('.subnav').show();
				$(this).addClass('hover');
		});
		$('.topnav').bind('mouseout', function(){
			var _this = $(this);
			timeout = setTimeout(function(){
				_this.removeClass('hover');
				_this.find('.subnav').hide();
			}, 750);
		});
		
	$('.subnav').bind('mouseover', function(){
		clearTimeout(timeout);
		$(this).parent('li').addClass('hover');
		$(this).show();
	});
	$('.subnav').bind('mouseout', function(){
		$(this).parent('li').removeClass('hover');
		$(this).hide();
	});
	
	$('img.swap').live('mouseover', function(){
		var orig = $(this).attr('src');
		var dest = orig.replace('off', 'on');
		$(this).attr('src', dest);
	});
	$('img.swap').live('mouseout', function(){
		var orig = $(this).attr('src');
		var dest = orig.replace('on', 'off');
		$(this).attr('src', dest);
	});
});

function puptogoTwitter(twitters) {
		var statusHTML = [];
		for (var i=0; i<twitters.length; i++){
		//	console.log(twitters[i]);
			var username = twitters[i].user.screen_name;
			var status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url){return '<br /><a target="_blank" href="'+url+'">'+url+'</a><br />';}).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
				return reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
			});
			var source = twitters[i].source;
			
			var timeIn = Date.parse(twitters[i].created_at);
			
			var timeOut = formatDate(timeIn);
			
			
			statusHTML.push('<div class="tweet"><div class="tweet_info">'+timeOut+' via '+source+'</div><div class="tweet_top"></div><div class="tweet_middle"><div class="tweet_body">'+status+'</div></div><div class="tweet_bottom"></div></div>');
		}
		document.getElementById('twitter_update_list').innerHTML = statusHTML.join('');
}

function formatDate(input){
	var m_names = new Array("January", "February", "March", 
	"April", "May", "June", "July", "August", "September", 
	"October", "November", "December");

	var d = new Date(input);
	var curr_date = d.getDate();
	var sup = "";
	if (curr_date == 1 || curr_date == 21 || curr_date ==31)
	   {
	   sup = "st";
	   }
	else if (curr_date == 2 || curr_date == 22)
	   {
	   sup = "nd";
	   }
	else if (curr_date == 3 || curr_date == 23)
	   {
	   sup = "rd";
	   }
	else
	   {
	   sup = "th";
	   }

	var curr_month = d.getMonth();
	var curr_year = d.getFullYear();
	var hours = d.getHours()
	var minutes = d.getMinutes()
	if (minutes < 10){
	minutes = "0" + minutes
	}
	var amPM = hours > 11 ? 'PM': 'AM';
	if(hours > 11){ hours = hours - 11;}
	return(hours+':'+minutes+' '+amPM+' on '+m_names[curr_month]+' '+curr_date + "<sup>" + sup + "</sup>");	
}


function setSize(wrapper){	

	
}
