$(window).load(function () {
    if ($(".search-page-b, .profile-page-b")[0]) {
        $('#lead-gen-exp .left, #lead-gen-exp .right').corners({
            radius: 5,
            background: "#F3F6ED"
        });
        // $('#lead-gen-exp .left, #lead-gen-exp .right').equalheight();
    }
    if ($(".search-page-b")[0]) {
        $('.lead-gen-form::not(.lead-form-exp)').before('<span class="lead-gen-form-prepend">&nbsp;</span>');
    }
    if ($(".profile-page, .search-page")[0]) {
        function checkEnter(e) {
            var a;
            if (e && e.which) {
                e = e;
                a = e.which;
            } else {
                e = event;
                a = e.keyCode;
            }
            if (a == 13) {
                doSearchSubmit(document.getElementById('narrow_search'));
                return false;
            }
        }
        $('#city_state').autocomplete({
            serviceUrl: '/cityStateComplete.do?jq=true',
            minChars: 3,
            maxHeight: 300,
            width: 300,
            deferRequestBy: 0
        });
        $('#trulia_area').autocomplete({
            serviceUrl: '/cityStateComplete.do?jq=true',
            minChars: 3,
            maxHeight: 300,
            width: 300,
            deferRequestBy: 0
        });
        $("a[href*='http://']:not([href*='" + location.hostname + "'])").attr("target", "_blank");
        $('input.text').click(function () {
            if (this.value == this.defaultValue) {
                this.value = '';
            }
        });
        $('input.text').blur(function () {
            if (this.value === '') {
                this.value = this.defaultValue;
            }
        });
        // password field label
        var passField = $("input.password");
        var passFieldNew = passField.clone();
        $('input.password').click(function () {
            passFieldNew.attr("type", "password");
            passFieldNew.attr("value", "");
            passFieldNew.insertBefore(passField);
            passField.remove();
        });
        $(".panel-trigger").click(function () {
            $(this).next(".panel").slideToggle("fast");
            $(this).toggleClass("active");
            return false;
        });
        $(".narrow-search.panel-trigger").click(function () {
            $("#narrow_search_panel").slideToggle("fast");
            $(this).toggleClass("active");
            return false;
        });
        $("#breadcrumb li:last:not(.action)").addClass("active");
        $('.hover').hover(function () {
            $(this).addClass('hovered');
        },

        function () {
            $(this).removeClass('hovered');
        });
        $(".related-search li:last").addClass("last");
        $('#body').corners({
            radius: 5,
            background: "#F3F6ED"
        });
        $('#breadcrumb').corners({
            radius: 5,
            background: "#F3F6ED",
            corners: "tl tr"
        });
        $('#search-compact').corners({
            radius: 5,
            background: "#F3F6ED",
            corners: "bl br"
        });
        $('#narrow_search_panel').corners({
            radius: 3
        });
        if ($('.test')[0]) {
            $('.leadgen-test-a .lead-form').prepend('<span class="arrow">&nbsp;</span>');
        }
        $('.tabbed-block').each(function(){
          var $block = $(this);
          $block.find('.tab-content:first').show();
          $block.find('ol li:first').addClass('active');
          $block.find('ol li a').click(function () {
            var $link = $(this);
            $link.parent().addClass('active').siblings().removeClass('active');
            var a = $link.attr('href');
            $link.closest('.tabbed-block').find('.tab-content').hide();
            $(a).show();
            return false;
          });
        });
    }
    if ($(".search-page")[0]) {
        $("#search-results ol li:last").addClass("last");
        $('#search-results ol li').hover(function () {
            $(this).addClass('hovered');
        }, function () {
            $(this).removeClass('hovered');
        });
        /*
        $("#search-results li .action a.lightbox").lightbox({
            opacity: "0.6",
            width: "940"
        });
        */
        $('.block, #search-results .action a').corners({ radius: 5 });
        $('#search-areas .tabs li.first a').corners({ radius: 7, corners: "tl" });
        $('#search-areas .tabs li.last a').corners({ radius: 7, corners: "tr" });
        $('.pagination.basic li.active a').corners({ radius: 2 });
        
    }
    if ($(".profile-page")[0]) {
        // if (!$.browser.msie) {
        thumbWidth = $(".realtor-snapshot .thumb").length ? $(".realtor-snapshot .thumb").outerWidth(true) : 0;
        ratingWidth = $(".realtor-snapshot .realtor-rating").length ? $(".realtor-snapshot .realtor-rating").outerWidth(true) : 0;
        personalWidth = $(".realtor-snapshot .personal").outerWidth(true);
        $('.realtor-snapshot .summary').width(907 - thumbWidth - personalWidth - ratingWidth);
        // }
        $(".block.related .box li:last").addClass("last");
        $('.other .block').equalheight();
        $('.block.related .box').equalheight();
        $('.realtor-snapshot .personal, .realtor-snapshot .summary').equalheight();
        $('.review-info, .block.related .box h4').after('<span class="darr"></span>');
        $('.review-text').prepend('<span class="quote quote-open">&ldquo;</span>');
        $('.review-text').append('<span class="quote quote-close">&rdquo;</span>');
        $("#designations dl:nth-child(4n)").addClass("nth").after('<br clear="all" />');
        $('#designations dl').hover(function () {
            $(this).addClass('hovered');
        },

        function () {
            $(this).removeClass('hovered');
        });
        $(".map-trigger").click(function () {
            $(this).toggleClass("active");
            if ($(this).hasClass("active")) {
                $(this).find('em').remove('em');
                $(this).prepend("<em>Hide</em>");
            } else {
                $(this).find("em").remove("em");
                $(this).prepend("<em>Show</em>");
            }
            var a = document.getElementById('email_realtor1').realtorId.value;
            $('.map-container').height("290px");
            $('.map-container').load("/displayMap.action?realtorId=" + a).slideToggle("slow");
            return false;
        });
        $('#realtor-sold ol, #realtor-selling ol').pagination('ul');
        $(".block.related .box").click(function () {
            window.location = $(this).find("a.name").attr("href");
            return false;
        });
        $(".sale-activity a.lightbox").lightbox({
            opacity: "0.6",
            width: "940"
        });
        $("#realtor-contact .btn-appointment").lightbox({
            opacity: "0.6",
            iframe: "true",
            width: "940",
            height: "400"
        });
        $('#realtor-info, #realtor-contact, #sale-activity, #reviews, .pagebody .block, .review-ratings li, .block.related .box, .lead-form-exp').corners({
            radius: 5
        });
        $('.realtor-bio, .realtor-snapshot .summary').corners({
            radius: 5,
            background: "#C37430"
        });
        $('#reviews .reviews').corners({
            radius: 5,
            background: "#eee"
        });
        if ($('blockquote.about')[0]) {
            $('blockquote.about').prepend('<span class="quotes open-quotes">&ldquo;</span>');
        }
        if ($('.realtor-interview')[0]) {
            $('.realtor-interview h4').toggle(function () {
                $(this).next().show();
                $(this).text('Hide Interview');
            },

            function () {
                $(this).next().hide();
                $(this).text('Show Interview');
            });
            $('.realtor-interview .question').toggle(function () {
                $(this).next('.answer').show();
            },

            function () {
                $(this).next('.answer').hide();
            });
        }
    }
    /* ===[ LEAD BUYING LANDING PAGE ]=== */
    
        if ($('.lead-page')[0]) {
            // corners
            $('.lead, .lead-info, .how-it-works, .countdown li').corners({
                radius: 5
            });
        }
        if ($('.lead-form-page')[0]) {
            // equal height
            $('.lead .block').equalheight();
            // corners
            $('.block').corners({
                radius: 5
            });
            // tabbed-block
            $('.tabbed-block').each(function(){
              var $block = $(this);
              $block.find('.tab-content:first').show();
              $block.find('ol li:first').addClass('active');
              $block.find('ol li a').click(function () {
                var $link = $(this);
                $link.parent().addClass('active').siblings().removeClass('active');
                var a = $link.attr('href');
                $link.closest('.tabbed-block').find('.tab-content').hide();
                $(a).show();
                return false;
              });
            });
            // tabs
            if (!$('.test')[0]) {
                alert(1);
                $('.tabbed-block ol li a').click(function () {
                    $('.btn-buyProperty').toggle();
                    $('.btn-sellProperty').toggle();
                    return false;
                });
            }
            // if test
            if ($('.test')[0]) {
                $('p.desc').prepend('<span class="arrow">&nbsp;</span>');
            }
        }
    
    if ($.browser.msie && $.browser.version == "6.0" && ($(".search-page, .profile-page")[0])) {
        $.getScript("/pages/javascript/pngfix.js", function () {
            PNG.fix('#lead-gen-exp .lead-gen-9 .inner-wrap, .lead-gen-form-prepend');
        });
    }
});

