﻿$(document).ready(function()
{
    //add image to search box
    $(".inputWithImge").each(function()
    {
        $(this).add($(this).next()).wrapAll('<div class="imageInputWrapper"></div>');
    });

    //add click event to magnifier image
    //$("#magnifier").click(function() { alert("Property search"); });

    //text replacer on location search box
    textReplacement($("#littleSearchForm .inputWithImge"));

    //tooltip
    $(".latestproperties img[title]").tooltip({

        // a little tweaking of the position
        offset: [0, 0],

        // use the built-in fadeIn/fadeOut effect
        effect: "slide"

    });
    $("#littleSearchForm :input[type='text']").tooltip({

        // place tooltip on the right edge
        position: "center left",

        // a little tweaking of the position
        offset: [10, -5],

        // use the built-in fadeIn/fadeOut effect
        effect: "fade"

    });

    // back to top link
    $('a#top').click(function()
    {
        $('html, body').animate({ scrollTop: '0px' }, 300);
        return false;
    });
    
});

function textReplacement(input)
{
    var originalvalue = input.val();
    input.focus(function()
    {
        if ($.trim(input.val()) == originalvalue) { input.val(''); }
    });
    input.blur(function()
    {
        if ($.trim(input.val()) == '') { input.val(originalvalue); }
    });
}

$(function()
{
    //overlay function
    
    $(".overlayLink").overlay({

        mask: 'black',
        effect: 'apple',

        onBeforeLoad: function()
        {
            // grab wrapper element inside content
            var wrap = this.getOverlay().find("#contentFrame");
            // load the page specified in the trigger
            wrap.attr("src", this.getTrigger().attr("href"))
        },
        onClose: function()
        {
            //refresh page
            window.location.href = window.location.href;
        }

    });
    
});


$(function()
{

    $.easing.custom = function(x, t, b, c, d)
    {
        var s = 1.70158;
        if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
        return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
    }

    $(".scrollable").scrollable({ mousewheel: true, easing: 'custom', speed: 700 });

    $(".items img").click(function()
    {

        // see if same thumb is being clicked
        if ($(this).hasClass("active")) { return; }

        // calclulate large image's URL based on the thumbnail URL
        var url = $(this).attr("src");

        // get handle to element that wraps the image and make it semi-transparent
        var wrap = $("#image_wrap").fadeTo("medium", 0.5);

        // the large image
        var img = new Image();


        // call this function after it's loaded
        img.onload = function()
        {

            // make wrapper fully visible
            wrap.fadeTo("fast", 1);

            // change the image
            wrap.find("img").attr("src", url);

        };

        // begin loading the image from www.flickr.com
        img.src = url;

        // activate item
        $(".items img").removeClass("active");
        $(this).addClass("active");

        // when page loads simulate a "click" on the first image
    }).filter(":first").click();

});

