$(function() {
	var bodyClass = myBodyClass(jQuery.url.attr("directory"));
  $("body").addClass(bodyClass);
	$("#projects").before("<a href='javascript:void(0);' class='arrow-left'><span><strong>Previous Project</strong></span></a>").before("<a href='javascript:void(0);' class='arrow-right'><span><strong>Next Project</strong></span></a>");
	$("#header ul li a strong, #featuredprojects .arrow-left span, #featuredprojects .arrow-right span, #content .nav ul li a").css("opacity", "0");
  $("#header ul li a strong, #featuredprojects .arrow-left span, #featuredprojects .arrow-right span, #content .nav ul li a").hover(function() {
		$(this).stop().animate({ opacity: 1 }, "medium");
	}, function() {
		$(this).stop().animate({ opacity: 0 }, "slow");
  });
	$("#content .latestnews .news").hover(function() {
		$(this).addClass("news-hover");
	}, function() {
		$(this).removeClass("news-hover");
	}).click(function(){
		window.location = $(this).children("h3").children("a").attr("href");
	});
	$("#content .main .newslist .article").hover(function() {
		$(this).addClass("article-hover");
	}, function() {
		$(this).removeClass("article-hover");
	}).click(function(){
		window.location = $(this).children("a").attr("href");
	});
	$("#content .main .servicelist .service").hover(function() {
		$(this).addClass("service-hover");
	}, function() {
		$(this).removeClass("service-hover");
	}).click(function(){
		window.location = $(this).children("h2").children("a").attr("href");
	});
	$('#projects').cycle({ 
    fx:     'scrollHorz', 
    speed:  'medium', 
    timeout: 0, 
    next:   '#featuredprojects .arrow-right', 
    prev:   '#featuredprojects .arrow-left' 
	});
	formatH1();
	$('#content .main .helpfulstufflist .resource h2').append('<span>expand</span>');
	$('#content .main .helpfulstufflist .resource h2:odd').addClass('alt');
	$('#content .main .helpfulstufflist .resource .description').height(0);
	$('#content .main .helpfulstufflist .resource h2 span').click(function(){
		var a = 0;
		var b = $(this).parent().next('div').children('p').each(function(){ a += $(this).outerHeight(true); });
		if($(this).parent().next('div').height() == 0){
			$(this).parent().next('div').animate({
				height: a
			}, 500, function(){
				$(this).parent().addClass('expanded');
				$(this).prev('h2').children('a').next().html('collapse');
			});
		} else {
			$(this).parent().next('div').animate({
				height: 0
			}, 250, function(){
				$(this).parent().removeClass('expanded');
				$(this).prev('h2').children('a').next().html('expand');
			});
		}
	});
});

function myBodyClass(src) { var myClass = ''; var a = src.substr(1).split("/"); for (i = 0; i < a.length; i++) { for (j = 0; j < i; j++) { myClass += a[j]; if ((j+1) != i) { myClass += "-"; } } myClass += " "; } return myClass.toLowerCase(); }

function formatH1() {
	if(!$("body").hasClass("root")){
		var src = $("#content .main h1").html();
		var letter = src.charAt(0);
		var newSrc = src.substring(1);
		$("#content .main h1").html("<span class='" + letter.toLowerCase() + "'><span>" + letter + "</span>" + newSrc + "</span>");
	}
}