function pageLoad() {

    /* CB - these divs are hidden and then displayed on domready event to avoid
    a loading display issue */
    var objectSizeRange = $("#object-size-range");
    var priceRange = $("#price-range");

    objectSizeRange.parent().css('display', 'block');
    priceRange.parent().css('display', 'block');

    objectSizeRange.slider({
        range: true,
        min: 0,
        max: 1200,
        values: [objectSizeRange.parent().children('div.sliderValuesLeft').children('input.from').val(),
                 objectSizeRange.parent().children('div.sliderValuesRight').children('input.to').val()],
        slide: function(event, ui) {
            $(this).parent().children('div.sliderValuesLeft').children('input.from').val(ui.values[0]);
            $(this).parent().children('div.sliderValuesRight').children('input.to').val(ui.values[1]);
        }
    });



    priceRange.slider({
        range: true,
        min: 0,
        max: 10000000,
        values: [priceRange.parent().children('div.sliderValuesLeft').children('input.from').val(),
                 priceRange.parent().children('div.sliderValuesRight').children('input.to').val()],
        slide: function(event, ui) {
            $(this).parent().children('div.sliderValuesLeft').children('input.from').val(ui.values[0]);
            $(this).parent().children('div.sliderValuesRight').children('input.to').val(ui.values[1]);
        }
    });

    /* hide the labels if someone starts typing */

    /*
    $('.tooltips input').keypress(function() {
    if ($(this).val() == '') $(this).parent().children('label').css('color', '#000');
    else $(this).parent().children('label').css('color', '#fff');
    });
    */
    /* this is just to check the inputs at load time in case someone hits f5 */

    /*
    $('.textfield input').each(function() {
    if ($(this).val() == '') $(this).parent().children('label').css('color', '#000');
    else $(this).parent().children('label').css('color', '#fff');
    });
    */

    /* these handle the threadless style rollovers */

    $('.imagepanel').hover(
			function() { $(this).parent().children('.results.grid ul li .lotinfo').fadeIn(); }
		); 

    // CB This stops the popup disappearing in the search results grid view mode when you select a portfolio from the dropdown
    //$(".results.grid select").mouseleave(function(event) { event.stopPropagation(); });

    $('.results.grid ul li .lotinfo').hover(
			null,
			function() {
			    $(this).fadeOut();
			    // CB This closes the popup form
			    //$('.popupForm').fadeOut();
			}
		); 

    $('.results.grid ul li .lotinfo').each(function() {
        $(this).css('margin-top', '-204px');
        $(this).hide();
    }); 

    /* controls the add to portfolio dialogues */

    $('.portfolioButton').click(
			function(e) {
				var popupForm = $('.addRemovePortfolioForm');
				//getting height and width of the message box
				var height = popupForm.height();
				var width = popupForm.width();
				//calculating offset for displaying popup message
				leftVal = e.pageX - (width * 1.1) + "px";
				topVal = e.pageY - (height * 1.3) + "px";
				//show the popup message and hide with fading effect
				popupForm.css({ left: leftVal, top: topVal }).fadeIn();

				/*popupForm.keypress(function(e) {
				if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
				popupForm.children('.default').click();
				popupForm.fadeOut();
				return true;
				}
				});*/
				popupForm = null;
				return false;
			}
		);

        /* Controls the remove from portfolio dialogue */
		$('.removeFromPortfolioButton').click(
			function(e) {
				var popupForm = $(this).parent().children('.addRemovePortfolioForm');
				//getting height and width of the message box
				var height = popupForm.height();
				var width = popupForm.width();
				//calculating offset for displaying popup message
				leftVal = e.pageX - (width * 1.1) + "px";
				topVal = e.pageY - (height * 1.3) + "px";
				//show the popup message and hide with fading effect
				popupForm.css({ left: leftVal, top: topVal }).fadeIn();
				popupForm = null;
				return false;
			}
		);

       $('.popupForm').click(
			null,
			function(e) {
			    e.preventDefault();
			    $(this).fadeOut();
			    return false;
			}
		);

    /* Save search Popup Form */
    $('.savesearch').toggle(
			function() { $('.saveSearchForm').fadeIn(); },
			function() { $('.saveSearchform').fadeOut(); }
		);

    /* Add Portfolio Popup Form */
    $('.addPortfolioAction').toggle(
		function() { $('.newPortfolioForm').fadeIn(); },
		function() { $('.newPortfolioForm').fadeOut(); }
	);

    /* Edit Portfolio Popup Form */
    $('.editPortfolioAction').toggle(
		function() { $('.editPortfolioForm').fadeIn(); },
		function() { $('.editPortfolioForm').fadeOut(); }
	);

    /* Delete Portfolio Popup Form */
    $('.deletePortfolioAction').toggle(
		function() { $('.deletePortfolioForm').fadeIn(); },
		function() { $('.deletePortfolioForm').fadeOut(); }
	);

    /* Controls the closing of the popup froms when clicking cancel button */
    $('.popupForm input.button').click(function() {
    	$(this).parent().fadeOut();
    });

    /* controls the red carousel on the home page */

    if ($(".carouselitems").length > 0) {
        // Add Carousel Buttons
        $('.carousel h3').before('<a class="carousel-control prev">&lt;</a>');
        $('.carousel h3').after('<a class="carousel-control next">&gt;</a>');

        // Get some vars going
        var total_items = $('.carousel li').length;
        var current_position = 0;
        var auto_play = true;

        function carouselNext(carousel) {
            if (current_position == total_items - 2) {
                current_position = 0;
                $(carousel).animate({ left: '0px' }, 5000, "swing");
            } else {
                current_position = current_position + 2;
                new_left = '-' + (309 * current_position) + 'px'
                $(carousel).animate({ left: new_left }, 5000, "swing");
            }
        }

        function carouselPrev(carousel) {
            if (current_position == 0) {
                current_position = total_items - 2;
                new_left = '-' + ((309 * current_position)) + 'px'
                $(carousel).animate({ left: new_left }, 5000, "swing");
            } else {
                current_position = current_position - 2;
                new_left = '-' + (309 * current_position) + 'px'
                $(carousel).animate({ left: new_left }, 5000, "swing");
            }
        }

        function autoPlay(carousel, first) {
            if (first == true) {
                var t = setTimeout(function() { autoPlay(carousel, false) }, 10000);
            } else if (auto_play == true) {
                carouselNext(carousel);
                var t = setTimeout(function() { autoPlay(carousel, false) }, 10000);
            } else {
                clearTimeout(t);
            }
        }

        $('.carousel a.carousel-control.prev').bind('click', function() {
            auto_play = false;
            carouselPrev($(this).parent().find('ul'));
        });

        $('.carousel a.carousel-control.next').bind('click', function() {
            auto_play = false;
            carouselNext($(this).parent().find('ul'));
        });

        autoPlay('.carousel ul', true);
    }

    /* Activates Zoomable Main Image on the homepage */

    if ($("a.zoom").length > 0) {
        $("a.zoom").jqzoom({
            title: false
        });
    }


    /* Auctions Type Refine on Click */
    $('.type-refine input').bind('focus', function() {
        if ($(this).attr('value') == 'Start typing Sale information') {
            $(this).attr('value', '');
        }
    });
}