$(function() {
	

		   
	//Basic page setup
	//corners
	$('#inspiration_header').corner('20px');
	$('#inspiration_wrapper').corner('20px');
	$('.toggle').corner('10px');
	$('#intro').corner('20px');
	$('#news').corner('20px');
	$('.newsItem').corner('20px');
	$('#whats_new div').corner('20px');
	$('#contentList li').corner('20px');
	$('.box').corner('20px');
	$('.formRounder').corner('5px');$('.textAreaFormRounder').corner('5px');
	$('pre').corner('20px');
	
	//h1 fix
	$('.box:first').css('marginTop','0');
	
	//other
	$('#input').fadeTo(0,.5);
	$('#social img').fadeTo(0,.5);
	
	//image predloading
	img1 = new Image();
	img1.src = "/images/logo.png";
	
	img2 = new Image();
	img2.src = "/images/logo_hover.png";
	
	img3 = new Image();
	img3.src = "/images/box_out.png";
	


	//mouse overs
	$('#topa').hover(function() {
	$('#top').css('background', 'url("/images/logo_hover.png")');
	}, function() {
	$('#top').css('background', 'url("/images/logo.png")');
	});

	//social icons
	$('#social img').hover(function() {
		$(this).fadeTo(0,1);
		$(this).parents('a').stop().animate({paddingTop:0},250, function() {
			$(this).animate({paddingTop:15},150, function() {
				$(this).animate({paddingTop:7},150, function() {
					$(this).animate({paddingTop:15},100);
				});
			});
		});
	}, function() {
		$(this).fadeTo(0,.5);
	});

	//form function
	$('#search_box').focus(function() {
		$(this).parents('#input').fadeTo(250, 1);
	});

	$('#search_box').blur(function() {
		$(this).parents('#input').fadeTo(750, .5);
		$(this).val('');
	});

	//slide animation for what's up box

	$('#whats_new li a').hover(function() {
	$(this).stop().animate({ paddingLeft: 15},250);
	}, function() {
	$(this).stop().animate({ paddingLeft: 25},250);
	});

	//Image toggle
		//needs to be more generic
		//needs to work better in IE7

	$('.toggle').click(function() {
		if ($(this).siblings('#img_holder').is(':hidden')) {
			$(this).html('Minimize');
			$(this).siblings('#img_holder').animate({height: height}, 500);
			$(this).parents('.closableImg').animate({minHeight: height}, 500);
			$(this).parents('#intro').children('.story').slideDown(500);
			$(this).parents('.closableImg').siblings('.headline').animate({paddingTop: 15},500);
		}
		else {
			height = $(this).siblings('#img_holder').css('height');
			$(this).html('Expand');
			$(this).siblings('#img_holder').animate({height: 0}, 500, function() {$(this).hide();});
			$(this).parents('.closableImg').animate({minHeight: 1},500);
			$(this).parents('#intro').children('.story').slideUp(500);
			$(this).parents('.closableImg').siblings('.headline').animate({paddingTop: 0},500);
		}
	$(this).corner('10px');
	});

	//bounce FX
	$('#nav a').mouseover(function() {
		$(this).stop().animate({marginTop:0},250).animate({marginTop:15},150).animate({marginTop:7},150).animate({marginTop:15},100);
	});

//whats new title length limit
	$('#whats_new div ul li a').each(function() {
		var charLimit = 30; //set to max number of characters in these links, prevents links from running too far
		$(this).attr('title', $(this).text());
		if(($(this).text()).length > charLimit) {
			$(this).html(($(this).html()).substring(0,charLimit) + '...');
		}
	});

//fancy date

	var message;
	$('.updated').each(function() {
		today = new Date();
		posted = new Date($(this).text().substring(($(this).text()).lastIndexOf(':') + 1));
		days = Math.round((today-posted)/(1000*60*60*24));
		days--;
		if (days < 0) {
			message='This is a message from the future!';
		}
		else if (days==0) {
			message='Posted Today';
		}
		else if (days==1) {
			message = 'Posted Yesterday';	
		}
		else if (days <= 30) {
			message='Posted ' + days + ' Day' + ((days==1)?' ':'s ') + 'Ago';
		}
		else {
			message='Posted ' + Math.round(days/30) + ' Month' + ((Math.round(days/30)==1)?' ':'s ') + 'Ago';
		}
		$(this).html(message);
	});

//Unavailable Features
	$('.comments').click(function() {
		$(this).siblings().stop().remove();
		$(this).parent().append('<p style="margin: 0; padding:0"><div style="display:none; float:left;">This feature is currently unavailable</div></p>');
		$(this).siblings().fadeIn(1500).animate({opacity:1.0},1000).fadeOut(1500);

	});
	
	$('.networks a, .news a').click(function() {
		if ($(this).parents('#social').children('span:first').attr('class')!='networks') $(this).parents('#social').children('span:first').stop().remove();
		$(this).parents('#social').prepend('<span style="display:none;margin-top:40px; position:absolute;font-size:14px;line-height:14px;padding-right:10px;position:absolute;right:0;text-align:right;">This feature is<br/> currently unavailable</span>');
		$(this).parents('#social').children('span:first').fadeIn(1500).animate({opacity:1.0},1000).fadeOut(1500);
	});
	

});