//=============================================================================
/* 

	main.js
	v1.0
	2009/01/28

	Headscape
	Written by Chris Sanderson (chris.sanderson@headscape.co.uk)

	The behaviours are served to all sites.

*/
//=============================================================================
// Creates the shadow that sits beneath the main page image

function pageImageShadow() {
	$("#pageImageContainer").append('<span class="shadow"></span>');
}

//=============================================================================
// Adds the background images for the footerInfo columns

function footerInfoColBkgs() {
	$("#footerInfo").append('<span id="visitorInfoBack"></span><span id="extraInfoBack"></span>');
}

//=============================================================================
// Adds the background images for the footerInfo columns

function sNavOpenLevelBullets() {
	$("#sNavigation ul ul li a").prepend('<span class="bullet"></span>');
}

//=============================================================================
// Creates the quotes on blockquote elements
function blockquoteCorners() {
	$("blockquote").append('<span class="bqTL"></span><span class="bqBR"></span>');
}

//=============================================================================
// Smoothly expands FAQ answers, only showing one at a time
function expandFAQs() {
	$('.lAnswer').hide();
	$('.lQuestion').click(function(){
		$(this).parent().siblings().find('.lAnswer').slideUp("fast");
		$(this).siblings('.lAnswer').slideDown("fast");
		if($(this).attr('href') =='#') {
			return false;
		} else {
			return true;
		};
    });
    $('#expandCollapse a').click(function(e) {
        if ($('.lAnswer:hidden').length > 0) {
            $('.lAnswer').slideDown("fast");
            $(this).text('Collapse all answers').parent().removeClass('expand').addClass('collapse');
        }
        else {
            $('.lAnswer').slideUp("fast");
            $(this).text('Expand all answers').parent().removeClass('collapse').addClass('expand');
        }
        return false;
    });
}

//=============================================================================
// Add hover state to list items
function listLinkHover() {
	$(".newsList li, .Landing #relatedLinks li").hover(
		function() {
			$(this).addClass("hover");
		},
		function() {
			$(this).removeClass("hover");
		}
	);
	$(".newsList li, .Landing #relatedLinks li").click(function() {
		if ($(this).find("a").attr("href")) {
			window.location = ($(this).find("a").attr("href"));
		}
	});
}

//=============================================================================
// Clear value on focus
function clearOnEnter() {
	$(".clearOnEnter").focus(function() {
		$(this).val("");
		$(this).unbind("focus");
	});
}

//=============================================================================
// Add class to alternate form rows
function alternateFormRows() {
	$("form .row:even").addClass("alternate");
}

//=============================================================================
// Add caption to content images
function contentImages() {
	$(window).load(function() {
	    $("body:not(.ImageGallery, .NewsListing) .mText .content img").each(function () {
			divWrapper = '<div class="' + $(this).attr("class") + '" style="width: ' + $(this).width() + 'px;"></div>';
			if ($(this).parent().get(0).tagName=="A") {
				$(this).parent().wrap(divWrapper);
			} else {
				$(this).wrap(divWrapper);
			};
			$(this).removeAttr("class");
			if ($(this).attr("title")!="") {
				$(this).after('<p class="caption">' + $(this).attr("title") + "</p>");
			} else if ($(this).parent("a").attr("title")!="" && $(this).parent("a").attr("title")!=undefined) {
				$(this).after('<p class="caption">' + $(this).parent("a").attr("title") + "</p>");
			};
		});
	});
}

//=============================================================================
// loads up the various functions we are going to use

$(document).ready(function(){
	pageImageShadow();
	footerInfoColBkgs();
	sNavOpenLevelBullets();
	blockquoteCorners();
	contentImages();
	clearOnEnter();
	listLinkHover();
	alternateFormRows();
	expandFAQs();
	$("a[rel^='prettyPhoto']").prettyPhoto();
});

//=============================================================================


