//Master Javascript file
//version:   3.0
//author:    Paul Boag
//email:     paul.boag@headscape.co.uk
//website:   http://www.headscape.co.uk


// Loads up the various functions we are going to use
$(document).ready(function(){
	swapLetter(); 
	imgCaption();
	latestShows(); 
	onFocus("input");
	onFocus("#comForm textarea");
	$("#juitterContainer").ready(function(){
	$.Juitter.start("searchWord","DesignTip");
	});
	
});

// Makes the latest shows expand and contract
function latestShows() {
	$("#sNav dd:first").css("display", "block");
	$("#sNav dt").mouseover(
	 function () {
		if ($(this).next().css("display") == "none") {
		$("#sNav dd").slideUp("slow");
        $(this).next().slideDown("slow");
		};
      });
}

// Adds in the drop cap
function swapLetter() {
  	var first_paragraph = $('#body p')[0];
  	if (!first_paragraph) { return false };
  	var text = first_paragraph.firstChild.nodeValue;
	if (!text) { return false };
	var first_letter = text.substr(0,1);
	if ( text ) {
    first_paragraph.firstChild.nodeValue = text.slice(1);
  };
  $("<span class='firstLetter'>" + first_letter +"</span>").prependTo( first_paragraph );
};


// Wraps images and adds caption

function imgCaption() {
	$(window).load(function() {
	$("#body img").each( function() {
	if ($(this).width() < 370) {
		$(this).wrap("<div class='img floatMe' style='width:" + ($(this).width() + 2) + "px'></div>");
			if ($(this).attr("title")!=undefined) { $(this).after("<p class='caption'>" + $(this).attr("title") + "</p>") };
			if ($(this).parents("a").attr("title")!=undefined) { $(this).after("<p class='caption'>" + $(this).parents("a").attr("title") + "</p>") };
		$(this).parents("a").addClass("imgSur");
	} else {
		$(this).wrap("<div class='img' style='width:" + ($(this).width() + 2) + "px'></div>");
			if ($(this).attr("title")!=undefined) { $(this).after("<p class='caption'>" + $(this).attr("title") + "</p>") };
			if ($(this).parents("a").attr("title")!=undefined) { $(this).after("<p class='caption'>" + $(this).parents("a").attr("title") + "</p>") };
		$(this).parents("a").addClass("imgSur");
	};
	if ($(this).width() > 600) {
		$(this).parents(".img").width("580px");
	}
	});
							});
};