
	var heightDifference = 499 + 22;
	var heightLimit = 260;

	$(document).ready( function() {

	        $.localScroll();

		$('td a.book + p').add('p#crayon-desc').hide();

		$('a.home-feat').click( function() {
			var featSrc = $(this).parent().parent().parent().children('.fl').children('img').attr('src');
			sample(featSrc);
		});

		$('a.book').wrap('<div style="position:relative;"></div>').after($('#bubble').clone());

		$('a.book').mouseover( function() {
			var html = $(this).parent().next('p').html();

				if($(this).hasClass("crayon-home")) {
					$(this).next(('#bubble')).html('<div style="line-height:1.1em;">' + html + '</div>').css( {
						bottom: '170px',
						left: '-125px'
					}).show();
				} else {
					$(this).next(('#bubble')).html('<div style="line-height:1.1em;">' + html + '</div>').css( {
						bottom: '40px',
						left: '-240px'
					}).show();
				}



		}).mouseout(function() {

			$('.bubble').hide();
		}).click(function() {
			var imgSrc = $(this).children('img').eq(0).attr('src');
			var bookDesc = $(this).parent().next('p').html();
			sample(imgSrc, bookDesc);
		});

		if($('body').attr('id') == 'home'){
			heightDifference += 130;
		}

		$('#crayon-feature a:first-child').unbind('click').click( function() {
			crayons();
		});

		sizePage();


          // hide subnav <li> if child <a> links to
          // an anchor not present on the page.
		if(!($('a#anchor-sb').length)) {
			$('#sub-sb').hide();
			$('#sub-cb').children('a').addClass('first');
		}
		if(!($('a#anchor-cb').length)) {
			$('#sub-cb').hide();
		}
		if(!($('a#anchor-ab').length)) {
			$('#sub-ab').hide();
		}
		if(!($('a#anchor-s').length)) {
			$('#sub-s').hide();
		}
		if(!($('a#anchor-gc').length)) {
			$('#sub-gc').hide();
		}
		if(!($('a#anchor-ap').length)) {
			$('#sub-ap').hide();
		}
		if(!($('a#anchor-ah').length)) {
			$('#sub-ah').hide();
		}
		if(!($('a#anchor-c').length)) {
			$('#sub-c').hide();
		}

          // find the last <li> and give its child <a>
          // a class of 'last'
		$vList = $('ul#subnav li:visible');
		var lastV = $vList.length - 2;
		$vList.eq(lastV).children('a').addClass('last');

	});

	$(window).resize( sizePage ).scroll( scrollPage );

	function sizePage() {
		var size = dynamItWindowSize();
		var newSize = (size.h - heightDifference);

		if(newSize <= heightLimit) return;

		var property = (IE6) ? 'height' : 'min-height';

		$('#outer').css(property, newSize + 'px');

	}

	var offset = 275;
	function scrollPage() {

		var footerHeight = document.getElementById("footer").offsetTop;

		var myHeight = parseInt( $("#scroller").css('height') );
		if(isNaN(myHeight)) myHeight = 700;

		var top = scrollY() - offset;

		if(top < 0) top = 0;
		if(scrollY() + myHeight > footerHeight) return;
		$("#scroller").css({ top: top + 'px' });

	}


// home page slider
function portfolioScroll (strDirection) {
    if ((strDirection == 'left') && (intPortfolioMargin != 0)) {
        intPortfolioMargin += intShift;
        $('#ar').fadeTo('fast', 1);
        if (intPortfolioMargin == 0) $('#al').fadeTo('fast', .25);
    }
    if ((strDirection == 'right') && (intPortfolioMargin > -1*((intNumPortfolioItems - 1) * intShift))) {
        intPortfolioMargin -= intShift;
        $('#al').fadeTo('fast', 1);
        if (intPortfolioMargin == -1*((intNumPortfolioItems - 1) * intShift)) $('#ar').fadeTo('fast', .25);
    }
    $('#slides').animate({marginLeft: intPortfolioMargin+'px'}, 'slow', 'swing');

}

// send a sample overlay
function sample(imgPath, bookDesc) {
	var bookDesc = urlencode(bookDesc);
	dynamItLoad('/sample/dlg_sample.php?i=' + imgPath + '&b=' + bookDesc, null, 465, 493, null);
}

// send a sample overlay
function sampleC(imgPath) {
	dynamItLoad('/sample/dlg_sample.php?i=' + imgPath, 'dynamItPopUp', 465, 493, null);
}

// virtual sample description overlay
function sDescription() {
	dynamItLoad('/sample/dlg_sample-desc.php', null, 465, 493, null);
}

// crayon pricing info overlay
function crayons() {
	dynamItLoad('/sample/dlg_crayons.php', null, 465, 493, null);
}