Cufon.replace(['#headerBtm p','.mod .mb h3','.mod .mh h2','.editableArea h2','.post h2','.project .mf h3','#rightCol h4','.homeOverride h3','#commentform label', 'p.publishInfo','#footer h4','#headerBtm h1'], { fontFamily: 'PF DinText Pro Thin'});
Cufon.replace(['#header .menu li a','.post h3'], { fontFamily: 'PF DinText Pro Thin', hover:true});
Cufon.replace(['strong','.editableArea h3:not(.homeOverride h3)','.editableArea h4','.blogListing ul li h3','.post h4','.post .categoryTags'], { fontFamily: 'PF DinText Pro Medium'});


$(document).ready(function() {
	$('body').addClass('jse');
	initScrollable();
	initFadedImageLinks();
	initPeopleListingMagic();
	initLazyLoad();
	descriptionMagic();
});

function initScrollable(){
	var projectBanner = $('#slides');
	if(projectBanner.length > 0){
		projectBanner.slides({
			preload: true,
			preloadImage: 'http://www.openingdoors.co.uk/wp-content/themes/openingdoors/_template/img/loading.gif',
			play: 6000,
			pause: 2500,
			slideSpeed: 1200,
			hoverPause: true
		});
	}
}


function initPeopleListingMagic(){
	var peopleItems = $('.personItem');
	if(peopleItems.length > 0){
		peopleItems.find('a').each(function(index){
            $(this).click(function(){ 
				$('.peopleListing .mf').hide().html($(this).parent().find('.personItemInner').html()).fadeIn('slow');		
				Cufon.refresh();
				$('html, body').animate({scrollTop:190}, 'slow');
			});
        });
	}
}

function initFadedImageLinks() {
    var imageLinks = $(".personItem a img, .clientListing .listItem a img");
    var excludeFromEffect = $('');
    if(imageLinks.length > 0) {
        if(imageLinks.length > 0){
            imageLinks.not(excludeFromEffect).css("opacity","1.0").hover(function() {
                $(this).stop().animate({
                    opacity: 0.7
                }, "fast");
                },
                function () {
                $(this).stop().animate({
                    opacity: 1.0
                }, "fast" );
            });
        }
    }
}

function initLazyLoad(){
	$('.personItem a img, .listItem img, .caseStudy img').lazyload({ 
		effect : "fadeIn"
	});
}

function descriptionMagic(){
	var self = $(".heroSignpost .mb .editableArea");
	if (self.length > 0) {
		var speed = 200;
		var orig = self.html();
		if (orig.search(/<!--more-->/) != -1) {
			var copy_split = orig.split(/<!--more-->/im);
			var copy = '<div class="copy-mini">' + copy_split[0] + '</div> \
<div class="copy-full">' + copy_split[1] + '</div> \
<div class="continue-reading"><p><a href="#">Continue Reading</a></p></div>';
			self.html(copy).data("open", false);
			var continue_height = $("div.copy-full", self).height();
			if (continue_height > 0) $("div.copy-full", self).height(1);
			else $("div.copy-full", self).hide();
			$(".continue-reading a", self).click(function () {
				if (self.data("open") == false) {
					if (continue_height > 0) $("div.copy-full", self).animate({
						height: continue_height
					}, speed);
					else $("div.copy-full", self).show();
					$(".continue-reading a", self).text("Close");
					self.data("open", true);
				} else if (self.data("open") == true) {
					if (continue_height > 0) $("div.copy-full", self).animate({
						height: '1px'
					}, speed);
					else $("div.copy-full", self).hide();
					$(".continue-reading a", self).text("Continue Reading");
					self.data("open", false);
				}
				return false;
			});
		}
	}	
}
