﻿
$(document).ready(function () {
    var embedlykey = "8dcd8b6ab6c511e0a0724040d3dc5c07";
    // preload css images
    $.preloadCssImages();

    $('.info img').hover(
        function () { $(this).css('opacity', '0.6'); },
        function () { $(this).css('opacity', '1'); }
    );

    var config = {
        interval: 75,
        sensitivity: 10,
        over: function () { $(".overlay", this).show(); },
        out: function () { $(".overlay", this).hide(); }
    };

    $(".news-item, .project-item, .project-widget").hoverIntent(config);

    $(".overlay").click(function () {
        var url = $("a.link", this).attr("href");
        window.location = url;
    });

    $(".blog-posts .post:last-child").removeClass("line-bottom");

    $('.blog-posts a.oembed, .project-detail a.oembed, .project-video a.oembed, .page-body a.oembed')
        .embedly({
            key: embedlykey,
            maxWidth: 565,
            'urlRe': /http:\/\/(.*youtube\.com\/watch.*|.*\.youtube\.com\/v\/.*|youtu\.be\/.*|.*\.youtube\.com\/user\/.*|.*\.youtube\.com\/.*#.*\/.*|m\.youtube\.com\/watch.*|m\.youtube\.com\/index.*|.*\.youtube\.com\/profile.*|www\.vimeo\.com\/groups\/.*\/videos\/.*|www\.vimeo\.com\/.*|vimeo\.com\/groups\/.*\/videos\/.*|vimeo\.com\/.*|vimeo\.com\/m\/#\/.*)/i
        }
    );

    // lazy load images
    var images = $("img.lazy");
    $(".lazy-wrap").addClass("loading");

    $(images)
        .hide()
        .each(function () {
            if (!this.complete) {
                $(this).load(function () {
                    displayImage(this);
                });
            }
            else {
                displayImage(this);
            }
        });
});

function displayImage(img) {
    $(img).fadeIn(100, function () {
        $(this).parents(".lazy-wrap").removeClass("loading");
    });
}

// safari overlay fix
$(window).unload(function () { });

// newsletter

function newsletterSubscribe_Begin() {
    $(".newsletter-subscription :input").attr("disabled", true);
    $('#subscribeResult').removeClass("subscribe-success subscribe-error")
}

function newsletterSubscribe_Success(data) {
    var subscribeResult = $("#subscribeResult");
    $(subscribeResult).html(data.Message);

    if (data.Success) {
        $(subscribeResult).addClass("subscribe-success");
        $("#email").val('');
    } else {
        $(subscribeResult).addClass("subscribe-error");
        $(".newsletter-subscription :input").removeAttr("disabled");
    }
}
