$(document).ready(function() {
						   
	/** STYLESWITCHER - REMOVE THIS ONCE YOU'VE PURCHASED THIS FILE **/
		var bodyClass = $('body').attr('class');
		$('div#styleswitcher ul.stylePatterns a').not('.noshadow').click(function() {
			if( $(this).hasClass('nobg') ) {
				$('body').attr('class', bodyClass);
			} else {
				$('body').attr('class', bodyClass).addClass($(this).attr('class'));
			}
		});
		$('.styleswitcher-trigger').click(function() {
			if( $(this).parent().hasClass('styleswitcher-toggled') ) {
				$(this).parent().stop().animate({marginLeft: 0}).removeClass('styleswitcher-toggled');
			} else {
				$(this).parent().stop().animate({marginLeft: '-102px'}).addClass('styleswitcher-toggled');
			}
		});
		
		$('div#styleswitcher select').change(function() {
        var newFont = $(this).val();
		var defaultFont = $(this).val().indexOf('Perpetua')>-1;
        $('h3.top-message, div.testimonial h3, div.testimonial-widget h6,.blockquote_s, .blockquote_m, .blockquote_l').each(function() {
            var h3 = $(this);
            // cache the current height
            $.data(h3, 'befH', $(this).outerHeight());
            // change the font
            if( defaultFont == false ) {
				$(this).css({
					fontFamily: newFont
				});
			} else {
				$(this).css({
					fontFamily: 'Perpetua',
					fontSize: '26px'
				});
			}
            // if the new height is higher than the older one
            if ($(this).outerHeight() > $.data(h3, 'befH')) {
                // reduce the font size untill the new height is less than the old one
                while ($(this).outerHeight() > $.data(h3, 'befH')) {
                    $(this).css({
                        fontSize: parseInt($(this).css('font-size')) - 1
                    });
                }
            }
        });
    });
});
