/*
 * 	Easy Slider 1.5 - jQuery plugin
 */

(function($) {

    $.fn.easySlider = function(options) {

        // default configuration properties
        var defaults = {
            prevId: 'prevBtn',
            prevText: '',
            nextId: 'nextBtn',
            nextText: '',
            controlsShow: true,
            controlsBefore: '',
            controlsAfter: '',
            controlsFade: true,
            firstId: 'firstBtn',
            firstText: 'First',
            firstShow: false,
            lastId: 'lastBtn',
            lastText: 'Last',
            lastShow: false,
            vertical: false,
            speed: 800,
            auto: false,
            pause: 3000,
            continuous: false,
            thumbnailsId: 'thumbs'
        };

        var options = $.extend(defaults, options);

        this.each(function() {
            var obj = $(this);
            var s = $("li", obj).length;
            var w = $("li", obj).width();
            var h = $("li", obj).height();
            obj.width(w);
            obj.height(h);
            obj.css("overflow", "hidden");
            var ts = s - 1;
            var t = 0;
            $("ul", obj).css('width', s * w);
            if (!options.vertical) $("li", obj).css('float', 'left');

            if (options.controlsShow) {
                var html = options.controlsBefore;
                if (options.firstShow) html += '<span id="' + options.firstId + '"><a href=\"javascript:void(0);\">' + options.firstText + '</a></span>';
                html += '<span id="' + options.prevId + '"><a href=\"javascript:void(0);\" title=\"Previous Photo\">' + options.prevText + '</a></span>';
                html += '<span id="' + options.nextId + '"><a href=\"javascript:void(0);\" title=\"Next Photo\">' + options.nextText + '</a></span>';
                if (options.lastShow) html += '<span id="' + options.lastId + '"><a href=\"javascript:void(0);\">' + options.lastText + '</a></span>';
                html += options.controlsAfter;
                $(obj).after(html);
            };

            $("a", "#" + options.nextId).click(function() {
                animate("next", true);
            });
            $("a", "#" + options.prevId).click(function() {
                animate("prev", true);
            });
            $("a", "#" + options.firstId).click(function() {
                animate("first", true);
            });
            $("a", "#" + options.lastId).click(function() {
                animate("last", true);
            });

            if (options.thumbnailsId != '') {
                $("#" + options.thumbnailsId + " li").each(
                function(intIndex) {
                    $(this).bind("click",
                        function() { clearAll('Photo'); animate("jump", true, intIndex); }
                    );
                }
                );

            }

            function animate(dir, clicked, jumpTo) {
                var ot = t;
                switch (dir) {
                    case "next":
                        t = (ot >= ts) ? (options.continuous ? 0 : ts) : t + 1;
                        break;
                    case "prev":
                        t = (t <= 0) ? (options.continuous ? ts : 0) : t - 1;
                        break;
                    case "first":
                        t = 0;
                        break;
                    case "last":
                        t = ts;
                        break;
                    case "jump":
                        t = jumpTo;
                        break;
                    default:
                        break;
                };

                var diff = Math.abs(ot - t);
                var speed = options.speed;
                if (!options.vertical) {
                    p = (t * w * -1);
                    $("ul", obj).animate(
						{ marginLeft: p },
						speed
					);
                } else {
                    p = (t * h * -1);
                    $("ul", obj).animate(
						{ marginTop: p },
						speed
					);
                };

                if (!options.continuous && options.controlsFade) {
                    if (t == ts) {
                        $("a", "#" + options.nextId).hide();
                        $("a", "#" + options.lastId).hide();
                    } else {
                        $("a", "#" + options.nextId).show();
                        $("a", "#" + options.lastId).show();
                    };
                    if (t == 0) {
                        $("a", "#" + options.prevId).hide();
                        $("a", "#" + options.firstId).hide();
                    } else {
                        $("a", "#" + options.prevId).show();
                        $("a", "#" + options.firstId).show();
                    };
                };

                if (clicked) clearTimeout(timeout);
                if (options.auto && dir == "next" && !clicked) {
                    ;
                    timeout = setTimeout(function() {
                        animate("next", false);
                    }, diff * options.speed + options.pause);
                };

            };
            // init
            var timeout;
            if (options.auto) {
                ;
                timeout = setTimeout(function() {
                    animate("next", false);
                }, options.pause);
            };

            if (!options.continuous && options.controlsFade) {
                $("a", "#" + options.prevId).hide();
                $("a", "#" + options.firstId).hide();
                if ($("li", obj).length < 2) {
                    $("a", "#" + options.nextId).hide();
                    $("a", "#" + options.lastId).hide();
                } 
            };

        });

    };

})(jQuery);


/**
* jQuery.ScrollTo - Easy element scrolling using jQuery.
*/
; (function($) { var m = $.scrollTo = function(b, h, f) { $(window).scrollTo(b, h, f) }; m.defaults = { axis: 'xy', duration: parseFloat($.fn.jquery) >= 1.3 ? 0 : 1 }; m.window = function(b) { return $(window).scrollable() }; $.fn.scrollable = function() { return this.map(function() { var b = this, h = !b.nodeName || $.inArray(b.nodeName.toLowerCase(), ['iframe', '#document', 'html', 'body']) != -1; if (!h) return b; var f = (b.contentWindow || b).document || b.ownerDocument || b; return $.browser.safari || f.compatMode == 'BackCompat' ? f.body : f.documentElement }) }; $.fn.scrollTo = function(l, j, a) { if (typeof j == 'object') { a = j; j = 0 } if (typeof a == 'function') a = { onAfter: a }; if (l == 'max') l = 9e9; a = $.extend({}, m.defaults, a); j = j || a.speed || a.duration; a.queue = a.queue && a.axis.length > 1; if (a.queue) j /= 2; a.offset = n(a.offset); a.over = n(a.over); return this.scrollable().each(function() { var k = this, o = $(k), d = l, p, g = {}, q = o.is('html,body'); switch (typeof d) { case 'number': case 'string': if (/^([+-]=)?\d+(\.\d+)?(px)?$/.test(d)) { d = n(d); break } d = $(d, this); case 'object': if (d.is || d.style) p = (d = $(d)).offset() } $.each(a.axis.split(''), function(b, h) { var f = h == 'x' ? 'Left' : 'Top', i = f.toLowerCase(), c = 'scroll' + f, r = k[c], s = h == 'x' ? 'Width' : 'Height'; if (p) { g[c] = p[i] + (q ? 0 : r - o.offset()[i]); if (a.margin) { g[c] -= parseInt(d.css('margin' + f)) || 0; g[c] -= parseInt(d.css('border' + f + 'Width')) || 0 } g[c] += a.offset[i] || 0; if (a.over[i]) g[c] += d[s.toLowerCase()]() * a.over[i] } else g[c] = d[i]; if (/^\d+$/.test(g[c])) g[c] = g[c] <= 0 ? 0 : Math.min(g[c], u(s)); if (!b && a.queue) { if (r != g[c]) t(a.onAfterFirst); delete g[c] } }); t(a.onAfter); function t(b) { o.animate(g, j, a.easing, b && function() { b.call(this, l, a) }) }; function u(b) { var h = 'scroll' + b; if (!q) return k[h]; var f = 'client' + b, i = k.ownerDocument.documentElement, c = k.ownerDocument.body; return Math.max(i[h], c[h]) - Math.min(i[f], c[f]) } }).end() }; function n(b) { return typeof b == 'object' ? b : { top: b, left: b} } })(jQuery);

; (function($) { var l = location.href.replace(/#.*/, ''); var g = $.localScroll = function(a) { $('body').localScroll(a) }; g.defaults = { duration: 1e3, axis: 'y', event: 'click', stop: true, target: window, reset: true }; g.hash = function(a) { if (location.hash) { a = $.extend({}, g.defaults, a); a.hash = false; if (a.reset) { var e = a.duration; delete a.duration; $(a.target).scrollTo(0, a); a.duration = e } i(0, location, a) } }; $.fn.localScroll = function(b) { b = $.extend({}, g.defaults, b); return b.lazy ? this.bind(b.event, function(a) { var e = $([a.target, a.target.parentNode]).filter(d)[0]; if (e) i(a, e, b) }) : this.find('a,area').filter(d).bind(b.event, function(a) { i(a, this, b) }).end().end(); function d() { return !!this.href && !!this.hash && this.href.replace(this.hash, '') == l && (!b.filter || $(this).is(b.filter)) } }; function i(a, e, b) { var d = e.hash.slice(1), f = document.getElementById(d) || document.getElementsByName(d)[0]; if (!f) return; if (a) a.preventDefault(); var h = $(b.target); if (b.lock && h.is(':animated') || b.onBefore && b.onBefore.call(b, a, f, h) === false) return; if (b.stop) h.stop(true); if (b.hash) { var j = f.id == d ? 'id' : 'name', k = $('<a> </a>').attr(j, d).css({ position: 'absolute', top: $(window).scrollTop(), left: $(window).scrollLeft() }); f[j] = ''; $('body').prepend(k); location = e.hash; k.remove(); f[j] = d } h.scrollTo(f, b).trigger('notify.serialScroll', [f]) } })(jQuery);

var bPhotoOrig = true;

$(document).ready(function() {

    // photos

    $("#slider").easySlider();
    $("#slider li img").css("visibility", "visible");

    $("#slider li img, #resize").click(
            function() {
                if (bPhotoOrig) {
                    growPic();
                } else {
                    shrinkPic();
                }
            });

    $("#nextBtn a").hover(
            function() { $("#nextBtn a").css("background-image", "url(/images/next_img_hl.png)"); },
            function() { $("#nextBtn a").css("background-image", "url(/images/next_img.png)"); }
            );

    $("#prevBtn a").hover(
            function() { $("#prevBtn a").css("background-image", "url(/images/prev_img_hl.png)"); },
            function() { $("#prevBtn a").css("background-image", "url(/images/prev_img.png)"); }
            );

    $("#thumbs li").hover(
            function() { $(this).css("background-color", "#ddd"); },
            function() { $(this).css("background-color", "white"); }
            );

    // map

    $("#map").after("<img id=\"expandMap\" src=\"/images/fullsc_left.png\" style=\"position:relative;top:-32px;background-color:#efefef;padding:3px;border:solid 1px #1b1c48;cursor:pointer;\"/>");
    $("#mapheader").hide();


    $("#expandMap").click(
            function() {
                $("#mapbox").css("position", "absolute");
                $("#mapbox").animate({ top: "80px", height: "572px", width: "824px", left: "-660px" }, 600);
                $("#mapbox").css("border", "solid 4px #999");
                $("#mapbox").css("z-index", "10000");
                $("#mapbox").draggable();
                $("#map").css("height", "540px");
                $("#map").css("width", "822px");

                window.setTimeout("largeMap();", 600);
                window.setTimeout("gmap.setCenter(new GLatLng(" + gmap.getCenter().lat() + ", " + gmap.getCenter().lng() + "), " + (gmap.getZoom() + 1) + ");", 640);

                $("#expandMap").hide();
                $("#mapheader").css("display", "block");
            }
            );

    $("#shrinkMap").click(
            function() {
                $("#mapbox").css("position", "relative");
                $("#mapbox").animate({ top: "0", height: "310px", width: "257px", left: "0" }, 600);
                $("#mapbox").css("border", "solid 1px silver");
                window.setTimeout("gmap.checkResize();", 620);
                window.setTimeout("gmap.setCenter(new GLatLng(" + gmap.getCenter().lat() + ", " + gmap.getCenter().lng() + "), " + (gmap.getZoom() - 1) + ");", 640);
                $("#map").css("height", "310px");
                $("#map").css("width", "257px");
                $("#mapbox").draggable('destroy');
                gmap.removeControl(mapcontrol);
                $("#mapheader").hide();
                $("#expandMap").show();
            });

    $(".toolbox").localScroll();

});

function growPic() {
    bPhotoOrig = false;
    $("#slider").animate({ height: "520px" }, 1000);
    $("#slider li").animate({ marginTop: 0 }, 1000);
    $(".oText").animate({ top: "-36px" }, 1000);
    $("#resize span").text("");
    $("#resize img").attr("src", "/images/fullsc_top.png");
}

function shrinkPic() {
    bPhotoOrig = true;
    $("#slider").animate({ height: "334px" }, 1000);
    $("#slider li").animate({ marginTop: "-70px" }, 1000);
    $(".oText").animate({ top: "-150px"}, 1000);
    $("#resize img").attr("src", "/images/fullsc_bottom.png");
}

function largeMap() {
    gmap.checkResize();
    mapcontrol = new GMapTypeControl();
    gmap.addControl(mapcontrol, new GControlPosition(G_ANCHOR_TOP_LEFT));
}

function showMort() {
    if (!bPhotoOrig) shrinkPic();
    $("#tbMort").addClass("tbselected");
    UpdateMortgageElements();
    $("#divMort").fadeIn("fast");
    clearAll('Mort');
}

function showEmail() {
    $("#tbEmail").addClass("tbselected");
    $("#divEmail").fadeIn("fast");
    clearAll('Email');
}

function showSMS() {
    $("#tbSMS").addClass("tbselected");
    $("#divSMS").fadeIn("fast");
    clearAll('SMS');
}

function clearAll(Except) {
    if (Except != 'Photo') { if (!bPhotoOrig) shrinkPic(); }
    if (Except != 'Mort') {
        $("#divMort").fadeOut("fast");
        $("#tbMort").removeClass("tbselected");
    }
    if (Except != 'Email') {
        $("#divEmail").fadeOut("fast");
        $("#tbEmail").removeClass("tbselected");
    }
    if (Except != 'SMS') {
        $("#divSMS").fadeOut("fast");
        $("#tbSMS").removeClass("tbselected");
    }
}        